Skip to content

Make use of new HtmlUnit API for access request parameters #28240

@rbri

Description

@rbri

Hi, i'm the maintainer of HtmlUnit and i like to finally fix the issues #25768 and HtmlUnit/htmlunit#223.

Did some analysis during the last day's - sorry for the long text here but i like to make my view on this clear and hopefully we can discuss and find a good solution.
Did my analysis based on the sample here - https://github.com/thuri/htmlunit-test-project/tree/JQueryAjax

Lets start with the WebRequest class from HtmlUnit:

  • this is more or less an internal class
  • the api of that class is really bad designed
    ** parameter and body are exclusive - you can only have one
    ** the usage of the class requires some internal knowledge of how the request got filled
    ** many more

Now the problem - from my point of view:
org.springframework.test.web.servlet.htmlunit.HtmlUnitRequestBuilder.params(MockHttpServletRequest, UriComponents) only takes parts of the (internal) logic of WebRequest into account; at the moment only the url and the parameters are checked when reading the parameters. There are more cases where the parameters are url-encoded in the body - these cases are the reason for the misbehavior.

Possible solutions
Option 1:
To fix the problem we can improve the HtmlUnitRequestBuilder.params implementation to reflect the whole functionality used by HtmlUnit
But i think this is not really maintainable - every time HtmlUnit changes parts of the internal magic here you have to fix something.

Option 2 (my preferred one):
We agree on a more stable interface for WebRequest that hides the internal parameter handling and always returns all the parameter (key value pairs) like e.g. the servlet api does. HtmlUnitRequestBuilder can use this method and gets always all params.

I have already prototyped this solution (breaking HtmlUnits backwardcomatibility) by changing the com.gargoylesoftware.htmlunit.WebRequest.getRequestParameters() method in the way described above (the impl is available as 2.61.0-SNAPSHOT).
This fixes the problems but introduces a new one because the url paramters are doubled now (because HtmlUnitRequestBuilder.params(MockHttpServletRequest, UriComponents) handles this params already).

Because of this i like to get some feedback from you how we should proceed here.

Or to summarize

  • i like to change HtmlUnit WebRequest to provide an API that returns always all request parameters (at best without breaking backward compatibility)
  • you change the impl of HtmlUnitRequestBuilder.params() to use only this method

Many thanks
Ronald
(rbri at rbri.de)

Metadata

Metadata

Assignees

Labels

in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions