[JWebUnit-development] [ jwebunit-Bugs-3190055 ] Handling same named Headers with HtmlUnit
Brought to you by:
henryju
From: SourceForge.net <no...@so...> - 2011-03-11 13:47:24
|
Bugs item #3190055, was opened at 2011-02-23 12:34 Message generated for change (Comment added) made by achimwestermann You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Achim Westermann (achimwestermann) Assigned to: Nobody/Anonymous (nobody) Summary: Handling same named Headers with HtmlUnit Initial Comment: Intro: Great work thanks! Scenario: Server sends two same named cookies (e.g. servlet container adds JSESSIONID and Servlet filter has to correct that cookie, but cannot kill the first cookie from the response). The 2nd header cookie sets a special attribute, e.g. "HttpOnly" which the first one does not have. Problem: assertCookieValueMatch("JSESSIONID", "(.)*HttpOnly"); will take the first cookie with that name and fail. This is because HtmlUnitTestingEngineImpl in public String getHeader(String name) trusts on com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) which will return the first header. Also the workaround "getAllHeaders()" is a bit unclean. In HtmlUnitTestingEngineImpl#getAllHeaders() all values are put into a map by header name. The latter same named header fields will overwrite the earlier ones. Expected behaviour: For HtmlUnitTestingEngineImple#getHeader(String name) the last same named header should be returned. Take e.g. this specification (regarding Cookie setting) : http://tools.ietf.org/html/draft-ietf-httpstate-cookie-21#section-4.1.2 -> The last cookie wins. For HtmlUnitTestingEngineImpl#getAllHeaders() some data structure (multi - map?) should be returned that preserves all headers in that order. Thanks a lot for your great work! Achim P.S.: If you'd like a patch, just contact me. - HtmlUnitTestingEngineImpl ---------------------------------------------------------------------- >Comment By: Achim Westermann (achimwestermann) Date: 2011-03-11 14:47 Message: Hi Julian, it took me some time to set up eclipse with m2eclipse (dependency hell), but now I had the time to write a test and propose a bugfix. Caution there is an API change! I attach two patches. One for the new test to see what is not working as I expect it. And one proposed bugfix. I worked on assertCookieValueMatch to use the last cookie with the given name being checked. Forget about my statement about com.gargoylesoftware.htmlunit.Webresponse#getResponseHeaderValue(String name) in this matter. I found out that assertCookieValueMatch works on getTestingEngine().getCookies() which returns everything right! I worked on ITestingEngine.getAllHeaders() and the HTMLunit impl to avoid loosing same named cookies. I did that by changing the data structure returned to allow passing multiple same named cookies. I did this in favour of a commons collections MultiValueMap as the latter would have disallowed to use generic code (and forced us to use casts) . If the patch is not working I could attach the plain files. Eclipse -> checkout maven project via scm did have it's on idea on which projects to create in my workspace (even if everything works well). kind regards, Achim ---------------------------------------------------------------------- Comment By: Julien HENRY (henryju) Date: 2011-02-23 13:38 Message: Hi Achim, Thanks for your detailed report. Could you please provide a patch with the fix and possibly a JUnit test that verify this situation. Thanks Julien ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=497982&aid=3190055&group_id=61302 |