-
-
Notifications
You must be signed in to change notification settings - Fork 167
Interpret content-type header for 'application/x-www-form-urlencoded' correctly #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -143,7 +143,10 @@ public function testShouldReceiveMultiPartBody() | |
$this->assertEquals(2, count($request->getFiles()['files'])); | ||
} | ||
|
||
public function testShouldReceivePostInBody() | ||
/** | ||
* @dataProvider shouldReceivePostInBodyDataProvider | ||
*/ | ||
public function testShouldReceivePostInBody($postData) | ||
{ | ||
$request = null; | ||
$body = null; | ||
|
@@ -154,7 +157,7 @@ public function testShouldReceivePostInBody() | |
$body = $parsedBodyBuffer; | ||
}); | ||
|
||
$parser->feed($this->createPostWithContent()); | ||
$parser->feed($postData); | ||
|
||
$this->assertInstanceOf('React\Http\Request', $request); | ||
$this->assertSame('', $body); | ||
|
@@ -164,6 +167,14 @@ public function testShouldReceivePostInBody() | |
); | ||
} | ||
|
||
public function shouldReceivePostInBodyDataProvider() | ||
{ | ||
return [ | ||
[$this->createPostWithContent()], | ||
[$this->createPostWithContentUtf8Charset()] | ||
]; | ||
} | ||
|
||
public function testHeaderOverflowShouldEmitError() | ||
{ | ||
$error = null; | ||
|
@@ -260,6 +271,20 @@ private function createPostWithContent() | |
return $data; | ||
} | ||
|
||
private function createPostWithContentUtf8Charset() | ||
{ | ||
$data = "POST /foo?bar=baz HTTP/1.1\r\n"; | ||
$data .= "Host: localhost:8080\r\n"; | ||
$data .= "User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:32.0) Gecko/20100101 Firefox/32.0\r\n"; | ||
$data .= "Connection: close\r\n"; | ||
$data .= "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind creating a separate test for this instead of adjusting an existing one so we can test this specific use case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. I'll have that commit shortly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Splendid! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @WyriHaximus Working on this now (sorry for the delay); however, since we are effectively testing the same exact thing as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @caseyamcl No worries we all have a life outside github; Yes that has my preference. That was we can easily include more test cases by simple adding more entries in the data provider 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Life outside of Github? Nevaheardofit. Anyhow, I added a commit tonight. Let me know if you need any more changes. |
||
$data .= "Content-Length: 79\r\n"; | ||
$data .= "\r\n"; | ||
$data .= "user=single&user2=second&users%5B%5D=first+in+array&users%5B%5D=second+in+array\r\n"; | ||
|
||
return $data; | ||
} | ||
|
||
private function createMultipartRequest() | ||
{ | ||
$data = "POST / HTTP/1.1\r\n"; | ||
|
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 did you choose to go for
=== 0
over!== false
? My preference would be the latter, that leaves room for an client messing up and adding a space in front of it. (Just nitpicking a bit here.)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.
Either way is fine, and I can change it if you want.
I can't find anywhere in the the official documents that specifies that the header name must appear as the first character on a line, although I've never seen white space before a header in practice.
Perhaps this may be the least ambiguous:
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.
Fair enough, leave it as is. Was mostly nitpicking because I've seen clients (and servers) pull really odd stunts so trying to be a bit more defensive and prepared for such occasions.