http: fix recent changes; picoev: make compile

pull/4957/head
Alexander Medvednikov 2020-05-20 05:36:46 +02:00
parent e137fbb1ea
commit 0a6d709ce2
7 changed files with 30 additions and 24 deletions

View File

@ -19,7 +19,8 @@ fn hello_response() string {
return 'Hello, World!'
}
pub fn callback(req picohttpparser.Request, res mut picohttpparser.Response) {
fn callback(req picohttpparser.Request, res mut picohttpparser.Response) {
if picohttpparser.cmpn(req.method, 'GET ', 4) {
if picohttpparser.cmp(req.path, '/t') {
res.http_ok().header_server().header_date().plain().body(hello_response())

View File

@ -147,7 +147,7 @@ fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response {
//println(h)
sb.write(chunk.after('\r\n'))
// TODO for some reason this can be missing from headers
is_chunk_encoding = true //h.contains('chunked')
is_chunk_encoding = false //h.contains('chunked')
//println(sb.str())
continue
}
@ -172,7 +172,7 @@ fn (req &Request) ssl_do(port int, method, host_name, path string) ?Response {
C.SSL_CTX_free(ctx)
}
body:= sb.str()
println(body)
//println(body)
return parse_response(h +'\r\n\r\n'+ body)
}

View File

@ -63,7 +63,7 @@ fn C.write() int
struct C.picoev_loop {}
struct Picoev {
loop *C.picoev_loop
loop &C.picoev_loop
cb fn(req picohttpparser.Request, res mut picohttpparser.Response)
mut:
date byteptr
@ -73,14 +73,17 @@ mut:
oidx [1024]int
}
fn picoev_del(*C.picoev_loop, int) int
fn picoev_set_timeout(*C.picoev_loop, int, int)
fn picoev_add(*C.picoev_loop, int, int, int, *C.picoev_handler, voidptr) int
fn picoev_init(int) int
fn picoev_create_loop(int) *C.picoev_loop
fn picoev_loop_once(*C.picoev_loop, int) int
fn picoev_destroy_loop(*C.picoev_loop) int
fn picoev_deinit() int
fn C.picoev_del(&C.picoev_loop, int) int
fn C.picoev_set_timeout(&C.picoev_loop, int, int)
fn C.picoev_add(&C.picoev_loop, int, int, int, &C.picoev_handler, voidptr) int
fn C.picoev_init(int) int
fn C.picoev_create_loop(int) &C.picoev_loop
fn C.picoev_loop_once(&C.picoev_loop, int) int
fn C.picoev_destroy_loop(&C.picoev_loop) int
fn C.picoev_deinit() int
fn C.phr_parse_request() int
fn C.phr_parse_request_path_pipeline() int
fn C.phr_parse_request_path() int
[inline]
fn setup_sock(fd int) {
@ -94,7 +97,7 @@ fn setup_sock(fd int) {
}
[inline]
fn close_conn(loop *C.picoev_loop, fd int) {
fn close_conn(loop &C.picoev_loop, fd int) {
C.picoev_del(loop, fd)
C.close(fd)
}
@ -109,8 +112,8 @@ fn mysubstr(s byteptr, from, len int) string {
return tos(s + from, len)
}
fn rw_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) {
mut p := *Picoev(cb_arg)
fn rw_callback(loop &C.picoev_loop, fd, events int, cb_arg voidptr) {
mut p := &Picoev(cb_arg)
if (events & C.PICOEV_TIMEOUT) != 0 {
close_conn(loop, fd)
p.idx[fd] = 0
@ -126,8 +129,8 @@ fn rw_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) {
p.idx[fd] = 0
return
} else if r == -1 {
if errno == C.EAGAIN || errno == C.EWOULDBLOCK {
//
if false { //errno == C.EAGAIN || errno == C.EWOULDBLOCK {
// TODO
} else {
close_conn(loop, fd)
p.idx[fd] = 0
@ -168,7 +171,7 @@ fn rw_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) {
}
}
fn accept_callback(loop *C.picoev_loop, fd, events int, cb_arg voidptr) {
fn accept_callback(loop &C.picoev_loop, fd, events int, cb_arg voidptr) {
newfd := C.accept(fd, 0, 0)
if newfd != -1 {
setup_sock(newfd)

View File

@ -26,4 +26,3 @@ fn phr_parse_request_path() int
fn phr_parse_request_path_pipeline() int
fn C.get_date() byteptr
fn C.u64toa() int
fn C.memcmp() int

View File

@ -1,15 +1,18 @@
module picohttpparser
pub struct Request {
mut:
pub mut:
method string
path string
headers *C.phr_header_t
headers &C.phr_header_t
num_headers u64
}
[inline]
pub fn (mut r Request) parse_request(s string, headers *C.phr_header_t, max_headers int) int {
pub fn (mut r Request) parse_request(s string, headers &C.phr_header_t, max_headers int) int {
method_len := u64(0)
path_len := u64(0)
minor_version := 0

View File

@ -5,7 +5,7 @@ pub struct Response {
pub:
date byteptr
buf_start byteptr
mut:
pub mut:
buf byteptr
}

View File

@ -44,7 +44,7 @@ Option ${dec_fn_name}(cJSON* root) {
if (!root) {
const char *error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL) {
fprintf(stderr, "Error in decode() for $styp error_ptr=: %%s\\n", error_ptr);
// fprintf(stderr, "Error in decode() for $styp error_ptr=: %%s\\n", error_ptr);
// printf("\\nbad js=%%s\\n", js.str);
return v_error(tos2(error_ptr));
}