| 314 EventHandler *ev = sn->ev; |
314 EventHandler *ev = sn->ev; |
| 315 const char *method = pblock_findkeyval(pb_key_method, rq->reqpb); |
315 const char *method = pblock_findkeyval(pb_key_method, rq->reqpb); |
| 316 const char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); |
316 const char *uri = pblock_findkeyval(pb_key_uri, rq->reqpb); |
| 317 const char *query = pblock_findkeyval(pb_key_query, rq->reqpb); |
317 const char *query = pblock_findkeyval(pb_key_query, rq->reqpb); |
| 318 |
318 |
| |
319 char *host_header = pblock_findval("host-header", param); |
| |
320 |
| 319 const char *location = pblock_findval("location", param); |
321 const char *location = pblock_findval("location", param); |
| 320 if(location) { |
322 if(location) { |
| 321 cxstring loc = cx_str(location); |
323 cxstring loc = cx_str(location); |
| 322 if(cx_strprefix(uri, loc)) { |
324 if(cx_strprefix(uri, loc)) { |
| 323 if(loc.length > 0 && loc.ptr[loc.length-1] == '/') { |
325 if(loc.length > 0 && loc.ptr[loc.length-1] == '/') { |
| 412 proxy->read_buf_pos = 0; |
414 proxy->read_buf_pos = 0; |
| 413 proxy->ref = 1; |
415 proxy->ref = 1; |
| 414 |
416 |
| 415 // Some request/response headers should be removed or altered |
417 // Some request/response headers should be removed or altered |
| 416 // An empty string means, the header should be removed |
418 // An empty string means, the header should be removed |
| 417 pblock_nvinsert("host", "", proxy->request_header_rewrite); |
419 if(!host_header) { |
| |
420 pblock_nvinsert("host", "", proxy->request_header_rewrite); |
| |
421 } |
| 418 //pblock_nvinsert("connection", "", proxy->request_header_rewrite); |
422 //pblock_nvinsert("connection", "", proxy->request_header_rewrite); |
| 419 pblock_nvinsert("transfer-encoding", "", proxy->request_header_rewrite); |
423 pblock_nvinsert("transfer-encoding", "", proxy->request_header_rewrite); |
| 420 pblock_nvinsert("content-length", "", proxy->request_header_rewrite); |
424 pblock_nvinsert("content-length", "", proxy->request_header_rewrite); |
| 421 pblock_nvinsert("server", "", proxy->response_header_rewrite); |
425 pblock_nvinsert("server", "", proxy->response_header_rewrite); |
| 422 pblock_nvinsert("connection", "", proxy->response_header_rewrite); |
426 pblock_nvinsert("connection", "", proxy->response_header_rewrite); |
| 465 if(!addr_set) { |
469 if(!addr_set) { |
| 466 http_client_free(client); |
470 http_client_free(client); |
| 467 return REQ_ABORTED; |
471 return REQ_ABORTED; |
| 468 } |
472 } |
| 469 |
473 |
| |
474 // prepare host header |
| |
475 if(!host_header) { |
| |
476 if(!((srv_url.scheme_num == WS_URI_HTTP && srv_url.port == 80) || |
| |
477 (srv_url.scheme_num == WS_URI_HTTPS && srv_url.port == 443))) |
| |
478 { |
| |
479 // we have reserved enough space for the port |
| |
480 srvhost[srv_url.hostlen] = ':'; |
| |
481 snprintf(srvhost + srv_url.hostlen + 1, 8, "%d", (int)srv_url.port); |
| |
482 } |
| |
483 host_header = srvhost; |
| |
484 } |
| |
485 |
| 470 // add host header |
486 // add host header |
| 471 if(!((srv_url.scheme_num == WS_URI_HTTP && srv_url.port == 80) || |
487 if(http_client_add_request_header(client, cx_mutstr("host"), cx_mutstr(host_header))) { |
| 472 (srv_url.scheme_num == WS_URI_HTTPS && srv_url.port == 443))) |
|
| 473 { |
|
| 474 // we have reserved enough space for the port |
|
| 475 srvhost[srv_url.hostlen] = ':'; |
|
| 476 snprintf(srvhost + srv_url.hostlen, 8, "%d", (int)srv_url.port); |
|
| 477 } |
|
| 478 if(http_client_add_request_header(client, cx_mutstr("host"), cx_mutstr(srvhost))) { |
|
| 479 http_client_free(client); |
488 http_client_free(client); |
| 480 return REQ_ABORTED; |
489 return REQ_ABORTED; |
| 481 } |
490 } |
| 482 |
491 |
| 483 // add request headers to the client |
492 // add request headers to the client |