You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Johannes Koch <ko...@w3development.de> on 2005/03/02 17:20:57 UTC

HTTP HEAD problem with some server

Hi there,

I tried to make a HEAD request to <http://www.niedersachsen.de/>.

Code is like this:

  String uri = "http://www.niedersachsen.de/";
  HttpClient httpClient = new HttpClient();
  HttpMethod httpMethod = new HeadMethod(uri);
  try
  {
      int responseCode = httpClient.executeMethod(httpMethod);
      System.out.println(responseCode);
  }
  catch (Exception e)
  {
      e.printStackTrace();
  }
  finally
  {
      httpMethod.releaseConnection();
  }

I used HttpClient 2.0.2 or 3.0-rc1. Both hang at

   while ((ch = inputStream.read()) >= 0) {

in HttpParser.readRawLine(InputStream inputStream)

If I make a HEAD request via telnet, I get the following response:

HTTP/1.1 302 Found
Date: Wed, 02 Mar 2005 15:53:03 GMT
Server: Apache
Location: http://www.niedersachsen.de/home.jsp
Content-Type: text/html; charset=iso-8859-1
-- 
Johannes Koch
In te domine speravi; non confundar in aeternum.
                             (Te Deum, 4th cent.)


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


Re: HTTP HEAD problem with some server

Posted by Oleg Kalnichevski <ol...@apache.org>.
To put this whole issue to an end this code produces no response and
times out, which in my opinion clearly indicates a server side issue:

Socket socket = SocketFactory.getDefault().
 createSocket("www.niedersachsen.de", 80);
socket.setSoTimeout(5000);
try {
  Writer out = new OutputStreamWriter(
    socket.getOutputStream(), "ISO-8859-1");
  out.write("HEAD / HTTP/1.1\r\n");  
  out.write("Host: www.niedersachsen.de:\r\n");  
  out.write("Agent: TEST\r\n");  
  out.write("\r\n");  
  out.flush();  
  BufferedReader in = new BufferedReader(
    new InputStreamReader(socket.getInputStream(), "ISO-8859-1"));
  String line = null;
  while ((line = in.readLine()) != null) {
    System.out.println(line);
  }
} finally {
  socket.close(); 
}

The same code works just fine if HEAD is replaced with GET.

Oleg


On Wed, 2005-03-02 at 17:20 +0100, Johannes Koch wrote:
> Hi there,
> 
> I tried to make a HEAD request to <http://www.niedersachsen.de/>.
> 
> Code is like this:
> 
>   String uri = "http://www.niedersachsen.de/";
>   HttpClient httpClient = new HttpClient();
>   HttpMethod httpMethod = new HeadMethod(uri);
>   try
>   {
>       int responseCode = httpClient.executeMethod(httpMethod);
>       System.out.println(responseCode);
>   }
>   catch (Exception e)
>   {
>       e.printStackTrace();
>   }
>   finally
>   {
>       httpMethod.releaseConnection();
>   }
> 
> I used HttpClient 2.0.2 or 3.0-rc1. Both hang at
> 
>    while ((ch = inputStream.read()) >= 0) {
> 
> in HttpParser.readRawLine(InputStream inputStream)
> 
> If I make a HEAD request via telnet, I get the following response:
> 
> HTTP/1.1 302 Found
> Date: Wed, 02 Mar 2005 15:53:03 GMT
> Server: Apache
> Location: http://www.niedersachsen.de/home.jsp
> Content-Type: text/html; charset=iso-8859-1


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


Re: HTTP HEAD problem with some server

Posted by Johannes Koch <ko...@w3development.de>.
Ortwin,

Ortwin Glück wrote:

> Could you provide a JUnit test case that reliably reproduces the problem?

No, unfortunately I never wrote a JUnit test case. But when I use the 
code from my first mail and debug, it hangs at this line in HttpParser.
-- 
Johannes Koch
In te domine speravi; non confundar in aeternum.
                             (Te Deum, 4th cent.)


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


Re: HTTP HEAD problem with some server

Posted by Ortwin Glück <or...@nose.ch>.

Johannes Koch wrote:
> Hi Julius,
> 
> Julius Davies wrote:
> 
>> Httpclient is following the redirect (the "location" header),
> 
> 
> Really? It doesn't even read the
> 
> HTTP/1.1 302 Found
> 
> line.
> 
>> Also, you should be setting the socket timeout and the connection
>> timeout:
> 
> 
> That's what I already do.

Johannes,

Could you provide a JUnit test case that reliably reproduces the problem?

Thanks

Ortwin Glück

-- 
  _________________________________________________________________
  NOSE applied intelligence ag

  ortwin glück                      [www]      http://www.nose.ch
  software engineer
  hardturmstrasse 171               [pgp id]           0x81CF3416
  8005 zürich                       [office]      +41-1-277 57 35
  switzerland                       [fax]         +41-1-277 57 12

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


Re: HTTP HEAD problem with some server

Posted by Julius Davies <ju...@cucbc.com>.
Ortwin,

Thanks for pointing that out!  I didn't know that.

Julius



On Thu, 2005-03-03 at 18:18 +0100, Ortwin Glück wrote:
> Julius,
> 
> a HTTP/1.1 request must include a Host header.
> 
> $ telnet www.niedersachsen.de 80
> Trying 195.37.201.132...
> Connected to cms.niedersachsen.de.
> Escape character is '^]'.
> HEAD /home.jsp HTTP/1.1
> Host: cms.niedersachsen.de
> 
> HTTP/1.1 404 Not Found
> Date: Thu, 03 Mar 2005 17:14:42 GMT
> Server: Apache
> Content-Type: text/html; charset=UTF-8
> pragma: no-cache
> 
> Connection closed by foreign host.
> 
> It might actually be a HTTP version issue, as:
> 
> $ telnet www.niedersachsen.de 80
> Trying 195.37.201.132...
> Connected to cms.niedersachsen.de.
> Escape character is '^]'.
> HEAD /home.jsp HTTP/1.0
> 
> does not return.
> 
> Julius Davies wrote:
> > Hi, Johannes,
> > 
> > It does read that line.  If you turned on the "wire tracing" you would
> > see that.  Behind the scenes HttpClient is following the redirect, and
> > the 2nd request is not getting any response.
> > 
> > To turn on "wire tracing":
> > http://jakarta.apache.org/commons/httpclient/logging.html
> > 
> > Your server does not reply to "HEAD" requests to "/home.jsp":
> > 
> > $ telnet www.niedersachsen.de 80
> > Trying 195.37.201.132...
> > Connected to cms.niedersachsen.de.
> > Escape character is '^]'.
> > HEAD /home.jsp HTTP/1.1
> > 
> > [no response....]
> > 
> > 
> > yours,
> > 
> > Julius
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
> 

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


Re: HTTP HEAD problem with some server

Posted by Ortwin Glück <or...@nose.ch>.
Julius,

a HTTP/1.1 request must include a Host header.

$ telnet www.niedersachsen.de 80
Trying 195.37.201.132...
Connected to cms.niedersachsen.de.
Escape character is '^]'.
HEAD /home.jsp HTTP/1.1
Host: cms.niedersachsen.de

HTTP/1.1 404 Not Found
Date: Thu, 03 Mar 2005 17:14:42 GMT
Server: Apache
Content-Type: text/html; charset=UTF-8
pragma: no-cache

Connection closed by foreign host.

It might actually be a HTTP version issue, as:

$ telnet www.niedersachsen.de 80
Trying 195.37.201.132...
Connected to cms.niedersachsen.de.
Escape character is '^]'.
HEAD /home.jsp HTTP/1.0

does not return.

Julius Davies wrote:
> Hi, Johannes,
> 
> It does read that line.  If you turned on the "wire tracing" you would
> see that.  Behind the scenes HttpClient is following the redirect, and
> the 2nd request is not getting any response.
> 
> To turn on "wire tracing":
> http://jakarta.apache.org/commons/httpclient/logging.html
> 
> Your server does not reply to "HEAD" requests to "/home.jsp":
> 
> $ telnet www.niedersachsen.de 80
> Trying 195.37.201.132...
> Connected to cms.niedersachsen.de.
> Escape character is '^]'.
> HEAD /home.jsp HTTP/1.1
> 
> [no response....]
> 
> 
> yours,
> 
> Julius

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


Re: HTTP HEAD problem with some server

Posted by Julius Davies <ju...@cucbc.com>.
Hi, Johannes,

It does read that line.  If you turned on the "wire tracing" you would
see that.  Behind the scenes HttpClient is following the redirect, and
the 2nd request is not getting any response.

To turn on "wire tracing":
http://jakarta.apache.org/commons/httpclient/logging.html

Your server does not reply to "HEAD" requests to "/home.jsp":

$ telnet www.niedersachsen.de 80
Trying 195.37.201.132...
Connected to cms.niedersachsen.de.
Escape character is '^]'.
HEAD /home.jsp HTTP/1.1

[no response....]


yours,

Julius


On Thu, 2005-03-03 at 10:31 +0100, Johannes Koch wrote:
> Hi Julius,
> 
> Julius Davies wrote:
> > Httpclient is following the redirect (the "location" header),
> 
> Really? It doesn't even read the
> 
> HTTP/1.1 302 Found
> 
> line.
> 
> > Also, you should be setting the socket timeout and the connection
> > timeout:
> 
> That's what I already do.

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


Re: HTTP HEAD problem with some server

Posted by Johannes Koch <ko...@w3development.de>.
Hi Julius,

Julius Davies wrote:
> Httpclient is following the redirect (the "location" header),

Really? It doesn't even read the

HTTP/1.1 302 Found

line.

> Also, you should be setting the socket timeout and the connection
> timeout:

That's what I already do.
-- 
Johannes Koch
In te domine speravi; non confundar in aeternum.
                             (Te Deum, 4th cent.)


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


Re: HTTP HEAD problem with some server

Posted by Johannes Koch <ko...@w3development.de>.
Julius,

Julius Davies wrote:

> Looks
> like "/home.jsp" doesn't bother responding to HEAD requests!

It does. Try with telnet.

>  It seems
> fine with GET requests though.

Yes

>  I just tried with telnet.

As I said, I tried HEAD with telnet. And it seems to be fine.

> You should either tell HttpClient to not follow redirects,

This does not help.

-- 
Johannes Koch
In te domine speravi; non confundar in aeternum.
                             (Te Deum, 4th cent.)


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


Re: HTTP HEAD problem with some server

Posted by Julius Davies <ju...@cucbc.com>.
Hi, Johannes,

Httpclient is following the redirect (the "location" header), and the
server is not writing anything back on this subsequent request.   Looks
like "/home.jsp" doesn't bother responding to HEAD requests!  It seems
fine with GET requests though.  I just tried with telnet.

You should either tell HttpClient to not follow redirects, or use GET.

Also, you should be setting the socket timeout and the connection
timeout:

Httpclient client = new HttpClient();
client.setTimeout( 30000 ); // 30 seconds
client.setConnectionTimeout( 30000 ); // 30 seconds

Part of me wishes HttpClient set these timeouts for us by default, and
let us set them to -1 (infinite) if we really wanted to.

yours,

Julius Davies


On Wed, 2005-02-03 at 17:20 +0100, Johannes Koch wrote:
> Hi there,
> 
> I tried to make a HEAD request to <http://www.niedersachsen.de/>.
> 
> Code is like this:
> 
>   String uri = "http://www.niedersachsen.de/";
>   HttpClient httpClient = new HttpClient();
>   HttpMethod httpMethod = new HeadMethod(uri);
>   try
>   {
>       int responseCode = httpClient.executeMethod(httpMethod);
>       System.out.println(responseCode);
>   }
>   catch (Exception e)
>   {
>       e.printStackTrace();
>   }
>   finally
>   {
>       httpMethod.releaseConnection();
>   }
> 
> I used HttpClient 2.0.2 or 3.0-rc1. Both hang at
> 
>    while ((ch = inputStream.read()) >= 0) {
> 
> in HttpParser.readRawLine(InputStream inputStream)
> 
> If I make a HEAD request via telnet, I get the following response:
> 
> HTTP/1.1 302 Found
> Date: Wed, 02 Mar 2005 15:53:03 GMT
> Server: Apache
> Location: http://www.niedersachsen.de/home.jsp
> Content-Type: text/html; charset=iso-8859-1

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