commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Can't set User-Agent header
Date Sun, 06 Jan 2002 02:45:45 GMT

I found out what was going on here.
I was setting the User-Agent request header correctly, but I was also calling recycle() on
my instance of GetMethod, which I wanted to reuse for multple URL fetches.

Method recycle() clears all request headers, among other things, which always removed my User-Agent
header, so HttpMethodBase would use its default one.

I like recycle(), and it makes sense that some request headers are reset (e.g. Host header),
but it makes less sense to erase some request headers that are likely to remain the same in
subsequent URL retrievals, such as the User-Agent header.

So how about this change to recycle() method in HttpMethodBase:

RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/,v
retrieving revision 1.21
diff -u -c -r1.21
***	15 Dec 2001 01:09:08 -0000	1.21
---	6 Jan 2002 02:41:52 -0000
*** 1110,1116 ****
--- 1110,1118 ----
          path = null;
          followRedirects = false;
          queryString = null;
+ 	String userAgent = ((Header)requestHeaders.get("user-agent")).getValue();
+ 	setRequestHeader("user-agent", userAgent);
          statusCode = -1;
          statusText = null;


_________________________________________________________________ Solutions for Your Life 
Check out the most exciting women's community on the Web

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message