aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/vlib/picohttpparser/request.v
diff options
context:
space:
mode:
authorIndrajith K L2022-12-03 17:00:20 +0530
committerIndrajith K L2022-12-03 17:00:20 +0530
commitf5c4671bfbad96bf346bd7e9a21fc4317b4959df (patch)
tree2764fc62da58f2ba8da7ed341643fc359873142f /v_windows/v/vlib/picohttpparser/request.v
downloadcli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.gz
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.tar.bz2
cli-tools-windows-f5c4671bfbad96bf346bd7e9a21fc4317b4959df.zip
Adds most of the toolsHEADmaster
Diffstat (limited to 'v_windows/v/vlib/picohttpparser/request.v')
-rw-r--r--v_windows/v/vlib/picohttpparser/request.v65
1 files changed, 65 insertions, 0 deletions
diff --git a/v_windows/v/vlib/picohttpparser/request.v b/v_windows/v/vlib/picohttpparser/request.v
new file mode 100644
index 0000000..98667be
--- /dev/null
+++ b/v_windows/v/vlib/picohttpparser/request.v
@@ -0,0 +1,65 @@
+module picohttpparser
+
+pub struct Request {
+mut:
+ prev_len int
+pub mut:
+ method string
+ path string
+ headers [100]C.phr_header
+ num_headers u64
+ body string
+}
+
+[inline]
+pub fn (mut r Request) parse_request(s string, max_headers int) int {
+ method_len := size_t(0)
+ path_len := size_t(0)
+ minor_version := 0
+ num_headers := size_t(max_headers)
+
+ pret := C.phr_parse_request(s.str, s.len, PPchar(&r.method.str), &method_len, PPchar(&r.path.str),
+ &path_len, &minor_version, &r.headers[0], &num_headers, r.prev_len)
+ if pret > 0 {
+ unsafe {
+ r.method = tos(r.method.str, int(method_len))
+ r.path = tos(r.path.str, int(path_len))
+ }
+ r.num_headers = u64(num_headers)
+ }
+ r.body = unsafe { (&s.str[pret]).vstring_literal_with_len(s.len - pret) }
+ r.prev_len = s.len
+ return pret
+}
+
+[inline]
+pub fn (mut r Request) parse_request_path(s string) int {
+ method_len := size_t(0)
+ path_len := size_t(0)
+
+ pret := C.phr_parse_request_path(s.str, s.len, PPchar(&r.method.str), &method_len,
+ PPchar(&r.path.str), &path_len)
+ if pret > 0 {
+ unsafe {
+ r.method = tos(r.method.str, int(method_len))
+ r.path = tos(r.path.str, int(path_len))
+ }
+ }
+ return pret
+}
+
+[inline]
+pub fn (mut r Request) parse_request_path_pipeline(s string) int {
+ method_len := size_t(0)
+ path_len := size_t(0)
+
+ pret := C.phr_parse_request_path_pipeline(s.str, s.len, PPchar(&r.method.str), &method_len,
+ PPchar(&r.path.str), &path_len)
+ if pret > 0 {
+ unsafe {
+ r.method = tos(r.method.str, int(method_len))
+ r.path = tos(r.path.str, int(path_len))
+ }
+ }
+ return pret
+}