hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eugeny N Dzhurinsky <b...@redwerk.com>
Subject multiple "location" headers are getting concatenated?
Date Tue, 11 Jul 2006 15:00:02 GMT
Hello, I facing strange problem with HttpClient
For some reason if there are more than 1 Location header in response, all
headers are collected into single string, for instance - 

/madeline/?GCID=C1000x047&AID=10280172&PID=1453275, /madeline

I used this test:

import junit.framework.Assert;
import junit.framework.TestCase;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpMethodParams;

import java.io.IOException;

public class HTTPClientTest extends TestCase {

    HttpClient client;

    HttpMethod method;

    protected void setUp() throws Exception {
        client = new HttpClient();
        String url = "http://www.allaboardtoys.com/madeline/default.asp?GCID=C1000x047&AID=10280172&PID=1453275";
        URI uri = new URI(url, url.indexOf('%') != -1);
        method = new GetMethod();
        method.setURI(uri);
        HttpMethodParams params = method.getParams();
        params.setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
        params.setParameter(HttpClientParams.USER_AGENT, "Mozilla/4.0"
                + "(compatible; MSIE 6.0; Windows NT 5.1;)");
        method.setFollowRedirects(true);
    }

    public void testResultcode() {
        try {
            client.executeMethod(method);
            Assert.assertEquals(HttpStatus.SC_OK, method.getStatusCode());
        } catch (HttpException e) {
            e.printStackTrace(System.out);
        } catch (IOException e) {
            e.printStackTrace(System.out);
        }
    }
}


With tcpflow i found:

request was
---------------------------------------------------------------------------
GET /madeline/default.asp?GCID=C1000x047&AID=10280172&PID=1453275 HTTP/1.1
User-Agent: Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1;)
Host: www.allaboardtoys.com
---------------------------------------------------------------------------

and response

---------------------------------------------------------------------------
HTTP/1.1 302 Object moved
Server: Microsoft-IIS/5.0
Date: Tue, 11 Jul 2006 14:52:28 GMT
X-Powered-By: ASP.NET
P3P: policyref="http://www.allaboardtoys.com/w3c/p3p.xml"
Pragma: no-cache
cache-control: no-store
Cache-Control: no-cache, must-revalidate
Location: http://www.allaboardtoys.com/madeline/?GCID=C1000x047&AID=10280172&PID=1453275
Location: /madeline
Content-Length: 130
Content-Type: text/html
Expires: Mon, 10 Jul 2006 14:52:28 GMT
Set-Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=C08BA8AEFED14F27BF4EF3FF1CE0CD85;
expires=Wed, 26-Jul-2006 14:52:28 GMT; domain=allaboardtoys.com; path=/
Set-Cookie: ASPSESSIONIDCATQCDDQ=JLAADADBKEKJBHKKFALPEMHH; path=/
Cache-control: no-cache

<head><title>Object moved</title></head>
<body><h1>Object Moved</h1>This object may be found <a HREF="/madeline">here</a>.</body>
---------------------------------------------------------------------------

then next request

---------------------------------------------------------------------------
GET /madeline/?GCID=C1000x047&AID=10280172&PID=1453275, /madeline HTTP/1.1
User-Agent: Mozilla/4.0(compatible; MSIE 6.0; Windows NT 5.1;)
Host: www.allaboardtoys.com
Cookie: ShopperManager%2F=sts=nwc45&ShopperManager%2F=C08BA8AEFED14F27BF4EF3FF1CE0CD85
Cookie: ASPSESSIONIDCATQCDDQ=JLAADADBKEKJBHKKFALPEMHH
---------------------------------------------------------------------------

and finally

---------------------------------------------------------------------------
HTTP/1.1 400 Bad Request
Server: Microsoft-IIS/5.0
Date: Tue, 11 Jul 2006 14:52:28 GMT
Content-Type: text/html
Content-Length: 87

<html><head><title>Error</title></head><body>The parameter
is incorrect. </body></html>
---------------------------------------------------------------------------

As you can see, instead of http://www.allaboardtoys.com/madeline HttpClient
used

/madeline/?GCID=C1000x047&AID=10280172&PID=1453275, /madeline

which is wrong.

I tried to handle redirects manually, but contents of header "location" are 

http://www.allaboardtoys.com/madeline/?GCID=C1000x047&AID=10280172&PID=1453275, /madeline

Is it correct to split it by comma or I can get list of headers manually
somehow?

-- 
Eugene N Dzhurinsky

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message