Skip to content

Commit b936fcc

Browse files
committed
fix: CURLRequest has multiple headers for Content-Type
1 parent e14e145 commit b936fcc

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

system/HTTP/CURLRequest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ public function __construct(App $config, URI $uri, ?ResponseInterface $response
116116

117117
parent::__construct(Method::GET, $uri);
118118

119-
$this->responseOrig = $response ?? new Response(config(App::class));
119+
$this->responseOrig = $response ?? new Response(config(App::class));
120+
// Remove the default Content-Type header.
121+
$this->responseOrig->removeHeader('Content-Type');
122+
120123
$this->baseURI = $uri->useRawQueryString();
121124
$this->defaultOptions = $options;
122125

tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,14 +784,14 @@ public function testSendContinuedWithManyHeaders(): void
784784

785785
$responseHeaderKeys = [
786786
'Cache-Control',
787-
'Content-Type',
788787
'Server',
789788
'Connection',
790789
'Keep-Alive',
791790
'Set-Cookie',
792791
'Date',
793792
'Expires',
794793
'Pragma',
794+
'Content-Type',
795795
'Transfer-Encoding',
796796
];
797797
$this->assertSame($responseHeaderKeys, array_keys($response->headers()));
@@ -823,10 +823,10 @@ public function testResponseHeadersWithMultipleRequests(): void
823823

824824
$responseHeaderKeys = [
825825
'Cache-Control',
826-
'Content-Type',
827826
'Server',
828827
'Expires',
829828
'Pragma',
829+
'Content-Type',
830830
'Transfer-Encoding',
831831
];
832832
$this->assertSame($responseHeaderKeys, array_keys($response->headers()));
@@ -846,8 +846,8 @@ public function testResponseHeadersWithMultipleRequests(): void
846846

847847
$responseHeaderKeys = [
848848
'Cache-Control',
849-
'Content-Type',
850849
'Expires',
850+
'Content-Type',
851851
'Transfer-Encoding',
852852
];
853853
$this->assertSame($responseHeaderKeys, array_keys($response->headers()));
@@ -1141,4 +1141,21 @@ public function testUserAgentOption(): void
11411141
$this->assertArrayHasKey(CURLOPT_USERAGENT, $options);
11421142
$this->assertSame($agent, $options[CURLOPT_USERAGENT]);
11431143
}
1144+
1145+
public function testGetHeaderLineContentType(): void
1146+
{
1147+
$output = 'HTTP/2 200
1148+
date: Thu, 11 Apr 2024 07:26:00 GMT
1149+
content-type: text/html; charset=UTF-8
1150+
cache-control: no-store, max-age=0, no-cache
1151+
server: cloudflare
1152+
content-encoding: br
1153+
alt-svc: h3=":443"; ma=86400' . "\x0d\x0a\x0d\x0aResponse Body";
1154+
1155+
$this->request->setOutput($output);
1156+
1157+
$response = $this->request->request('get', 'http://example.com');
1158+
1159+
$this->assertSame('text/html; charset=UTF-8', $response->getHeaderLine('Content-Type'));
1160+
}
11441161
}

tests/system/HTTP/CURLRequestTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -782,14 +782,14 @@ public function testSendContinuedWithManyHeaders(): void
782782

783783
$responseHeaderKeys = [
784784
'Cache-Control',
785-
'Content-Type',
786785
'Server',
787786
'Connection',
788787
'Keep-Alive',
789788
'Set-Cookie',
790789
'Date',
791790
'Expires',
792791
'Pragma',
792+
'Content-Type',
793793
'Transfer-Encoding',
794794
];
795795
$this->assertSame($responseHeaderKeys, array_keys($response->headers()));
@@ -836,10 +836,10 @@ public function testResponseHeadersWithMultipleRequests(): void
836836

837837
$responseHeaderKeys = [
838838
'Cache-Control',
839-
'Content-Type',
840839
'Server',
841840
'Expires',
842841
'Pragma',
842+
'Content-Type',
843843
'Transfer-Encoding',
844844
];
845845
$this->assertSame($responseHeaderKeys, array_keys($response->headers()));
@@ -859,8 +859,8 @@ public function testResponseHeadersWithMultipleRequests(): void
859859

860860
$responseHeaderKeys = [
861861
'Cache-Control',
862-
'Content-Type',
863862
'Expires',
863+
'Content-Type',
864864
'Transfer-Encoding',
865865
];
866866
$this->assertSame($responseHeaderKeys, array_keys($response->headers()));

0 commit comments

Comments
 (0)