You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Jeremy Mayhew <Ma...@orbital.com> on 2008/04/04 20:14:19 UTC

Dealing with a server that doesn't always respond with an HTTP response header

Hi,

I am using htmlunit+httpclient to test an embedded web application.
Unfortunately there is a large set of requests for which this embedded
webserver does not respond with an HTTP header, but instead splats the body
without a header.  The httpclient rightly throws a protocol exception out
on the malformed response.  (Firefox and IE will still render the pages
without the HTTP response header, so it "works" for the user case.  I can't
change the embedded web server code.)

I was wondering if there is an easy way to configure httpclient to do best
effort on the response and assume that the response is OK so that the
response body can be processed as a valid HTML page.

Thanks!
Jeremy Mayhew


-----------------------------------------
Notice:  This e-mail is intended solely for use of the individual
or entity to which it is addressed and may contain information that
is proprietary, privileged and exempt from disclosure under
applicable law.  If the reader is not the intended recipient or
agent responsible for delivering the message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly
prohibited.  This communication may also contain data subject to
U.S. export laws.  If so, that data subject to the International
Traffic in Arms Regulation cannot be disseminated, distributed or
copied to foreign nationals, residing in the U.S. or abroad, absent
the express prior approval of the U.S. Department of State.   If
you have received this communication in error, please notify the
sender by reply e-mail and destroy the e-mail message and any
physical copies made of the communication.  Thank you.

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


Re: Dealing with a server that doesn't always respond with an HTTP response header

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Fri, 2008-04-04 at 14:14 -0400, Jeremy Mayhew wrote:
> Hi,
> 
> I am using htmlunit+httpclient to test an embedded web application.
> Unfortunately there is a large set of requests for which this embedded
> webserver does not respond with an HTTP header, but instead splats the body
> without a header.  The httpclient rightly throws a protocol exception out
> on the malformed response.  (Firefox and IE will still render the pages
> without the HTTP response header, so it "works" for the user case.  I can't
> change the embedded web server code.)
> 
> I was wondering if there is an easy way to configure httpclient to do best
> effort on the response and assume that the response is OK so that the
> response body can be processed as a valid HTML page.
> 

Not easily. HttpClient assumes at least a certain degree of sanity in
HTTP responses. If your application really needs to handle a complete
garbage, the only way I see is to implement a custom HTTP connection
that can test whether an incoming stream contains a valid HTTP response
or an HTML content, and generate a dummy response in the latter case.
One note though, this is possible with HttpClient 4.0 only. You are out
of luck with HttpClient 3.x 

Hope this helps

Oleg


> Thanks!
> Jeremy Mayhew
> 
> 
> -----------------------------------------
> Notice:  This e-mail is intended solely for use of the individual
> or entity to which it is addressed and may contain information that
> is proprietary, privileged and exempt from disclosure under
> applicable law.  If the reader is not the intended recipient or
> agent responsible for delivering the message to the intended
> recipient, you are hereby notified that any dissemination,
> distribution or copying of this communication is strictly
> prohibited.  This communication may also contain data subject to
> U.S. export laws.  If so, that data subject to the International
> Traffic in Arms Regulation cannot be disseminated, distributed or
> copied to foreign nationals, residing in the U.S. or abroad, absent
> the express prior approval of the U.S. Department of State.   If
> you have received this communication in error, please notify the
> sender by reply e-mail and destroy the e-mail message and any
> physical copies made of the communication.  Thank you.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


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