commons-dev mailing list archives

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

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:

Index: HttpMethodBase.java
===================================================================
RCS file: /home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/HttpMethodBase.java,v
retrieving revision 1.21
diff -u -c -r1.21 HttpMethodBase.java
*** HttpMethodBase.java	15 Dec 2001 01:09:08 -0000	1.21
--- HttpMethodBase.java	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();
          requestHeaders.clear();
+ 	setRequestHeader("user-agent", userAgent);
          responseHeaders.clear();
          statusCode = -1;
          statusText = null;


Thanks,
Otis

_________________________________________________________________
iVillage.com: Solutions for Your Life 
Check out the most exciting women's community on the Web   
http://www.ivillage.com

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message