Re: HeadMethodWebRequest problems
"Wolfgang Fahl" <[email protected]> Wed, 19 Aug 2009 12:47:42 +0200
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Organization | BITPlan GmbH |
| Message-ID | <[email protected]> |
Dear Dan,
thanks for pointing this out and supplying the testCase.
Subversion Revision 1040
http://httpunit.svn.sourceforge.net/viewvc/httpunit?view=rev&revision=1040
has the fix for it.
WebPageText.java contains your test. I have added an
assertion that no body is returned as asked for in
RFC 2616
http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
9.4 HEAD
The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in
response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about
the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent
modification.
The response to a HEAD request MAY be cacheable in the sense that the information contained in the response MAY be used to update a previously cached entity from
that resource. If the new field values indicate that the cached entity differs from the current entity (as would be indicated by a change in Content-Length, Content-MD5,
ETag or Last-Modified), then the cache MUST treat the cache entry as stale.
/**
* add test for HeadMethodWebRequest
* @author Dan Lipofsky 2009-08-19
* @throws Exception
*/
public void testHeadMethodWebRequest() throws Exception {
defineResource( "SimplePage.html",
"<html><head><title>A Sample Page</title></head>\n" +
"<body>Hello</body></html>\n" );
HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
WebConversation wc = new WebConversation();
// create a HeadMethodWebRequest
// see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html for definition
WebRequest request = new HeadMethodWebRequest( getHostPath() + "/SimplePage.html" );
WebResponse simplePage = wc.getResponse( request );
String text=simplePage.getText();
// no body should be returned
assertEquals("",text);
}
Keep up the good work!
Yours
Wolfgang
> I tried to use HeadMethodWebRequest, but I have problems because it is
> calling the HTMLParser I set with HTMLParserFactory.setHTMLParser(...)
> which it shouldn't be doing because HEAD will have no body in the response.
>
> I tried to look in the unit tests, and I see no tests
> for HeadMethodWebRequest. Perhaps the test server doesn't
> support it because this gave me a 404:
>
> public void testHead() throws Exception {
> defineResource( "SimplePage.html",
> "<html><head><title>A Sample Page</title></head>\n" +
> "<body>Hello</body></html>\n" );
> HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
> WebConversation wc = new WebConversation();
> WebRequest request = new HeadMethodWebRequest( getHostPath() + "/SimplePage.html" );
> WebResponse simplePage = wc.getResponse( request );
> }
BITPlan - smart solutions
Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
Tel. +49 2154 811-480, Fax +49 2154 811-481
Web: http://www.bitplan.de
bitplan GmbH, Willich - HRB 6820 Krefeld, VAT-ID: 10258040548,
Geschäftsführer: Wolfgang Fahl
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Httpunit-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/httpunit-develop