-
Notifications
You must be signed in to change notification settings - Fork 18
Parsed form urlencoded requests. #19
Parsed form urlencoded requests. #19
Conversation
@@ -78,7 +78,7 @@ public function notApplicableProvider() | |||
['GET', 'application/json'], | |||
['HEAD', 'application/json'], | |||
['OPTIONS', 'application/json'], | |||
['POST', 'application/x-www-form-urlencoded'], | |||
['GET', 'application/x-www-form-urlencoded'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this test case Changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this makes POST of application/x-www-form-urlencoded
an applicable type, thus the test would break if I didn't change it.
They don't need to be parsed in most cases. Diactoros uses the value of |
Are you saying Also, if they are doing that, it seems very wrong as |
No, I'm saying |
I was not experiencing what you are saying. It wasn't until I made these changes that I got the values of $_POST. I used |
I'd argue that if we do this, the following should occur: $parsed = $request->getParsedBody();
if (! empty($parsed)) {
return $request;
}
$raw = $request->getBody()->getContents();
if (empty($raw)) {
return $request;
}
parse_str($raw, $parsed);
return $request->withBodyParams($parsed); This would ensure that parsing only happens (a) if the parsed body is empty AND (b) if we have raw body contents. This would require:
UPDATED to separate the |
I've used this myself on several sites, and have it working exactly as I described. The only thing I can think of is that it may be a difference in web server or how you're creating the ServerRequest instance, as the Anyways, with the changes I suggest above, we would eliminate unnecessary double-parsing, while providing a way to parse if it's not populated. |
Ok, I'll work on the changes based on what you said. And your explanation is definitely the reason. It's actually a functional test client I created for an application where I'm having the issue. We build up the request and pass it to the application to run it as it makes it much quicker and easier than going against a real server. With these changes, at least we'll be guaranteed that this middleware will work regardless of how the request was built, which I think is the right way to do it. I'll get to work on these changes sometime this week then as I have to switch focus to another project for a bit. Thanks! |
@nesl247 I've flagged this for 2.1.0 in hopes that I can wrap up the remainder of pending issues and PRs in that release. Please let me know if you need some help with this, or if you think you'll be able to make the discussed changes yourself before long. |
This parses urlencoded requests when a request is not built from `ServerRequestFactory::fromGlobals()`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Will be released with 2.1.0
.
I'm not sure why urlencoded requests weren't being parsed.