| 1398 | } |
| 1399 | |
| 1400 | void |
| 1401 | HttpTransact::ModifyRequest(State *s) |
| 1402 | { |
| 1403 | int scheme, hostname_len; |
| 1404 | HTTPHdr &request = s->hdr_info.client_request; |
| 1405 | static const int PORT_PADDING = 8; |
| 1406 | |
| 1407 | TxnDbg(dbg_ctl_http_trans, "START HttpTransact::ModifyRequest"); |
| 1408 | |
| 1409 | // Initialize the state vars necessary to sending error responses |
| 1410 | bootstrap_state_variables_from_request(s, &request); |
| 1411 | |
| 1412 | //////////////////////////////////////////////// |
| 1413 | // If there is no scheme, default to http // |
| 1414 | //////////////////////////////////////////////// |
| 1415 | URL *url = request.url_get(); |
| 1416 | |
| 1417 | s->orig_scheme = (scheme = url->scheme_get_wksidx()); |
| 1418 | |
| 1419 | s->method = request.method_get_wksidx(); |
| 1420 | if (scheme < 0 && s->method != HTTP_WKSIDX_CONNECT) { |
| 1421 | if (s->client_info.port_attribute == HttpProxyPort::TRANSPORT_SSL) { |
| 1422 | url->scheme_set(URL_SCHEME_HTTPS, URL_LEN_HTTPS); |
| 1423 | s->orig_scheme = URL_WKSIDX_HTTPS; |
| 1424 | } else { |
| 1425 | url->scheme_set(URL_SCHEME_HTTP, URL_LEN_HTTP); |
| 1426 | s->orig_scheme = URL_WKSIDX_HTTP; |
| 1427 | } |
| 1428 | } |
| 1429 | |
| 1430 | if (s->method == HTTP_WKSIDX_CONNECT && !request.is_port_in_header()) { |
| 1431 | url->port_set(80); |
| 1432 | } |
| 1433 | |
| 1434 | // Ugly - this must come after the call to url->scheme_set or |
| 1435 | // it can't get the scheme properly and the wrong data is cached. |
| 1436 | // The solution should be to move the scheme detecting logic in to |
| 1437 | // the header class, rather than doing it in a random bit of |
| 1438 | // external code. |
| 1439 | const char *buf = request.host_get(&hostname_len); |
| 1440 | if (!request.is_target_in_url()) { |
| 1441 | s->hdr_info.client_req_is_server_style = true; |
| 1442 | } |
| 1443 | // Copy out buf to a hostname just in case its heap header memory is freed during coalescing |
| 1444 | // due to later HdrHeap operations |
| 1445 | char *hostname = static_cast<char *>(alloca(hostname_len + PORT_PADDING)); |
| 1446 | memcpy(hostname, buf, hostname_len); |
| 1447 | |
| 1448 | // Make clang analyzer happy. hostname is non-null iff request.is_target_in_url(). |
| 1449 | ink_assert(hostname || s->hdr_info.client_req_is_server_style); |
| 1450 | |
| 1451 | // If the incoming request is proxy-style make sure the Host: header |
| 1452 | // matches the incoming request URL. The exception is if we have |
| 1453 | // Max-Forwards set to 0 in the request |
| 1454 | int max_forwards = -1; // -1 is a valid value meaning that it didn't find the header |
| 1455 | if (request.presence(MIME_PRESENCE_MAX_FORWARDS)) { |
| 1456 | max_forwards = request.get_max_forwards(); |
| 1457 | } |
nothing calls this directly
no test coverage detected