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
std: add http definitions for Method and Status #10661
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch
on Status
is currently inconsistent
/// A cacheable response is an HTTP response that can be cached, that is stored to be retrieved and used later, saving a new request to the server. | ||
/// https://developer.mozilla.org/en-US/docs/Glossary/cacheable | ||
/// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.3 | ||
pub fn cacheable(self: Method) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a feeling this method could be very misleading (e.g. it might then depend on Vary
header)
I think it might make sense to collapse the /// An HTTP method is safe if it doesn't alter the state of the server.
/// https://developer.mozilla.org/en-US/docs/Glossary/Safe/HTTP
/// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.1
pub fn safe(self: Method) bool {
return switch (self) {
.GET, .HEAD, .OPTIONS, .TRACE => true,
.POST, .PUT, .DELETE, .CONNECT, .PATCH => false,
};
} |
pub fn responseHasBody(self: Method) bool { | ||
return switch (self) { | ||
.GET, .POST, .DELETE, .CONNECT, .OPTIONS, .PATCH => true, | ||
.HEAD, .PUT, .TRACE => false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why PUT
is in this list?
Infact most PUT
responses I've seen have a body on them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example of PUT returning a body.
I would still say the stdlib should follow the http standard, but it should not block the ability to get a response body from a PUT request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it wouldnt stop a client from receiving a PUT body, but it could raise a warning in the server implementation from sending a body
Was |
starts again the
std.http
namespace and add definitions for theMethod
andStatus
primitives for use in further work and 3rd party librariesadditionally will be used by 910, 2007, 943