v/vlib/picohttpparser/request.v

62 lines
1.4 KiB
V
Raw Normal View History

2020-01-23 03:26:30 +01:00
module picohttpparser
pub struct Request {
pub mut:
method string
path string
headers [100]C.phr_header
2020-01-23 03:26:30 +01:00
num_headers u64
body string
2020-01-23 03:26:30 +01:00
}
[inline]
pub fn (mut r Request) parse_request(s string, max_headers int) int {
2020-01-23 03:26:30 +01: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, PPchar(&r.method.str), &method_len, PPchar(&r.path.str),
&path_len, &minor_version, &r.headers[0], &num_headers, 0)
2020-01-23 03:26:30 +01:00
if pret > 0 {
unsafe {
r.method = tos(r.method.str, int(method_len))
r.path = tos(r.path.str, int(path_len))
}
2020-01-23 03:26:30 +01:00
r.num_headers = num_headers
}
return pret
}
[inline]
2020-05-17 13:51:18 +02:00
pub fn (mut r Request) parse_request_path(s string) int {
2020-01-23 03:26:30 +01:00
method_len := u64(0)
path_len := u64(0)
pret := C.phr_parse_request_path(s.str, s.len, PPchar(&r.method.str), &method_len,
PPchar(&r.path.str), &path_len)
2020-01-23 03:26:30 +01:00
if pret > 0 {
unsafe {
r.method = tos(r.method.str, int(method_len))
r.path = tos(r.path.str, int(path_len))
}
2020-01-23 03:26:30 +01:00
}
return pret
}
[inline]
2020-05-17 13:51:18 +02:00
pub fn (mut r Request) parse_request_path_pipeline(s string) int {
2020-01-23 03:26:30 +01:00
method_len := u64(0)
path_len := u64(0)
pret := C.phr_parse_request_path_pipeline(s.str, s.len, PPchar(&r.method.str), &method_len,
PPchar(&r.path.str), &path_len)
2020-01-23 03:26:30 +01:00
if pret > 0 {
unsafe {
r.method = tos(r.method.str, int(method_len))
r.path = tos(r.path.str, int(path_len))
}
2020-01-23 03:26:30 +01:00
}
return pret
}