You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by sj...@apache.org on 2010/02/17 05:12:02 UTC
svn commit: r910817 -
/incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc
Author: sjiang
Date: Wed Feb 17 04:12:02 2010
New Revision: 910817
URL: http://svn.apache.org/viewvc?rev=910817&view=rev
Log:
TS-191: Missing :port in the Host: header for forward requests to target with non-default port
Fixed the header spoofing logic to correctly check and insert the port
Author: Steve Jiang
Review: Vijaya Mamidi
Modified:
incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc
Modified: incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc
URL: http://svn.apache.org/viewvc/incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc?rev=910817&r1=910816&r2=910817&view=diff
==============================================================================
--- incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc (original)
+++ incubator/trafficserver/traffic/trunk/proxy/http2/HttpTransact.cc Wed Feb 17 04:12:02 2010
@@ -1089,6 +1089,21 @@
if ((hostname = url->host_get(&hostname_len)) == NULL)
s->hdr_info.client_req_is_server_style = true;
+ s->orig_scheme = (scheme = url->scheme_get_wksidx());
+
+ s->method = s->hdr_info.client_request.method_get_wksidx();
+ if (scheme < 0 && s->method != HTTP_WKSIDX_CONNECT) {
+ if (s->client_info.port_attribute == SERVER_PORT_SSL) {
+ url->scheme_set(URL_SCHEME_HTTPS, URL_LEN_HTTPS);
+ s->orig_scheme = URL_WKSIDX_HTTPS;
+ } else {
+ url->scheme_set(URL_SCHEME_HTTP, URL_LEN_HTTP);
+ s->orig_scheme = URL_WKSIDX_HTTP;
+ }
+ }
+ if (s->method == HTTP_WKSIDX_CONNECT && url->port_get() == 0)
+ url->port_set(80);
+
// If the incoming request is proxy-style AND contains a Host header,
// then remove the Host header to prevent content spoofing.
@@ -1098,15 +1113,26 @@
max_forwards = max_forwards_f->value_get_int();
}
- if ((max_forwards != 0) && !s->hdr_info.client_req_is_server_style) {
+ if ((max_forwards != 0) && !s->hdr_info.client_req_is_server_style && s->method != HTTP_WKSIDX_CONNECT) {
MIMEField *host_field = s->hdr_info.client_request.field_find(MIME_FIELD_HOST, MIME_LEN_HOST);
- int host_val_len;
- const char *host_val;
+ int host_val_len = hostname_len;
+ const char **host_val = &hostname;
+ int req_host_val_len;
+ const char *req_host_val;
+ int port = url->port_get_raw();
+ char *buf = NULL;
+
+ if (port > 0) {
+ buf = (char *) xmalloc(host_val_len + 15);
+ strncpy(buf, hostname, host_val_len);
+ host_val_len += snprintf(buf + host_val_len, host_val_len + 15, ":%u", port);
+ host_val = (const char**)(&buf);
+ }
if (!host_field ||
(s->http_config_param->avoid_content_spoofing &&
- ((host_val = host_field->value_get(&host_val_len)) == NULL ||
- host_val_len != hostname_len || strncasecmp(hostname, host_val, hostname_len) != 0))) {
+ ((req_host_val = host_field->value_get(&req_host_val_len)) == NULL ||
+ host_val_len != req_host_val_len || strncasecmp(*host_val, req_host_val, host_val_len) != 0))) {
// instead of deleting the Host: header, set it to URL host for all requests (including HTTP/1.0)
if (!host_field) {
@@ -1114,8 +1140,11 @@
s->hdr_info.client_request.field_attach(host_field);
}
- s->hdr_info.client_request.field_value_set(host_field, hostname, hostname_len);
+ s->hdr_info.client_request.field_value_set(host_field, *host_val, host_val_len);
}
+
+ if (buf)
+ xfree(buf);
}
if (s->http_config_param->normalize_ae_gzip) {
@@ -1133,21 +1162,6 @@
}
}
- s->orig_scheme = (scheme = url->scheme_get_wksidx());
-
- s->method = s->hdr_info.client_request.method_get_wksidx();
- if (scheme < 0 && s->method != HTTP_WKSIDX_CONNECT) {
- if (s->client_info.port_attribute == SERVER_PORT_SSL) {
- url->scheme_set(URL_SCHEME_HTTPS, URL_LEN_HTTPS);
- s->orig_scheme = URL_WKSIDX_HTTPS;
- } else {
- url->scheme_set(URL_SCHEME_HTTP, URL_LEN_HTTP);
- s->orig_scheme = URL_WKSIDX_HTTP;
- }
- }
- if (s->method == HTTP_WKSIDX_CONNECT && url->port_get() == 0)
- url->port_set(80);
-
////////////////////////////////////////////////////////
// First check for the presence of a host header or //
// the availability of the host name through the url. //