MIRROR: javascript for ๐Ÿœ's, a tiny runtime with big ambitions
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

prevent tlsuv from closing request until done

+151
+151
vendor/packagefiles/patches/tlsuv-boringssl.patch
··· 23 23 #include <openssl/ecdsa.h> 24 24 #endif 25 25 26 + diff --git a/include/tlsuv/http.h b/include/tlsuv/http.h 27 + index 8af05fe..fa56144 100644 28 + --- a/include/tlsuv/http.h 29 + +++ b/include/tlsuv/http.h 30 + @@ -117,6 +117,10 @@ struct tlsuv_http_req_s { 31 + llhttp_t parser; 32 + enum http_request_state state; 33 + bool keepalive; 34 + + bool parser_active; 35 + + bool cancel_pending; 36 + + int cancel_error; 37 + + char *cancel_status; 38 + 39 + bool req_chunked; 40 + ssize_t req_body_size; 41 + diff --git a/src/http.c b/src/http.c 42 + index 3a82e49..953b065 100644 43 + --- a/src/http.c 44 + +++ b/src/http.c 45 + @@ -47,6 +47,8 @@ static void tr_read_cb(uv_stream_t *s, ssize_t nread, const uv_buf_t *buf); 46 + static void tr_alloc_cb(uv_handle_t *s, size_t suggested_size, uv_buf_t *buf); 47 + 48 + static void fail_active_request(tlsuv_http_t *c, int code, const char *msg); 49 + +static void clear_req_body(tlsuv_http_req_t *req, int code); 50 + +static void finalize_canceled_request(tlsuv_http_t *c, tlsuv_http_req_t *req); 51 + 52 + #define close_connection(c) close_connection1(c, __FUNCTION__, __LINE__) 53 + static void close_connection1(tlsuv_http_t *c, const char *src_fn, int src_line); 54 + @@ -133,6 +135,9 @@ static void clt_read_cb(tlsuv_http_t *c, ssize_t nread, const uv_buf_t *buf) { 55 + DUMP_REQ(ERR, ar, "failed to parse HTTP response"); 56 + fail_active_request(c, UV_EINVAL, "failed to parse HTTP response"); 57 + keepalive = false; 58 + + } else if (ar->cancel_pending) { 59 + + keepalive = false; 60 + + finalize_canceled_request(c, ar); 61 + } else if (ar->state == completed) { 62 + keepalive = c->keepalive && ar->keepalive; 63 + c->active = NULL; 64 + @@ -179,6 +184,34 @@ static void clear_req_body(tlsuv_http_req_t *req, int code) { 65 + req->req_body = NULL; 66 + } 67 + 68 + +static void finalize_canceled_request(tlsuv_http_t *c, tlsuv_http_req_t *req) { 69 + + if (req == NULL || !req->cancel_pending) return; 70 + + 71 + + req->cancel_pending = false; 72 + + if (c->active == req) { 73 + + c->active = NULL; 74 + + } 75 + + 76 + + req->resp.code = req->cancel_error; 77 + + if (req->resp.status) { 78 + + tlsuv__free(req->resp.status); 79 + + } 80 + + req->resp.status = req->cancel_status; 81 + + req->cancel_status = NULL; 82 + + 83 + + clear_req_body(req, req->resp.code); 84 + + 85 + + if (req->state < headers_received && req->resp_cb != NULL) { 86 + + req->resp_cb(&req->resp, req->data); 87 + + req->resp_cb = NULL; 88 + + } else if (req->resp.body_cb != NULL) { 89 + + req->resp.body_cb(req, NULL, req->resp.code); 90 + + } 91 + + 92 + + http_req_free(req); 93 + + tlsuv__free(req); 94 + +} 95 + + 96 + static void fail_active_request(tlsuv_http_t *c, int code, const char *msg) { 97 + tlsuv_http_req_t *req = c->active; 98 + 99 + @@ -918,6 +951,16 @@ int http_req_cancel_err(tlsuv_http_t *clt, tlsuv_http_req_t *req, int error, con 100 + 101 + if (r == req || req == clt->active) { // req is in the queue 102 + if (req == clt->active) { 103 + + if (req->parser_active) { 104 + + req->cancel_pending = true; 105 + + req->cancel_error = error; 106 + + if (req->cancel_status) { 107 + + tlsuv__free(req->cancel_status); 108 + + } 109 + + req->cancel_status = tlsuv__strdup(msg ? msg : uv_strerror(error)); 110 + + llhttp_pause(&req->parser); 111 + + return 0; 112 + + } 113 + clt->active = NULL; 114 + // since active request is being canceled we don't want to consume what's left on the wire for it 115 + // and need to close connection 116 + @@ -1053,4 +1096,3 @@ static void free_http(tlsuv_http_t *clt) { 117 + tlsuv_tls_link_free(&clt->tls_link); 118 + } 119 + } 120 + - 121 + diff --git a/src/http_req.c b/src/http_req.c 122 + index 302cad1..d34182e 100644 123 + --- a/src/http_req.c 124 + +++ b/src/http_req.c 125 + @@ -46,6 +46,10 @@ void http_req_init(tlsuv_http_req_t* r, const char* method, const char* path) { 126 + r->req_body_size = -1; 127 + r->body_sent_size = 0; 128 + r->state = created; 129 + + r->parser_active = false; 130 + + r->cancel_pending = false; 131 + + r->cancel_error = 0; 132 + + r->cancel_status = NULL; 133 + r->resp.req = r; 134 + 135 + llhttp_init(&r->parser, HTTP_RESPONSE, &HTTP_PROC); 136 + @@ -57,9 +61,15 @@ void http_req_free(tlsuv_http_req_t* req) { 137 + 138 + free_hdr_list(&req->req_headers); 139 + free_hdr_list(&req->resp.headers); 140 + + if (req->resp.curr_header) { 141 + + tlsuv__free(req->resp.curr_header); 142 + + } 143 + if (req->resp.status) { 144 + tlsuv__free(req->resp.status); 145 + } 146 + + if (req->cancel_status) { 147 + + tlsuv__free(req->cancel_status); 148 + + } 149 + if (req->inflater) { 150 + um_free_inflater(req->inflater); 151 + } 152 + @@ -89,11 +99,17 @@ int http_req_finish(tlsuv_http_req_t* req) { 153 + 154 + ssize_t http_req_process(tlsuv_http_req_t* req, const char* buf, ssize_t len) { 155 + UM_LOG(TRACE, "processing %zd bytes\n%.*s", len, printable_len((const unsigned char*)buf, len), buf); 156 + + req->parser_active = true; 157 + llhttp_errno_t err = llhttp_execute(&req->parser, buf, len); 158 + + req->parser_active = false; 159 + ssize_t processed = -1; 160 + if (err == HPE_OK) { 161 + processed = len; 162 + UM_LOG(VERB, "processed %zd of %zd", processed, len); 163 + + } else if (err == HPE_PAUSED && req->cancel_pending) { 164 + + processed = llhttp_get_error_pos(&req->parser) - buf; 165 + + UM_LOG(VERB, "request[%s %s] canceled after processing %zd of %zd", 166 + + req->method, req->path, processed, len); 167 + } else if (err == HPE_PAUSED_UPGRADE) { 168 + processed = llhttp_get_error_pos(&req->parser) - buf; 169 + UM_LOG(VERB, "websocket upgrade: processed %zd out of %zd", processed, len); 170 + @@ -420,4 +436,4 @@ static int http_body_cb(llhttp_t* parser, const char* body, size_t len) { 171 + } 172 + } 173 + return 0; 174 + -} 175 + \ No newline at end of file 176 + +}