2020-01-23 05:26:30 +03:00
|
|
|
module picohttpparser
|
|
|
|
|
|
|
|
pub struct Request {
|
2020-05-20 06:36:46 +03:00
|
|
|
pub mut:
|
2020-01-23 05:26:30 +03:00
|
|
|
method string
|
|
|
|
path string
|
2020-06-07 02:23:30 +03:00
|
|
|
headers[100] C.phr_header
|
2020-01-23 05:26:30 +03:00
|
|
|
num_headers u64
|
2020-06-07 02:23:30 +03:00
|
|
|
body string
|
2020-01-23 05:26:30 +03:00
|
|
|
}
|
|
|
|
|
2020-05-20 06:36:46 +03:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-01-23 05:26:30 +03:00
|
|
|
[inline]
|
2020-06-07 02:23:30 +03:00
|
|
|
pub fn (mut r Request) parse_request(s string, max_headers int) int {
|
2020-01-23 05:26:30 +03:00
|
|
|
method_len := u64(0)
|
|
|
|
path_len := u64(0)
|
|
|
|
minor_version := 0
|
|
|
|
num_headers := u64(max_headers)
|
|
|
|
|
|
|
|
pret := C.phr_parse_request(
|
|
|
|
s.str, s.len,
|
2021-03-05 17:41:11 +03:00
|
|
|
&r.method.str, &method_len,
|
|
|
|
&r.path.str, &path_len,
|
2020-01-23 05:26:30 +03:00
|
|
|
&minor_version,
|
2020-06-07 02:23:30 +03:00
|
|
|
r.headers, &num_headers,
|
2020-01-23 05:26:30 +03:00
|
|
|
0
|
|
|
|
)
|
|
|
|
if pret > 0 {
|
2021-02-15 18:15:52 +03:00
|
|
|
unsafe {
|
|
|
|
r.method = tos(r.method.str, int(method_len))
|
|
|
|
r.path = tos(r.path.str, int(path_len))
|
|
|
|
}
|
2020-01-23 05:26:30 +03:00
|
|
|
r.num_headers = num_headers
|
|
|
|
}
|
|
|
|
return pret
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-05-17 14:51:18 +03:00
|
|
|
pub fn (mut r Request) parse_request_path(s string) int {
|
2020-01-23 05:26:30 +03:00
|
|
|
method_len := u64(0)
|
|
|
|
path_len := u64(0)
|
|
|
|
|
|
|
|
pret := C.phr_parse_request_path(
|
|
|
|
s.str, s.len,
|
2021-03-05 17:41:11 +03:00
|
|
|
&r.method.str, &method_len,
|
|
|
|
&r.path.str, &path_len
|
2020-01-23 05:26:30 +03:00
|
|
|
)
|
|
|
|
if pret > 0 {
|
2021-02-15 18:15:52 +03:00
|
|
|
unsafe {
|
|
|
|
r.method = tos(r.method.str, int(method_len))
|
|
|
|
r.path = tos(r.path.str, int(path_len))
|
|
|
|
}
|
2020-01-23 05:26:30 +03:00
|
|
|
}
|
|
|
|
return pret
|
|
|
|
}
|
|
|
|
|
|
|
|
[inline]
|
2020-05-17 14:51:18 +03:00
|
|
|
pub fn (mut r Request) parse_request_path_pipeline(s string) int {
|
2020-01-23 05:26:30 +03:00
|
|
|
method_len := u64(0)
|
|
|
|
path_len := u64(0)
|
|
|
|
|
|
|
|
pret := C.phr_parse_request_path_pipeline(
|
|
|
|
s.str, s.len,
|
2021-03-05 17:41:11 +03:00
|
|
|
&r.method.str, &method_len,
|
|
|
|
&r.path.str, &path_len
|
2020-01-23 05:26:30 +03:00
|
|
|
)
|
|
|
|
if pret > 0 {
|
2021-02-15 18:15:52 +03:00
|
|
|
unsafe {
|
|
|
|
r.method = tos(r.method.str, int(method_len))
|
|
|
|
r.path = tos(r.path.str, int(path_len))
|
|
|
|
}
|
2020-01-23 05:26:30 +03:00
|
|
|
}
|
|
|
|
return pret
|
|
|
|
}
|