httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Taisuke Yamada <...@iij.ad.jp>
Subject [PATCH] HTTP proxy, ab, and Host: as a hop-by-hop header?
Date Thu, 28 Mar 2002 10:19:03 GMT

Hi.

I do believe it's been discussed at least once, but I have a
question on Host: header generated by ab(1).

The problem I'm encountering is that ab(1) generates Host: header
pointing to proxy server instead of real destination host.
Due to this behavior, proxy server (not mod_proxy, BTW) is failing
to send a valid HTTP request to destintion webserver using name-based
virtualhost, as it simply passes Host: header with its (proxy
server's) hostname in it.

After some experiments, I found ab(1) that comes with 2.0.32
does not behave this way, and simply puts destination hostname
in Host: header even when HTTP proxy is in use. This seems to
be the correct behavior.

# Current ab-2.0.32 cannot interoperate with proxy server,
# but that's an another story...(patch attached below)

I think this is a bug, but I'm not yet completely certain on that,
as comment left in ab.c shows that this code was included with
some intent. I suspect this was done to test mod_proxy running
on name-based virtualhost.

# mod_proxy does not have problem with above Host: header, because
# mod_proxy always drops Host: header client had sent.

As it is stated

  - ab is a tool for benchmarking the performance of your
    Apache HyperText Transfer Protocol (HTTP) server.

  - Ab does not implement HTTP/1.x fully; instead, it only
    accepts some 'expected' forms of responses.

in the manual, I may be plain wrong to expect ab behave like
other HTTP client. But is there any possibility to have a
patch accepted if I added new option to ab so it will behave
more like standard client?

Since I first made a quick fix to ab.c to make it work with
other proxy servers, I'm attaching it in this email anyway.
There are two patches, one for ab-1.3 and the other for ab-2.0.32.

If there's any chance to get new option (like -rfc as in -ansi
in gcc?) into ab, I'll probably make one and submit it also.

Best Regards,
--
Taisuke Yamada <tai@iij.ad.jp>
Internet Initiative Japan Inc., Technical Planning Division

* Quick fix to make latest ab-1.3d (or CVS version) generate Host:
  header using destination hostname. Also adds port number.

--- for ab-1.3d --- for ab-1.3d --- for ab-1.3d --- for ab-1.3d ---
--- ab.c.orig	Thu Mar 28 14:32:50 2002
+++ ab.c	Thu Mar 28 14:38:14 2002
@@ -1186,7 +1186,7 @@
          * the proxy - whistl quoting the
 	 * full URL in the GET/POST line.
 	 */
-	host  = proxyhost;
+	host  = hostname;
 	connectport = proxyport;
     	url_on_request = fullurl;
     }
@@ -1234,7 +1234,7 @@
 	sprintf(request, "%s %s HTTP/1.0\r\n"
 		"User-Agent: ApacheBench/%s\r\n"
 		"%s" "%s" "%s"
-		"Host: %s\r\n"
+		"Host: %s:%d\r\n"
 		"Accept: */*\r\n"
 		"%s" "\r\n",
 		(posting == 0) ? "GET" : "HEAD",
@@ -1242,13 +1242,13 @@
 		VERSION,
 		keepalive ? "Connection: Keep-Alive\r\n" : "",
 		cookie, auth, 
-		host, hdrs);
+		host, port, hdrs);
     }
     else {
 	sprintf(request, "POST %s HTTP/1.0\r\n"
 		"User-Agent: ApacheBench/%s\r\n"
 		"%s" "%s" "%s"
-		"Host: %s\r\n"
+		"Host: %s:%d\r\n"
 		"Accept: */*\r\n"
 		"Content-length: %d\r\n"
 		"Content-type: %s\r\n"
@@ -1258,7 +1258,7 @@
 		VERSION,
 		keepalive ? "Connection: Keep-Alive\r\n" : "",
 		cookie, auth,
-		host, postlen,
+		host, port, postlen,
 		(content_type[0]) ? content_type : "text/plain", hdrs);
     }
 
--- for ab-1.3d --- for ab-1.3d --- for ab-1.3d --- for ab-1.3d ---

* Quick fix to make latest ab-2.0.32 (or CVS version) work with
  HTTP proxy. This will prevent ab from dropping URL in HTTP
  request line, resulted in invalid HTTP request. Also adds port number.

--- for ab-2.0.32 --- ab-2.0.32 --- ab-2.0.32 --- ab-2.0.32 ---
--- ab.c.orig	Thu Mar 28 14:44:10 2002
+++ ab.c	Thu Mar 28 14:57:21 2002
@@ -274,8 +274,7 @@
 apr_port_t connectport;
 char *gnuplot;			/* GNUplot file */
 char *csvperc;			/* CSV Percentile file */
-char url[1024];
-char fullurl[1024];
+char *fullurl;
 int isproxy = 0;
 apr_short_interval_time_t aprtimeout = 30 * APR_USEC_PER_SEC;	/* timeout value */
  /*
@@ -1150,20 +1149,20 @@
 	sprintf(request, "%s %s HTTP/1.0\r\n"
 		"User-Agent: ApacheBench/%s\r\n"
 		"%s" "%s" "%s"
-		"Host: %s\r\n"
+		"Host: %s:%d\r\n"
 		"Accept: */*\r\n"
 		"%s" "\r\n",
 		(posting == 0) ? "GET" : "HEAD",
 		(isproxy) ? fullurl : path,
 		AP_SERVER_BASEREVISION,
 		keepalive ? "Connection: Keep-Alive\r\n" : "",
-		cookie, auth, host_field, hdrs);
+		cookie, auth, host_field, port, hdrs);
     }
     else {
 	sprintf(request, "POST %s HTTP/1.0\r\n"
 		"User-Agent: ApacheBench/%s\r\n"
 		"%s" "%s" "%s"
-		"Host: %s\r\n"
+		"Host: %s:%d\r\n"
 		"Accept: */*\r\n"
 		"Content-length: %" APR_SIZE_T_FMT "\r\n"
 		"Content-type: %s\r\n"
@@ -1173,7 +1172,7 @@
 		AP_SERVER_BASEREVISION,
 		keepalive ? "Connection: Keep-Alive\r\n" : "",
 		cookie, auth,
-		host_field, postlen,
+		host_field, port, postlen,
 		(content_type[0]) ? content_type : "text/plain", hdrs);
     }
 
@@ -1367,6 +1366,8 @@
     char *h;
     char *scope_id;
     apr_status_t rv;
+
+    fullurl = apr_pstrdup(cntxt, url);
 
     if (strlen(url) > 7 && strncmp(url, "http://", 7) == 0)
 	url += 7;
--- for ab-2.0.32 --- ab-2.0.32 --- ab-2.0.32 --- ab-2.0.32 ---

Mime
View raw message