@@ -86,7 +86,7 @@ public function appendBody($data): self
8686 */
8787 public function populateHeaders (): void
8888 {
89- $ contentType = service ('superglobals ' )->server ('CONTENT_TYPE ' , ( string ) getenv ( ' CONTENT_TYPE ' ) );
89+ $ contentType = service ('superglobals ' )->server ('CONTENT_TYPE ' );
9090 if (! empty ($ contentType )) {
9191 $ this ->setHeader ('Content-Type ' , $ contentType );
9292 }
@@ -283,18 +283,25 @@ protected function getHeaderName(string $name): string
283283 */
284284 public function setProtocolVersion (string $ version ): self
285285 {
286- if (! is_numeric ($ version )) {
286+ // If empty or null, keep default protocol version (usually 1.1) and do nothing.
287+ if ($ version === '' || $ version === null ) {
288+ return $ this ;
289+ }
290+
291+ // If a full protocol string (e.g., "HTTP/1.1") is provided, extract the numeric part.
292+ if (strpos ($ version , '/ ' ) !== false ) {
287293 $ version = substr ($ version , strpos ($ version , '/ ' ) + 1 );
288294 }
289295
290- // Make sure that version is in the correct format
291- $ version = number_format ((float ) $ version , 1 );
296+ // Normalize to a single decimal place as used in validProtocolVersions.
297+ $ normalized = number_format ((float ) $ version , 1 );
292298
293- if (! in_array ($ version , $ this ->validProtocolVersions , true )) {
299+ // Throw exception if the version is not recognized.
300+ if (! in_array ($ normalized , $ this ->validProtocolVersions , true )) {
294301 throw HTTPException ::forInvalidHTTPProtocol ($ version );
295302 }
296303
297- $ this ->protocolVersion = $ version ;
304+ $ this ->protocolVersion = $ normalized ;
298305
299306 return $ this ;
300307 }
0 commit comments