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

Share HTTP status codes map between SAPIs #892

Merged
merged 1 commit into from
Dec 14, 2014

Conversation

hikari-no-yume
Copy link
Contributor

There's some other stuff (header parsing etc.) which also ought to be shared, but this is, at least, a start.

This also means other code in PHP can benefit from this info.

@hikari-no-yume hikari-no-yume changed the title Share HTTP status codes map Share HTTP status codes map between SAPIs Nov 6, 2014
{ 502, "Bad Gateway" },
{ 503, "Service Unavailable" },
{ 504, "Gateway Timeout" },
{ 505, "HTTP Version Not Supported" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

506, 507, 508 and 510 could be added as well. What would be nice is to offer a userland function to expose a map of HTTP status codes as well.

P.S.: nice refactoring!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for a getter for userland

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👎 Those are not part of RFC, I think only those specified in RFC 7231 should be explicitly set.
👍 for some sort of getter.

@Majkl578
Copy link
Contributor

Majkl578 commented Nov 6, 2014

Any reason why these code messages do not match RFC 7231 (https://tools.ietf.org/html/rfc7231#section-6.1)?

{ 426, "Upgrade Required" },
{ 428, "Precondition Required" },
{ 429, "Too Many Requests" },
{ 431, "Request Header Fields Too Large" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These three above are not specified in RFC 7231.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are in RFC 6585, however.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is an extension of obsoslete 2616, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't obsolete 6585.

@Hywan
Copy link
Contributor

Hywan commented Nov 7, 2014

You will find an exhaustive list here: Hypertext Transfer Protocol (HTTP) Status Code Registry (IANA). Just copy/paste ;-).

@hikari-no-yume
Copy link
Contributor Author

@Hywan That's handy, thanks. Though I don't think any of the ones in that which we don't have are worth adding, unless they're actually used much.

@Hywan
Copy link
Contributor

Hywan commented Nov 8, 2014

@TazeTSchnitzel Used or not, if you would like to be exhaustive, you have to follow this list :-). Especially if you expose this API to the userland.

@jpauli
Copy link
Member

jpauli commented Nov 29, 2014

I suggest not adding strings to our binary if we dont use them.
Less strings, less process memory consumed

@@ -449,8 +401,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
}
err++;
}
if (err->msg) {
len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg);
if (err->str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TazeTSchnitzel This condition can be omitted, because current shared map no longer contains code-text pair {0, NULL} as did previous map. According to this case, the else-block will never get run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh god, how does it know it reached the end, then? I need to add {0, NULL} back D:

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. But the header should not really depend on other layer implementation, should it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess so, but terminating with {0, NULL} isn't really a bad idea.

@hikari-no-yume
Copy link
Contributor Author

@jpauli It's a header, no strings are added unless it's used somewhere.

@@ -457,8 +408,8 @@ static int sapi_cgi_send_headers(sapi_headers_struct *sapi_headers TSRMLS_DC)
}
err++;
}
if (err->msg) {
len = slprintf(buf, sizeof(buf), "Status: %d %s\r\n", SG(sapi_headers).http_response_code, err->msg);
if (err->str) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is also able to be omitted (reason).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh god, I'm surprised this isn't segfaulting, oh god...

@hikari-no-yume
Copy link
Contributor Author

Well, it's been a while with no real complaints, so I'll merge this.

@php-pulls php-pulls merged commit 65768ed into php:master Dec 14, 2014
@hikari-no-yume
Copy link
Contributor Author

I screwed up when I merged it and I reverted it, new pull request here: #957

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants