2025-06-27 20:05:22 -07:00
|
|
|
const builtin = @import("builtin");
|
|
|
|
|
const std = @import("std.zig");
|
|
|
|
|
const assert = std.debug.assert;
|
|
|
|
|
|
2022-12-12 21:18:56 -07:00
|
|
|
pub const Client = @import("http/Client.zig");
|
2023-03-13 12:46:58 -05:00
|
|
|
pub const Server = @import("http/Server.zig");
|
|
|
|
|
pub const protocol = @import("http/protocol.zig");
|
std.http.Server: rework the API entirely
Mainly, this removes the poorly named `wait`, `send`, `finish`
functions, which all operated on the same "Response" object, which was
actually being used as the request.
Now, it looks like this:
1. std.net.Server.accept() gives you a std.net.Server.Connection
2. std.http.Server.init() with the connection
3. Server.receiveHead() gives you a Request
4. Request.reader() gives you a body reader
5. Request.respond() is a one-shot, or Request.respondStreaming() creates
a Response
6. Response.writer() gives you a body writer
7. Response.end() finishes the response; Response.endChunked() allows
passing response trailers.
In other words, the type system now guides the API user down the correct
path.
receiveHead allows extra bytes to be read into the read buffer, and then
will reuse those bytes for the body or the next request upon connection
reuse.
respond(), the one-shot function, will send the entire response in one
syscall.
Streaming response bodies no longer wastefully wraps every call to write
with a chunk header and trailer; instead it only sends the HTTP chunk
wrapper when flushing. This means the user can still control when it
happens but it also does not add unnecessary chunks.
Empirically, in my example project that uses this API, the usage code is
significantly less noisy, it has less error handling while handling
errors more correctly, it's more obvious what is happening, and it is
syscall-optimal.
Additionally:
* Uncouple std.http.HeadParser from protocol.zig
* Delete std.Server.Connection; use std.net.Server.Connection instead.
- The API user supplies the read buffer when initializing the
http.Server, and it is used for the HTTP head as well as a buffer
for reading the body into.
* Replace and document the State enum. No longer is there both "start"
and "first".
2024-02-20 03:30:51 -07:00
|
|
|
pub const HeadParser = @import("http/HeadParser.zig");
|
2024-02-21 00:16:03 -07:00
|
|
|
pub const ChunkParser = @import("http/ChunkParser.zig");
|
2024-02-23 02:58:02 -07:00
|
|
|
pub const HeaderIterator = @import("http/HeaderIterator.zig");
|
2024-08-04 15:25:42 -07:00
|
|
|
pub const WebSocket = @import("http/WebSocket.zig");
|
2023-01-03 19:14:44 -07:00
|
|
|
|
|
|
|
|
pub const Version = enum {
|
|
|
|
|
@"HTTP/1.0",
|
|
|
|
|
@"HTTP/1.1",
|
|
|
|
|
};
|
2022-12-12 21:18:56 -07:00
|
|
|
|
|
|
|
|
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2023-04-30 18:02:08 +01:00
|
|
|
/// https://datatracker.ietf.org/doc/html/rfc7231#section-4 Initial definition
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2022-12-12 21:18:56 -07:00
|
|
|
/// https://datatracker.ietf.org/doc/html/rfc5789#section-2 PATCH
|
std.http: remove Headers API
I originally removed these in 402f967ed5339fa3d828b7fe1d57cdb5bf38dbf2.
I allowed them to be added back in #15299 because they were smuggled in
alongside a bug fix, however, I wasn't kidding when I said that I wanted
to take the design of std.http in a different direction than using this
data structure.
Instead, some headers are provided via explicit field names populated
while parsing the HTTP request/response, and some are provided via
new fields that support passing extra, arbitrary headers.
This resulted in simplification of logic in many places, as well as
elimination of the possibility of failure in many places. There is
less deinitialization code happening now.
Furthermore, it made it no longer necessary to clone the headers data
structure in order to handle redirects.
http_proxy and https_proxy fields are now pointers since it is common
for them to be unpopulated.
loadDefaultProxies is changed into initDefaultProxies to communicate
that it does not actually load anything from disk or from the network.
The function now is leaky; the API user must pass an already
instantiated arena allocator. Removes the need to deinitialize proxies.
Before, proxies stored arbitrary sets of headers. Now they only store
the authorization value.
Removed the duplicated code between https_proxy and http_proxy. Finally,
parsing failures of the environment variables result in errors being
emitted rather than silently ignoring the proxy.
error.CompressionNotSupported is renamed to
error.CompressionUnsupported, matching the naming convention from all
the other errors in the same set.
Removed documentation comments that were redundant with field and type
names.
Disabling zstd decompression in the server for now; see #18937.
I found some apparently dead code in src/Package/Fetch/git.zig. I want
to check with Ian about this.
I discovered that test/standalone/http.zig is dead code, it is only
being compiled but not being run. Furthermore it hangs at the end if you
run it manually. The previous commits in this branch were written under
the assumption that this test was being run with
`zig build test-standalone`.
2024-02-12 23:03:06 -07:00
|
|
|
pub const Method = enum(u64) {
|
2023-08-27 16:36:24 -05:00
|
|
|
GET = parse("GET"),
|
|
|
|
|
HEAD = parse("HEAD"),
|
|
|
|
|
POST = parse("POST"),
|
|
|
|
|
PUT = parse("PUT"),
|
|
|
|
|
DELETE = parse("DELETE"),
|
|
|
|
|
CONNECT = parse("CONNECT"),
|
|
|
|
|
OPTIONS = parse("OPTIONS"),
|
|
|
|
|
TRACE = parse("TRACE"),
|
|
|
|
|
PATCH = parse("PATCH"),
|
|
|
|
|
|
|
|
|
|
_,
|
|
|
|
|
|
|
|
|
|
/// Converts `s` into a type that may be used as a `Method` field.
|
|
|
|
|
/// Asserts that `s` is 24 or fewer bytes.
|
|
|
|
|
pub fn parse(s: []const u8) u64 {
|
|
|
|
|
var x: u64 = 0;
|
2023-10-17 19:08:22 -05:00
|
|
|
const len = @min(s.len, @sizeOf(@TypeOf(x)));
|
|
|
|
|
@memcpy(std.mem.asBytes(&x)[0..len], s[0..len]);
|
2023-08-27 16:36:24 -05:00
|
|
|
return x;
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-05 10:43:14 -07:00
|
|
|
pub fn format(self: Method, w: *std.io.Writer) std.io.Writer.Error!void {
|
2025-06-27 20:05:22 -07:00
|
|
|
const bytes: []const u8 = @ptrCast(&@intFromEnum(self));
|
2023-08-27 16:36:24 -05:00
|
|
|
const str = std.mem.sliceTo(bytes, 0);
|
|
|
|
|
try w.writeAll(str);
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-12 21:18:56 -07:00
|
|
|
/// Returns true if a request of this method is allowed to have a body
|
|
|
|
|
/// Actual behavior from servers may vary and should still be checked
|
|
|
|
|
pub fn requestHasBody(self: Method) bool {
|
|
|
|
|
return switch (self) {
|
|
|
|
|
.POST, .PUT, .PATCH => true,
|
|
|
|
|
.GET, .HEAD, .DELETE, .CONNECT, .OPTIONS, .TRACE => false,
|
2023-08-27 16:36:24 -05:00
|
|
|
else => true,
|
2022-12-12 21:18:56 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Returns true if a response to this method is allowed to have a body
|
|
|
|
|
/// Actual behavior from clients may vary and should still be checked
|
|
|
|
|
pub fn responseHasBody(self: Method) bool {
|
|
|
|
|
return switch (self) {
|
|
|
|
|
.GET, .POST, .DELETE, .CONNECT, .OPTIONS, .PATCH => true,
|
|
|
|
|
.HEAD, .PUT, .TRACE => false,
|
2023-08-27 16:36:24 -05:00
|
|
|
else => true,
|
2022-12-12 21:18:56 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// An HTTP method is safe if it doesn't alter the state of the server.
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2022-12-12 21:18:56 -07:00
|
|
|
/// https://developer.mozilla.org/en-US/docs/Glossary/Safe/HTTP
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2022-12-12 21:18:56 -07:00
|
|
|
/// 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,
|
2023-08-27 16:36:24 -05:00
|
|
|
else => false,
|
2022-12-12 21:18:56 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-27 20:05:22 -07:00
|
|
|
/// An HTTP method is idempotent if an identical request can be made once
|
|
|
|
|
/// or several times in a row with the same effect while leaving the server
|
|
|
|
|
/// in the same state.
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2022-12-12 21:18:56 -07:00
|
|
|
/// https://developer.mozilla.org/en-US/docs/Glossary/Idempotent
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2022-12-12 21:18:56 -07:00
|
|
|
/// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2
|
|
|
|
|
pub fn idempotent(self: Method) bool {
|
|
|
|
|
return switch (self) {
|
|
|
|
|
.GET, .HEAD, .PUT, .DELETE, .OPTIONS, .TRACE => true,
|
|
|
|
|
.CONNECT, .POST, .PATCH => false,
|
2023-08-27 16:36:24 -05:00
|
|
|
else => false,
|
2022-12-12 21:18:56 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-27 20:05:22 -07:00
|
|
|
/// A cacheable response can be stored to be retrieved and used later,
|
|
|
|
|
/// saving a new request to the server.
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2022-12-12 21:18:56 -07:00
|
|
|
/// https://developer.mozilla.org/en-US/docs/Glossary/cacheable
|
Fix simple doc mistakes. (#17624)
* Add missing period in Stack's description
This looks fine in the source, but looks bad when seen on the documentation website.
* Correct documentation for attachSegfaultHandler()
The description for attachSegfaultHandler() looks pretty bad without indicating that the stuff at the end is code
* Added missing 'the's in Queue.put's documentation
* Fixed several errors in Stack's documentation
`push()` and `pop()` were not styled as code
There was no period after `pop()`, which looks bad on the documentation.
* Fix multiple problems in base64.zig
Both "invalid"s in Base64.decoder were not capitalized.
Missing period in documentation of Base64DecoderWithIgnore.calcSizeUpperBound.
* Fix capitalization typos in bit_set.zig
In DynamicBitSetUnmanaged.deinit's and DynamicBitSet.deinit's documentation, "deinitializes" was uncapitalized.
* Fix typos in fifo.zig's documentation
Added a previously missing period to the end of the first line of LinearFifo.writableSlice's documentation.
Added missing periods to both lines of LinearFifo.pump's documentation.
* Fix typos in fmt.bufPrint's documentation
The starts of both lines were not capitalized.
* Fix minor documentation problems in fs/file.zig
Missing periods in documentation for Permissions.setReadOnly, PermissionsWindows.setReadOnly, MetadataUnix.created, MetadataLinux.created, and MetadataWindows.created.
* Fix a glaring typo in enums.zig
* Correct errors in fs.zig
* Fixed documentation problems in hash_map.zig
The added empty line in verify_context's documentation is needed, otherwise autodoc for some reason assumes that the list hasn't been terminated and continues reading off the rest of the documentation as if it were part of the second list item.
* Added lines between consecutive URLs in http.zig
Makes the documentation conform closer to what was intended.
* Fix wrongfully ended sentence in Uri.zig
* Handle wrongly entered comma in valgrind.zig.
* Add missing periods in wasm.zig's documentation
* Fix odd spacing in event/loop.zig
* Add missing period in http/Headers.zig
* Added missing period in io/limited_reader.zig
This isn't in the documentation due to what I guess is a limitation of autodoc, but it's clearly supposed to be. If it was, it would look pretty bad.
* Correct documentation in math/big/int.zig
* Correct formatting in math/big/rational.zig
* Create an actual link to ZIGNOR's paper.
* Fixed grammatical issues in sort/block.zig
This will not show up in the documentation currently.
* Fix typo in hash_map.zig
2023-10-21 17:24:55 -04:00
|
|
|
///
|
2022-12-12 21:18:56 -07:00
|
|
|
/// https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.3
|
|
|
|
|
pub fn cacheable(self: Method) bool {
|
|
|
|
|
return switch (self) {
|
|
|
|
|
.GET, .HEAD => true,
|
|
|
|
|
.POST, .PUT, .DELETE, .CONNECT, .OPTIONS, .TRACE, .PATCH => false,
|
2023-08-27 16:36:24 -05:00
|
|
|
else => false,
|
2022-12-12 21:18:56 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
|
|
|
|
|
pub const Status = enum(u10) {
|
|
|
|
|
@"continue" = 100, // RFC7231, Section 6.2.1
|
|
|
|
|
switching_protocols = 101, // RFC7231, Section 6.2.2
|
|
|
|
|
processing = 102, // RFC2518
|
|
|
|
|
early_hints = 103, // RFC8297
|
|
|
|
|
|
|
|
|
|
ok = 200, // RFC7231, Section 6.3.1
|
|
|
|
|
created = 201, // RFC7231, Section 6.3.2
|
|
|
|
|
accepted = 202, // RFC7231, Section 6.3.3
|
|
|
|
|
non_authoritative_info = 203, // RFC7231, Section 6.3.4
|
|
|
|
|
no_content = 204, // RFC7231, Section 6.3.5
|
|
|
|
|
reset_content = 205, // RFC7231, Section 6.3.6
|
|
|
|
|
partial_content = 206, // RFC7233, Section 4.1
|
|
|
|
|
multi_status = 207, // RFC4918
|
|
|
|
|
already_reported = 208, // RFC5842
|
|
|
|
|
im_used = 226, // RFC3229
|
|
|
|
|
|
|
|
|
|
multiple_choice = 300, // RFC7231, Section 6.4.1
|
|
|
|
|
moved_permanently = 301, // RFC7231, Section 6.4.2
|
|
|
|
|
found = 302, // RFC7231, Section 6.4.3
|
|
|
|
|
see_other = 303, // RFC7231, Section 6.4.4
|
|
|
|
|
not_modified = 304, // RFC7232, Section 4.1
|
|
|
|
|
use_proxy = 305, // RFC7231, Section 6.4.5
|
|
|
|
|
temporary_redirect = 307, // RFC7231, Section 6.4.7
|
|
|
|
|
permanent_redirect = 308, // RFC7538
|
|
|
|
|
|
|
|
|
|
bad_request = 400, // RFC7231, Section 6.5.1
|
|
|
|
|
unauthorized = 401, // RFC7235, Section 3.1
|
|
|
|
|
payment_required = 402, // RFC7231, Section 6.5.2
|
|
|
|
|
forbidden = 403, // RFC7231, Section 6.5.3
|
|
|
|
|
not_found = 404, // RFC7231, Section 6.5.4
|
|
|
|
|
method_not_allowed = 405, // RFC7231, Section 6.5.5
|
|
|
|
|
not_acceptable = 406, // RFC7231, Section 6.5.6
|
|
|
|
|
proxy_auth_required = 407, // RFC7235, Section 3.2
|
|
|
|
|
request_timeout = 408, // RFC7231, Section 6.5.7
|
|
|
|
|
conflict = 409, // RFC7231, Section 6.5.8
|
|
|
|
|
gone = 410, // RFC7231, Section 6.5.9
|
|
|
|
|
length_required = 411, // RFC7231, Section 6.5.10
|
|
|
|
|
precondition_failed = 412, // RFC7232, Section 4.2][RFC8144, Section 3.2
|
|
|
|
|
payload_too_large = 413, // RFC7231, Section 6.5.11
|
|
|
|
|
uri_too_long = 414, // RFC7231, Section 6.5.12
|
|
|
|
|
unsupported_media_type = 415, // RFC7231, Section 6.5.13][RFC7694, Section 3
|
|
|
|
|
range_not_satisfiable = 416, // RFC7233, Section 4.4
|
|
|
|
|
expectation_failed = 417, // RFC7231, Section 6.5.14
|
|
|
|
|
teapot = 418, // RFC 7168, 2.3.3
|
|
|
|
|
misdirected_request = 421, // RFC7540, Section 9.1.2
|
|
|
|
|
unprocessable_entity = 422, // RFC4918
|
|
|
|
|
locked = 423, // RFC4918
|
|
|
|
|
failed_dependency = 424, // RFC4918
|
|
|
|
|
too_early = 425, // RFC8470
|
|
|
|
|
upgrade_required = 426, // RFC7231, Section 6.5.15
|
|
|
|
|
precondition_required = 428, // RFC6585
|
|
|
|
|
too_many_requests = 429, // RFC6585
|
2023-04-26 11:02:55 -07:00
|
|
|
request_header_fields_too_large = 431, // RFC6585
|
2022-12-12 21:18:56 -07:00
|
|
|
unavailable_for_legal_reasons = 451, // RFC7725
|
|
|
|
|
|
|
|
|
|
internal_server_error = 500, // RFC7231, Section 6.6.1
|
|
|
|
|
not_implemented = 501, // RFC7231, Section 6.6.2
|
|
|
|
|
bad_gateway = 502, // RFC7231, Section 6.6.3
|
|
|
|
|
service_unavailable = 503, // RFC7231, Section 6.6.4
|
|
|
|
|
gateway_timeout = 504, // RFC7231, Section 6.6.5
|
|
|
|
|
http_version_not_supported = 505, // RFC7231, Section 6.6.6
|
|
|
|
|
variant_also_negotiates = 506, // RFC2295
|
|
|
|
|
insufficient_storage = 507, // RFC4918
|
|
|
|
|
loop_detected = 508, // RFC5842
|
|
|
|
|
not_extended = 510, // RFC2774
|
|
|
|
|
network_authentication_required = 511, // RFC6585
|
2022-05-11 12:43:18 -07:00
|
|
|
|
2022-12-12 21:18:56 -07:00
|
|
|
_,
|
|
|
|
|
|
|
|
|
|
pub fn phrase(self: Status) ?[]const u8 {
|
|
|
|
|
return switch (self) {
|
|
|
|
|
// 1xx statuses
|
|
|
|
|
.@"continue" => "Continue",
|
|
|
|
|
.switching_protocols => "Switching Protocols",
|
|
|
|
|
.processing => "Processing",
|
|
|
|
|
.early_hints => "Early Hints",
|
|
|
|
|
|
|
|
|
|
// 2xx statuses
|
|
|
|
|
.ok => "OK",
|
|
|
|
|
.created => "Created",
|
|
|
|
|
.accepted => "Accepted",
|
|
|
|
|
.non_authoritative_info => "Non-Authoritative Information",
|
|
|
|
|
.no_content => "No Content",
|
|
|
|
|
.reset_content => "Reset Content",
|
|
|
|
|
.partial_content => "Partial Content",
|
|
|
|
|
.multi_status => "Multi-Status",
|
|
|
|
|
.already_reported => "Already Reported",
|
|
|
|
|
.im_used => "IM Used",
|
|
|
|
|
|
|
|
|
|
// 3xx statuses
|
|
|
|
|
.multiple_choice => "Multiple Choice",
|
|
|
|
|
.moved_permanently => "Moved Permanently",
|
|
|
|
|
.found => "Found",
|
|
|
|
|
.see_other => "See Other",
|
|
|
|
|
.not_modified => "Not Modified",
|
|
|
|
|
.use_proxy => "Use Proxy",
|
|
|
|
|
.temporary_redirect => "Temporary Redirect",
|
|
|
|
|
.permanent_redirect => "Permanent Redirect",
|
|
|
|
|
|
|
|
|
|
// 4xx statuses
|
|
|
|
|
.bad_request => "Bad Request",
|
|
|
|
|
.unauthorized => "Unauthorized",
|
|
|
|
|
.payment_required => "Payment Required",
|
|
|
|
|
.forbidden => "Forbidden",
|
|
|
|
|
.not_found => "Not Found",
|
|
|
|
|
.method_not_allowed => "Method Not Allowed",
|
|
|
|
|
.not_acceptable => "Not Acceptable",
|
|
|
|
|
.proxy_auth_required => "Proxy Authentication Required",
|
|
|
|
|
.request_timeout => "Request Timeout",
|
|
|
|
|
.conflict => "Conflict",
|
|
|
|
|
.gone => "Gone",
|
|
|
|
|
.length_required => "Length Required",
|
|
|
|
|
.precondition_failed => "Precondition Failed",
|
|
|
|
|
.payload_too_large => "Payload Too Large",
|
|
|
|
|
.uri_too_long => "URI Too Long",
|
|
|
|
|
.unsupported_media_type => "Unsupported Media Type",
|
|
|
|
|
.range_not_satisfiable => "Range Not Satisfiable",
|
|
|
|
|
.expectation_failed => "Expectation Failed",
|
|
|
|
|
.teapot => "I'm a teapot",
|
|
|
|
|
.misdirected_request => "Misdirected Request",
|
|
|
|
|
.unprocessable_entity => "Unprocessable Entity",
|
|
|
|
|
.locked => "Locked",
|
|
|
|
|
.failed_dependency => "Failed Dependency",
|
|
|
|
|
.too_early => "Too Early",
|
|
|
|
|
.upgrade_required => "Upgrade Required",
|
|
|
|
|
.precondition_required => "Precondition Required",
|
|
|
|
|
.too_many_requests => "Too Many Requests",
|
2023-04-26 11:02:55 -07:00
|
|
|
.request_header_fields_too_large => "Request Header Fields Too Large",
|
2022-12-12 21:18:56 -07:00
|
|
|
.unavailable_for_legal_reasons => "Unavailable For Legal Reasons",
|
|
|
|
|
|
|
|
|
|
// 5xx statuses
|
|
|
|
|
.internal_server_error => "Internal Server Error",
|
|
|
|
|
.not_implemented => "Not Implemented",
|
|
|
|
|
.bad_gateway => "Bad Gateway",
|
|
|
|
|
.service_unavailable => "Service Unavailable",
|
|
|
|
|
.gateway_timeout => "Gateway Timeout",
|
|
|
|
|
.http_version_not_supported => "HTTP Version Not Supported",
|
|
|
|
|
.variant_also_negotiates => "Variant Also Negotiates",
|
|
|
|
|
.insufficient_storage => "Insufficient Storage",
|
|
|
|
|
.loop_detected => "Loop Detected",
|
|
|
|
|
.not_extended => "Not Extended",
|
|
|
|
|
.network_authentication_required => "Network Authentication Required",
|
|
|
|
|
|
|
|
|
|
else => return null,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub const Class = enum {
|
|
|
|
|
informational,
|
|
|
|
|
success,
|
|
|
|
|
redirect,
|
|
|
|
|
client_error,
|
|
|
|
|
server_error,
|
|
|
|
|
};
|
|
|
|
|
|
2023-01-04 18:28:37 -07:00
|
|
|
pub fn class(self: Status) Class {
|
2023-06-15 13:14:16 +06:00
|
|
|
return switch (@intFromEnum(self)) {
|
2022-12-12 21:18:56 -07:00
|
|
|
100...199 => .informational,
|
|
|
|
|
200...299 => .success,
|
|
|
|
|
300...399 => .redirect,
|
|
|
|
|
400...499 => .client_error,
|
2023-01-05 13:31:26 -07:00
|
|
|
else => .server_error,
|
2022-12-12 21:18:56 -07:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test {
|
|
|
|
|
try std.testing.expectEqualStrings("OK", Status.ok.phrase().?);
|
|
|
|
|
try std.testing.expectEqualStrings("Not Found", Status.not_found.phrase().?);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
test {
|
2023-10-07 22:46:35 +02:00
|
|
|
try std.testing.expectEqual(Status.Class.success, Status.ok.class());
|
|
|
|
|
try std.testing.expectEqual(Status.Class.client_error, Status.not_found.class());
|
2022-12-12 21:18:56 -07:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-06-27 20:05:22 -07:00
|
|
|
/// compression is intentionally omitted here since it is handled in `ContentEncoding`.
|
2023-01-05 19:27:53 -07:00
|
|
|
pub const TransferEncoding = enum {
|
|
|
|
|
chunked,
|
2023-10-06 21:38:05 -05:00
|
|
|
none,
|
2023-03-08 08:20:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pub const ContentEncoding = enum {
|
2023-09-26 17:16:40 -04:00
|
|
|
identity,
|
2023-01-05 19:27:53 -07:00
|
|
|
compress,
|
2023-10-06 21:38:05 -05:00
|
|
|
@"x-compress",
|
2023-01-05 19:27:53 -07:00
|
|
|
deflate,
|
|
|
|
|
gzip,
|
2023-10-06 21:38:05 -05:00
|
|
|
@"x-gzip",
|
2023-03-08 08:20:53 -06:00
|
|
|
zstd,
|
2023-01-05 19:27:53 -07:00
|
|
|
};
|
|
|
|
|
|
2023-03-06 20:13:15 -06:00
|
|
|
pub const Connection = enum {
|
|
|
|
|
keep_alive,
|
|
|
|
|
close,
|
|
|
|
|
};
|
|
|
|
|
|
std.http: remove Headers API
I originally removed these in 402f967ed5339fa3d828b7fe1d57cdb5bf38dbf2.
I allowed them to be added back in #15299 because they were smuggled in
alongside a bug fix, however, I wasn't kidding when I said that I wanted
to take the design of std.http in a different direction than using this
data structure.
Instead, some headers are provided via explicit field names populated
while parsing the HTTP request/response, and some are provided via
new fields that support passing extra, arbitrary headers.
This resulted in simplification of logic in many places, as well as
elimination of the possibility of failure in many places. There is
less deinitialization code happening now.
Furthermore, it made it no longer necessary to clone the headers data
structure in order to handle redirects.
http_proxy and https_proxy fields are now pointers since it is common
for them to be unpopulated.
loadDefaultProxies is changed into initDefaultProxies to communicate
that it does not actually load anything from disk or from the network.
The function now is leaky; the API user must pass an already
instantiated arena allocator. Removes the need to deinitialize proxies.
Before, proxies stored arbitrary sets of headers. Now they only store
the authorization value.
Removed the duplicated code between https_proxy and http_proxy. Finally,
parsing failures of the environment variables result in errors being
emitted rather than silently ignoring the proxy.
error.CompressionNotSupported is renamed to
error.CompressionUnsupported, matching the naming convention from all
the other errors in the same set.
Removed documentation comments that were redundant with field and type
names.
Disabling zstd decompression in the server for now; see #18937.
I found some apparently dead code in src/Package/Fetch/git.zig. I want
to check with Ian about this.
I discovered that test/standalone/http.zig is dead code, it is only
being compiled but not being run. Furthermore it hangs at the end if you
run it manually. The previous commits in this branch were written under
the assumption that this test was being run with
`zig build test-standalone`.
2024-02-12 23:03:06 -07:00
|
|
|
pub const Header = struct {
|
|
|
|
|
name: []const u8,
|
|
|
|
|
value: []const u8,
|
|
|
|
|
};
|
|
|
|
|
|
2022-05-11 12:43:18 -07:00
|
|
|
test {
|
2024-02-23 02:29:02 -07:00
|
|
|
if (builtin.os.tag != .wasi) {
|
2024-07-04 07:00:56 +01:00
|
|
|
_ = Client;
|
|
|
|
|
_ = Method;
|
|
|
|
|
_ = Server;
|
|
|
|
|
_ = Status;
|
|
|
|
|
_ = HeadParser;
|
|
|
|
|
_ = ChunkParser;
|
2024-08-04 15:25:42 -07:00
|
|
|
_ = WebSocket;
|
2024-02-23 02:29:02 -07:00
|
|
|
_ = @import("http/test.zig");
|
|
|
|
|
}
|
2022-05-11 12:43:18 -07:00
|
|
|
}
|