@@ -81,7 +81,7 @@ public function appendBody($data): self
8181 */
8282 public function populateHeaders (): void
8383 {
84- $ contentType = service ('superglobals ' )->server ('CONTENT_TYPE ' , ( string ) getenv ( ' CONTENT_TYPE ' ) );
84+ $ contentType = service ('superglobals ' )->server ('CONTENT_TYPE ' );
8585 if (! empty ($ contentType )) {
8686 $ this ->setHeader ('Content-Type ' , $ contentType );
8787 }
@@ -266,18 +266,25 @@ protected function getHeaderName(string $name): string
266266 */
267267 public function setProtocolVersion (string $ version ): self
268268 {
269- if (! is_numeric ($ version )) {
269+ // If empty or null, keep default protocol version (usually 1.1) and do nothing.
270+ if ($ version === '' || $ version === null ) {
271+ return $ this ;
272+ }
273+
274+ // If a full protocol string (e.g., "HTTP/1.1") is provided, extract the numeric part.
275+ if (strpos ($ version , '/ ' ) !== false ) {
270276 $ version = substr ($ version , strpos ($ version , '/ ' ) + 1 );
271277 }
272278
273- // Make sure that version is in the correct format
274- $ version = number_format ((float ) $ version , 1 );
279+ // Normalize to a single decimal place as used in validProtocolVersions.
280+ $ normalized = number_format ((float ) $ version , 1 );
275281
276- if (! in_array ($ version , $ this ->validProtocolVersions , true )) {
282+ // Throw exception if the version is not recognized.
283+ if (! in_array ($ normalized , $ this ->validProtocolVersions , true )) {
277284 throw HTTPException ::forInvalidHTTPProtocol ($ version );
278285 }
279286
280- $ this ->protocolVersion = $ version ;
287+ $ this ->protocolVersion = $ normalized ;
281288
282289 return $ this ;
283290 }
0 commit comments