You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Taisuke Yamada <ta...@iij.ad.jp> on 2002/03/28 11:19:03 UTC

[PATCH] HTTP proxy, ab, and Host: as a hop-by-hop header?

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 <ta...@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 ---

Re: [PATCH] HTTP proxy, ab, and Host: as a hop-by-hop header?

Posted by di...@covalent.net.
> 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.

I am fixing this... but the puzzle I have is that -always- adding
a ':80' in the Host: is kind of causing an extra 3 bytes on the wire for
each request - which makes it harder to compare the results a runs
against each other.

Let me puzzle a bit.

Dw


Re: [PATCH] HTTP proxy, ab, and Host: as a hop-by-hop header?

Posted by di...@covalent.net.
Yes - our mails crossed - quite some change between earlier drafts and the
final RFC2616 which has little guidance for proxies.

Dw.

-- 
Dirk-Willem van Gulik

On Fri, 29 Mar 2002, Chuck Murcko wrote:

> For HTTP 1.1 you should use the Host: urlhost[:urlport] form. AFAICS
> these are the simplest possible proxy requests:
>
> HTTP 1.0:
> GET http://www.ibm.com/ HTTP/1.0
> <cr><cr>
>
> HTTP 1.1:
> GET http://www.ibm.com/ HTTP/1.1
> Host: www.ibm.com
> <cr><cr>
>
> Chuck
>
> On Friday, March 29, 2002, at 02:41 PM, dirkx@covalent.net wrote:
>
> >
> > Actually:
> >
> >> 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.
> >
> > I am double checking the spec. To verify what exactly should be send -
> > as
> > one could also have to consider a proxy on a vhost.
> >
> > To summarize, in the case of a PROXY we have
> >
> > 	proxyhost + proxyport
> > 	full URL (http://urlhost:urlport/foo) (or ftp, etc)
> >
> > and we do
> >
> > 	connect to proxyhost, proxyport
> > 	then say 'GET full-URL HTTP...'
> >
> > And now the question is, do we do
> >
> > 	Host: proxyhost [:proxyport]
> > or
> > 	Host: urlhost[:urlport]
> > or
> > 	<nil> (i.e. explictly NO Host:).
> >
> > Dw
> >
>
>


Re: [PATCH] HTTP proxy, ab, and Host: as a hop-by-hop header?

Posted by Chuck Murcko <ch...@topsail.org>.
For HTTP 1.1 you should use the Host: urlhost[:urlport] form. AFAICS 
these are the simplest possible proxy requests:

HTTP 1.0:
GET http://www.ibm.com/ HTTP/1.0
<cr><cr>

HTTP 1.1:
GET http://www.ibm.com/ HTTP/1.1
Host: www.ibm.com
<cr><cr>

Chuck

On Friday, March 29, 2002, at 02:41 PM, dirkx@covalent.net wrote:

>
> Actually:
>
>> 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.
>
> I am double checking the spec. To verify what exactly should be send - 
> as
> one could also have to consider a proxy on a vhost.
>
> To summarize, in the case of a PROXY we have
>
> 	proxyhost + proxyport
> 	full URL (http://urlhost:urlport/foo) (or ftp, etc)
>
> and we do
>
> 	connect to proxyhost, proxyport
> 	then say 'GET full-URL HTTP...'
>
> And now the question is, do we do
>
> 	Host: proxyhost [:proxyport]
> or
> 	Host: urlhost[:urlport]
> or
> 	<nil> (i.e. explictly NO Host:).
>
> Dw
>


Re: [PATCH] HTTP proxy, ab, and Host: as a hop-by-hop header?

Posted by di...@covalent.net.
Actually:

> 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.

I am double checking the spec. To verify what exactly should be send - as
one could also have to consider a proxy on a vhost.

To summarize, in the case of a PROXY we have

	proxyhost + proxyport
	full URL (http://urlhost:urlport/foo) (or ftp, etc)

and we do

	connect to proxyhost, proxyport
	then say 'GET full-URL HTTP...'

And now the question is, do we do

	Host: proxyhost [:proxyport]
or
	Host: urlhost[:urlport]
or
	<nil> (i.e. explictly NO Host:).

Dw