Skip to content

contents of $http_response_header is incorrect with long http message #9316

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

Closed
fasterforward opened this issue Aug 12, 2022 · 2 comments
Closed

Comments

@fasterforward
Copy link

Description

The following code:

echo file_get_contents('https://secret.blob.core.windows.net/container/documents/899/00000898942?si=secret&spr=https&sv=2021-06-08&sr=c&sig=secret');

print_r($http_response_header);

Resulted in this output:

Array
(
    [0] => HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly includ
    [1] => ing the signature.
    [2] => Content-Length: 544
    [3] => Content-Type: application/xml
    [4] => Server: Microsoft-HTTPAPI/2.0
    [5] => x-ms-request-id: 62435059-d01e-0017-2c51-aea046000000
    [6] => x-ms-error-code: AuthenticationFailed
    [7] => Date: Fri, 12 Aug 2022 13:45:53 GMT
    [8] => Connection: close
)

But I expected this output instead:

Array
(
    [0] => HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
    [1] => Content-Length: 544
    [2] => Content-Type: application/xml
    [3] => Server: Microsoft-HTTPAPI/2.0
    [4] => x-ms-request-id: 62435059-d01e-0017-2c51-aea046000000
    [5] => x-ms-error-code: AuthenticationFailed
    [6] => Date: Fri, 12 Aug 2022 13:45:53 GMT
    [7] => Connection: close
)

Here are the raw response headers according to network tab of FireFox:

HTTP/1.1 403 Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Content-Length: 544
Content-Type: application/xml
Server: Microsoft-HTTPAPI/2.0
x-ms-request-id: d9fdcb88-f01e-0022-4551-ae0e13000000
x-ms-error-code: AuthenticationFailed
Date: Fri, 12 Aug 2022 13:42:57 GMT

PHP Version

PHP 8.1

Operating System

No response

@damianwadley
Copy link
Member

Allowing more than 127 characters, like 255 is a nice round number, seems reasonable, but that status line is only supposed to have a short descriptive reason for the code. It is not the place for error messages. So tsk tsk, Microsoft.

@cmb69
Copy link
Member

cmb69 commented Aug 12, 2022

I have to agree that the reason-phrase is unnecessarily verbose, but to my knowledge there is no actual length restriction, so we should probably comply.

cmb69 added a commit to cmb69/php-src that referenced this issue Aug 12, 2022
While the reason-phrase in a HTTP response status line is usually
short, there is no actual limit specified by the RFCs.  As such, we
must not assume that the line fits into the buffer (which is currently
128 bytes large).

Since there is no real need to present the complete status line, we
simply read and discard the rest of a long line.
@cmb69 cmb69 self-assigned this Aug 16, 2022
cmb69 added a commit to cmb69/php-src that referenced this issue Aug 17, 2022
While the reason-phrase in a HTTP response status line is usually
short, there is no actual limit specified by the RFCs.  As such, we
must not assume that the line fits into the buffer (which is currently
128 bytes large).

Since there is no real need to present the complete status line, we
simply read and discard the rest of a long line.
cmb69 added a commit that referenced this issue Aug 18, 2022
* PHP-8.0:
  Fix GH-9316: $http_response_header is wrong for long status line
@cmb69 cmb69 closed this as completed in 72da418 Aug 18, 2022
cmb69 added a commit that referenced this issue Aug 18, 2022
* PHP-8.1:
  Fix GH-9316: $http_response_header is wrong for long status line
Girgias added a commit that referenced this issue Nov 22, 2023
http_build_query() default null argument for  is implicitly coerced to string

Closes GH-9316
Girgias added a commit that referenced this issue Nov 22, 2023
* PHP-8.3:
  ext/standard: Fix GH-9316
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@cmb69 @fasterforward @damianwadley and others