From 17260672cd7c29355dfb80e04c1f9e72b9a006d5 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 21 Oct 2016 16:43:26 +1100 Subject: [PATCH 1/2] Add a testcase verifying that the `Content-Length` header is sent. --- tests/Transport/Base.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tests/Transport/Base.php b/tests/Transport/Base.php index 5ddce18c1..aa2278c8c 100644 --- a/tests/Transport/Base.php +++ b/tests/Transport/Base.php @@ -145,6 +145,15 @@ public function testRawPOST() { $this->assertEquals('test', $result['data']); } + public function testEmptyPOST() { + $request = Requests::post(httpbin('/post'), array(), null, $this->getOptions()); + $this->assertEquals(200, $request->status_code); + + $result = json_decode($request->body, true); + // Heroku appears to add this on incoming requests even if we don't send it + $this->assertArrayHasKey( 'content-length', $result['headers'] ); + } + public function testFormPost() { $data = 'test=true&test2=test'; $request = Requests::post(httpbin('/post'), array(), $data, $this->getOptions()); From 1dcf0e146f04b496ee08a68bdf95bbb5bfaa52f4 Mon Sep 17 00:00:00 2001 From: Dion Hulse Date: Fri, 21 Oct 2016 16:44:08 +1100 Subject: [PATCH 2/2] Always send the `Content-Length` and `Content-Type` headers for POST requests. --- library/Requests/Transport/fsockopen.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Requests/Transport/fsockopen.php b/library/Requests/Transport/fsockopen.php index 21cb56d5e..011c62852 100644 --- a/library/Requests/Transport/fsockopen.php +++ b/library/Requests/Transport/fsockopen.php @@ -160,7 +160,7 @@ public function request($url, $headers = array(), $data = array(), $options = ar $request_body = $data; } - if (!empty($data)) { + if (!empty($data) || $options['type'] === Requests::POST) { if (!isset($case_insensitive_headers['Content-Length'])) { $headers['Content-Length'] = strlen($request_body); }