diff --git a/src/http_cgi.c b/src/http_cgi.c index 63176d2..8d00126 100644 --- a/src/http_cgi.c +++ b/src/http_cgi.c @@ -1290,7 +1290,7 @@ int AddReqContentPtr (void * vmsg, void * body, int64 bodylen) if (bodylen < 0) bodylen = str_len(body); if (bodylen <= 0) return -3; - chunk_add_bufptr(msg->req_body_chunk, body, bodylen, NULL); + chunk_add_bufptr(msg->req_body_chunk, body, bodylen, NULL, NULL); return 0; } @@ -1856,7 +1856,7 @@ int AddResContentPtr (void * vmsg, void * body, int64 bodylen) if (bodylen < 0) bodylen = str_len(body); if (bodylen <= 0) return -3; - chunk_add_bufptr(msg->res_body_chunk, body, bodylen, NULL); + chunk_add_bufptr(msg->res_body_chunk, body, bodylen, NULL, NULL); return 0; } diff --git a/src/http_chunk.c b/src/http_chunk.c index af2df99..b995790 100644 --- a/src/http_chunk.c +++ b/src/http_chunk.c @@ -312,7 +312,7 @@ int http_chunk_add_bufptr (void * vchk, void * vbgn, int len, int * rmlen) chk->recvsize += restlen; chk->recvlen += restlen - 2; - chunk_add_bufptr(chk->chunk, poct, restlen - 2, NULL); + chunk_add_bufptr(chk->chunk, poct, restlen - 2, NULL, NULL); arr_push(chk->item_list, item); chk->curitem = NULL; @@ -328,7 +328,7 @@ int http_chunk_add_bufptr (void * vchk, void * vbgn, int len, int * rmlen) item->recvlen += min(restnum, restlen); chk->recvlen += min(restnum, restlen); - chunk_add_bufptr(chk->chunk, poct, min(restnum, restlen), NULL); + chunk_add_bufptr(chk->chunk, poct, min(restnum, restlen), NULL, NULL); if (rmlen) *rmlen = len; diff --git a/src/http_cli_io.c b/src/http_cli_io.c index 4e94e34..cca9060 100644 --- a/src/http_cli_io.c +++ b/src/http_cli_io.c @@ -594,13 +594,13 @@ int http_cli_reqbody_parse (void * vcon, void * vmsg) } else { chunk_add_bufptr(msg->req_body_chunk, frameP(msg->req_body_stream), - frameL(msg->req_body_stream), NULL); + frameL(msg->req_body_stream), NULL, NULL); } http_form_multipart_parse(msg, NULL); if (msg->req_content_type && msg->req_contype_len > 0) { - if (strncasecmp(msg->req_content_type, "application/x-www-form-urlencoded", 33) == 0) { + if (str_ncasecmp(msg->req_content_type, "application/x-www-form-urlencoded", 33) == 0) { if (!msg->req_form_kvobj) { msg->req_form_kvobj = kvpair_init(37, "&", "="); } @@ -608,7 +608,7 @@ int http_cli_reqbody_parse (void * vcon, void * vmsg) chunk_ptr(msg->req_body_chunk, 0, NULL, (void **)&pbody, &restlen); kvpair_decode(msg->req_form_kvobj, pbody, restlen); - } else if (strncasecmp(msg->req_content_type, "application/json", 16) == 0) { + } else if (str_ncasecmp(msg->req_content_type, "application/json", 16) == 0) { if (!msg->req_form_json) { msg->req_form_json = json_init(0, 0, 0); } diff --git a/src/http_do.c b/src/http_do.c index fddea98..1611747 100644 --- a/src/http_do.c +++ b/src/http_do.c @@ -164,6 +164,10 @@ void * do_http_get_msg (void * vmgmt, char * url, int urllen, msg->SetMethod(msg, "GET", 3); msg->SetURL(msg, url, urllen, 1); + str_secpy(msg->req_ver, sizeof(msg->req_ver)-1, "HTTP/1.1", 8); + msg->req_ver_major = 1; + msg->req_ver_minor = 1; + msg->req_body_flag = BC_NONE; msg->dstport = msg->req_port; @@ -234,6 +238,10 @@ void * do_http_post_msg (void * vmgmt, char * url, int urllen, char * mime, msg->SetMethod(msg, "POST", 4); msg->SetURL(msg, url, urllen, 1); + str_secpy(msg->req_ver, sizeof(msg->req_ver)-1, "HTTP/1.1", 8); + msg->req_ver_major = 1; + msg->req_ver_minor = 1; + msg->req_body_flag = BC_CONTENT_LENGTH; msg->dstport = msg->req_port; diff --git a/src/http_fcgi_io.c b/src/http_fcgi_io.c index e3bb553..8d2da69 100644 --- a/src/http_fcgi_io.c +++ b/src/http_fcgi_io.c @@ -519,7 +519,7 @@ int http_fcgi_recv_forward (void * vcon) if (pbyte + 4 <= ppar[0] + arlen[0]) { /* add all STDOUT body into httpmsg->res_body_chunk */ - chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm); + chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm, NULL); } else { /* header trailer \r\n\r\n across the 2 buffer, move them @@ -528,7 +528,7 @@ int http_fcgi_recv_forward (void * vcon) frame_put_nlast(httpmsg->res_header_stream, pbody, len); /* add STDOUT body into httpmsg->res_body_chunk */ - chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm); + chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm, NULL); } /* move the pointer to the end of first FastCGI pdu */ @@ -540,7 +540,7 @@ int http_fcgi_recv_forward (void * vcon) if (bodylen > len) { /* add STDOUT body into httpmsg->res_body_chunk */ - chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm); + chunk_add_bufptr(httpmsg->res_body_chunk, pbody + len, bodylen - len, frm, NULL); } /* move the pointer to the end of first FastCGI pdu */ @@ -584,7 +584,7 @@ int http_fcgi_recv_forward (void * vcon) } else { //STDOUT header has been got before /* add all STDOUT body into httpmsg->res_body_chunk */ - chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm); + chunk_add_bufptr(httpmsg->res_body_chunk, pbody, bodylen, frm, NULL); /* move the pointer to the end of first FastCGI pdu */ iter = (pend - pbgn); @@ -655,16 +655,16 @@ int http_fcgi_handle (void * vmsg) HTTPMgmt * mgmt = NULL; FcgiSrv * cgisrv = NULL; char url[512]; - + if (!msg) return -1; - + mgmt = (HTTPMgmt *)msg->httpmgmt; if (!mgmt) return -2; - + /* check the request if it's to be transformed to FCGI server */ if (http_fcgi_check(msg, url, sizeof(url)-1) <= 0) return -100; - + msg->fastcgi = 1; cgisrv = http_fcgisrv_open(mgmt, url, 100); diff --git a/src/http_fcgi_msg.c b/src/http_fcgi_msg.c index fb53831..14c45cd 100644 --- a/src/http_fcgi_msg.c +++ b/src/http_fcgi_msg.c @@ -257,7 +257,8 @@ void * http_fcgimsg_open (void * vsrv, void * vhttpmsg) http_fcgimsg_request_encode(msg); http_fcgimsg_abort_encode(msg); - chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->fcgi_request), frameL(msg->fcgi_request), 1); + chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->fcgi_request), + frameL(msg->fcgi_request), NULL, NULL, 1); return msg; } @@ -410,7 +411,7 @@ void fcgi_predefined_param_encode (frame_p frm, HTTPMsg * httpmsg) num = json_num(jpara); for (i = 0; i < num; i++) { - ret = json_iter(jpara, i, (void **)&name, &namelen, (void **)&value, &valuelen, NULL); + ret = json_iter(jpara, i, 0, (void **)&name, &namelen, (void **)&value, &valuelen, NULL); if (ret < 0) continue; if (!name || namelen <= 0) continue; @@ -675,7 +676,7 @@ int http_fcgimsg_stdin_encode_chunk (void * vmsg, void * pbyte, int bytelen, voi fcgi_header_encode2(hdrbuf, FCGI_STDIN, /*msg->msgid*/1, contlen); chunk_add_buffer(msg->req_body_chunk, hdrbuf, 8); - chunk_add_bufptr(msg->req_body_chunk, (uint8 *)pbyte + pos, contlen, porig); + chunk_add_bufptr(msg->req_body_chunk, (uint8 *)pbyte + pos, contlen, porig, NULL); padding = contlen % 8; if (padding > 0) padding = 8 - padding; diff --git a/src/http_listen.c b/src/http_listen.c index 84bb2be..47c14a2 100644 --- a/src/http_listen.c +++ b/src/http_listen.c @@ -713,7 +713,7 @@ int http_host_build (void * vhl, void * jhl) num = json_num(jerrpage); for (j = 0; j < num; j++) { - ret = json_iter(jerrpage, j, (void **)&hname, &keylen, + ret = json_iter(jerrpage, j, 0, (void **)&hname, &keylen, (void **)&value, &valuelen, NULL); if (ret > 0 && hname && keylen > 0) { code = strtol(hname, NULL, 10); diff --git a/src/http_mgmt.c b/src/http_mgmt.c index a2ce5db..b7f548d 100644 --- a/src/http_mgmt.c +++ b/src/http_mgmt.c @@ -812,7 +812,7 @@ int http_conf_mime_init (void * vmgmt) num = json_num(mimeobj); for (i = 0; i < num; i++) { - json_iter(mimeobj, i, (void **)&mime, &mimelen, (void **)&ext, &extlen, NULL); + json_iter(mimeobj, i, 0, (void **)&mime, &mimelen, (void **)&ext, &extlen, NULL); if (!mime || mimelen <= 0 || !ext || extlen <= 0) continue; diff --git a/src/http_proxy.c b/src/http_proxy.c index 59cb138..d194caf 100644 --- a/src/http_proxy.c +++ b/src/http_proxy.c @@ -222,6 +222,10 @@ void * http_proxy_srvmsg_open (void * vmsg, char * url, int urllen) proxymsg->SetURL(proxymsg, url, urllen, 1); proxymsg->req_url_type = msg->req_url_type; + str_cpy(proxymsg->req_ver, msg->req_ver); + proxymsg->req_ver_major = msg->req_ver_major; + proxymsg->req_ver_minor = msg->req_ver_minor; + proxymsg->dstport = proxymsg->req_port; str_cpy(proxymsg->srcip, msg->srcip); @@ -355,7 +359,7 @@ int http_proxy_srv_send (void * vsrvcon, void * vsrvmsg) isend = srvmsg->req_body_iolen >= climsg->req_body_length; if (rcvslen > 0) { - chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm); + chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm, NULL); } } else if (climsg->req_body_flag == BC_TE && num > 0) { @@ -365,7 +369,7 @@ int http_proxy_srv_send (void * vsrvcon, void * vsrvmsg) isend = chunk->gotall; if (ret >= 0 && rcvslen > 0) { - chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm); + chunk_add_bufptr(srvmsg->req_body_chunk, pbgn, rcvslen, frm, NULL); } climsg->req_body_iolen += rcvslen; @@ -511,7 +515,7 @@ int http_proxy_cli_send (void * vclicon, void * vclimsg) isend = climsg->res_body_iolen >= srvmsg->res_body_length ? 1 : 0; if (rcvslen > 0) { - chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm); + chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm, NULL); } } else if (srvmsg->res_body_flag == BC_TE && num > 0) { @@ -521,7 +525,7 @@ int http_proxy_cli_send (void * vclicon, void * vclimsg) isend = chunk->gotall; if (ret >= 0 && rcvslen > 0) { - chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm); + chunk_add_bufptr(climsg->res_body_chunk, pbgn, rcvslen, frm, NULL); } srvmsg->res_body_iolen += rcvslen; @@ -1060,6 +1064,10 @@ void * http_proxy_srv_cache_send (void * vmsg) srvmsg->SetURL(srvmsg, msg->fwdurl, msg->fwdurllen, 1); srvmsg->req_url_type = msg->req_url_type; + str_cpy(srvmsg->req_ver, msg->req_ver); + srvmsg->req_ver_major = msg->req_ver_major; + srvmsg->req_ver_minor = msg->req_ver_minor; + srvmsg->dstport = srvmsg->req_port; str_cpy(srvmsg->srcip, msg->srcip); diff --git a/src/http_request.c b/src/http_request.c index e9e6c12..c70994b 100644 --- a/src/http_request.c +++ b/src/http_request.c @@ -898,7 +898,8 @@ int http_req_encoding (void * vmsg, int encode) msg->reqsent = 0; msg->req_stream_sent = 0; - chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->req_stream), frameL(msg->req_stream), 1); + chunk_prepend_bufptr(msg->req_body_chunk, frameP(msg->req_stream), + frameL(msg->req_stream), NULL, NULL, 1); return 0; } diff --git a/src/http_response.c b/src/http_response.c index 66aca6c..e026eaa 100644 --- a/src/http_response.c +++ b/src/http_response.c @@ -656,7 +656,8 @@ int http_res_encoding (void * vmsg) msg->res_header_length = frameL(msg->res_stream); - chunk_prepend_bufptr(msg->res_body_chunk, frameP(msg->res_stream), frameL(msg->res_stream), 1); + chunk_prepend_bufptr(msg->res_body_chunk, frameP(msg->res_stream), + frameL(msg->res_stream), NULL, NULL, 1); #if defined _DEBUG print_response(msg, stderr); diff --git a/src/http_sndpxy.c b/src/http_sndpxy.c index b787f2f..1b91af4 100644 --- a/src/http_sndpxy.c +++ b/src/http_sndpxy.c @@ -73,7 +73,7 @@ int http_send_proxy_init (void * vmgmt) num = json_num(jsndpxy); for (i = 0; i < num; i++) { - ret = json_iter(jsndpxy, i, (void **)&key, &keylen, (void **)&data, &datalen, NULL); + ret = json_iter(jsndpxy, i, 0, (void **)&key, &keylen, (void **)&data, &datalen, NULL); if (ret <= 0) continue; if (!key || keylen <= 0) continue; if (!data || datalen <= 0) continue; diff --git a/src/http_srv.c b/src/http_srv.c index 2847b0a..0e3631a 100644 --- a/src/http_srv.c +++ b/src/http_srv.c @@ -345,20 +345,20 @@ void * http_srv_open (void * vmgmt, char * ip, int port, int ssl_link, int maxco strncpy(srv->ip, ip, sizeof(srv->ip)-1); srv->port = port; + } - srv->ssl_link = ssl_link; - if (srv->ssl_link) { + srv->ssl_link = ssl_link; + if (srv->ssl_link) { #ifdef HAVE_OPENSSL - if (mgmt->srv_sslctx) { - srv->sslctx = mgmt->srv_sslctx; - srv->sslctx_alloc = 0; - } else { - srv->sslctx = http_ssl_client_ctx_init(mgmt->srv_con_cert, - mgmt->srv_con_prikey, mgmt->srv_con_cacert); - srv->sslctx_alloc = 1; - } -#endif + if (mgmt->srv_sslctx) { + srv->sslctx = mgmt->srv_sslctx; + srv->sslctx_alloc = 0; + } else { + srv->sslctx = http_ssl_client_ctx_init(mgmt->srv_con_cert, + mgmt->srv_con_prikey, mgmt->srv_con_cacert); + srv->sslctx_alloc = 1; } +#endif } srv->maxcon = maxcon; @@ -512,7 +512,7 @@ int http_srv_msg_dns (void * vmsg, void * cb) if (!dnscb) dnscb = http_srv_msg_dns_cb; if (msg->proxy && msg->proxyport > 0) { - ret = dns_query(mgmt->pcore, msg->proxy, msg->proxyport, dnscb, msg); + ret = dns_query(mgmt->pcore, msg->proxy, -1, dnscb, msg); } else { ret = dns_query(mgmt->pcore, msg->req_host, msg->req_hostlen, dnscb, msg); } diff --git a/src/http_srv_io.c b/src/http_srv_io.c index 44ffa5f..f1357b4 100644 --- a/src/http_srv_io.c +++ b/src/http_srv_io.c @@ -854,7 +854,7 @@ int http_srv_resbody_parse (void * vcon, void * vmsg, int64 * offset, int64 * sa } else { chunk_add_bufptr(msg->res_body_chunk, frameP(msg->res_body_stream), - frameL(msg->res_body_stream), NULL); + frameL(msg->res_body_stream), NULL, NULL); } return 1; diff --git a/src/http_uri.c b/src/http_uri.c index 5801492..45c7c9e 100644 --- a/src/http_uri.c +++ b/src/http_uri.c @@ -161,7 +161,7 @@ int http_uri_parse (void * vuri) uri->scheme = pbgn; uri->schemelen = p - 1 - pbgn; - if (uri->schemelen == 5 && strncasecmp(uri->scheme, "https", 8) == 0) + if (uri->schemelen == 5 && strncasecmp(uri->scheme, "https", 5) == 0) uri->ssl_link = 1; else uri->ssl_link = 0;