Skip to content
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

Respect response's status code #111

Merged
merged 1 commit into from Oct 12, 2017

Conversation

ryo88c
Copy link
Contributor

@ryo88c ryo88c commented Oct 6, 2017

Passing WWW-Authenticate to header() overwrites the status code to 401.

https://github.com/php/php-src/blob/a51cb393b1accc29200e8f57ef867a6a47b2564f/main/SAPI.c#L829

According to RFC it is said that it is also possible to include WWW-Authenticate in status codes other than 401.

https://tools.ietf.org/html/rfc7235#page-7

A server MAY generate a WWW-Authenticate header field in other response.

Since OAuth 2.0 Bearer writes its contents in WWW-Authenticate header even for errors other than 401, the original status code is applied after the status code reaches 401 by inserting the WWW-Authenticate header field is necessary.

https://tools.ietf.org/html/rfc6750#page-9


401 以外のステータスコードでも WWW-Authenticate ヘッダを挿入できるように。

header()WWW-Authenticate を渡すとステータスコードが 401 に上書きされます。

https://github.com/php/php-src/blob/a51cb393b1accc29200e8f57ef867a6a47b2564f/main/SAPI.c#L829

RFC によれば 401 以外のステータスコードでも WWW-Authenticate を含めてもよいとされています。

https://tools.ietf.org/html/rfc7235#page-7

A server MAY generate a WWW-Authenticate header field in other response.

OAuth 2.0 Bearer では 401 以外のエラーでもその内容を WWW-Authenticate ヘッダ記述するため、WWW-Authenticate ヘッダを挿入したことによってステータスコードが 401 になった後、本来のステータスコードが適用される必要があります。

https://tools.ietf.org/html/rfc6750#page-9

Passing `WWW-Authenticate` to `header()` overwrites the status code to 401.

https://github.com/php/php-src/blob/a51cb393b1accc29200e8f57ef867a6a47b2564f/ain/SAPI.c#L829

According to RFC it is said that it is also possible to include `WWW-Authenticate` in status codes other than 401.

https://tools.ietf.org/html/rfc7235#page-7

> A server MAY generate a WWW-Authenticate header field in other response.

Since OAuth 2.0 Bearer writes its contents in `WWW-Authenticate` header even for errors other than 401, the original status code is applied after the status code reaches 401 by inserting the `WWW-Authenticate` header field is necessary.

https://tools.ietf.org/html/rfc6750#page-9
@koriym
Copy link
Member

koriym commented Oct 12, 2017

これはPHP内部の動作とも関係してテストコードの記述は難しいですよね?

@ryo88c
Copy link
Contributor Author

ryo88c commented Oct 12, 2017

そうですね。検証性のあるテストを書くのは難しいと思います。

@koriym
Copy link
Member

koriym commented Oct 12, 2017

これはhttp_response_codeでコードを先に出力してもWWW-Authenticateが失敗した時も401ではなく指定したHTTPコードを出力したいというものですよね?

@ryo88c
Copy link
Contributor Author

ryo88c commented Oct 12, 2017

はい、そうです。OAuth 2.0 Bearer の仕様に基づき、レスポンスヘッダに WWW-Authenticate が含まれているときに 401 以外のステータスコードも返したいです。

@koriym
Copy link
Member

koriym commented Oct 12, 2017

他のも調べて見他ところ、タイムリーに同じようなディスカッションが..
zendframework/zend-diactoros#273

@koriym
Copy link
Member

koriym commented Oct 12, 2017

@ryo88c さんのPRと同じようにstatus codeの出力を他のheaderの後にしていますね

@koriym koriym merged commit c702ce7 into bearsunday:1.x Oct 12, 2017
@koriym
Copy link
Member

koriym commented Oct 15, 2017

他からも参照したいので、タイトルをオリジナルの「Allow the WWW-Authenticate header field in other response than 401.」からより実態に即した「Respect response's status code」(zend-diactorosでのissueと同じ)に変更します。

@koriym koriym changed the title Allow the WWW-Authenticate header field in other response than 401. Respect response's status code Oct 15, 2017
koriym added a commit to bearsunday/BEAR.Streamer that referenced this pull request Oct 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants