-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
http client in the standard library #2007
Comments
I am assuming this would be a HTTP/1.1 client. The use case you mention has no need for the much more complicated HTTP/2 or HTTP/3. |
I found a workaround here Lines 219 to 247 in 5026db1
|
Most of HTTP client/server code can be done without any IO notion at all. For example python implementation https://h11.readthedocs.io/en/latest/. It would be great so see similar approach in Zig. @andrewrk how do you plan to support SSL in stdlib? Self-hosted implementation of tls1.2 is a pretty big investment. Or package manager can be linked with external library on its own? |
I think we do not need such huge and opinionated modules in standard library. There are a lot of open questions to me. Protocol: Not sure about Apple products, how much NSURLRequest is integrated with other OS components. Trusted Certificates: Protocol versions and extensions: Various helpers: Uploading a file to an HTTP server is a process of creating MIME envelope for file data and supplying a few headers. Should HTTP client library be dependent on/play nicely with MIME library? MIME is a huge beast, I've wrote a few parsers, it's not an easy task. Should the same MIME library be reused for email? Honestly, I'd rather wrap WinInet, WinHTTP and libcurl, maybe vendor these libraries like musl. Rewriting anything related to HTTP in Zig, taking into account limited resources, enormous size of task, and questionable benefits does not seem reasonable to me. |
Here is my simple HTTP client that I am now using as a replacement for |
@Mouvedia could you elaborate on how those issues are blocking this one? I just want to keep up-to-date with the goings on. |
@marler8997 #287 being the last blocker, what was left of it was divided into two separate issues. |
@Mouvedia I read through those issues but am unclear as to how issues with copy eliding affect inclusion of an HTTP client in the standard library? |
With how ubiquitous HTTP is in the world, I feel this should definitely not be one of those things where everyone rolls their own solution and that this should absolutely be implemented in the std lib. Not having base primitives for interacting with the Web in Zig would severely hurt its ecosystem. |
I kinda agree that HTTP is de facto standard package/module for any language and stdlib, but this might be out of scope for Zig 'cause it's targeting on another type of projects. Probably an official package under Ziglang organisation might work well 👀 |
Anything that is necessary for the package manager will need to go into the standard library, that includes an HTTP client. |
Hi everyone ! I just finished a tiny library called http that provides request and response builders. Here is a snippet, and I would love to have your reviews on the current API ! const Request = @import("http").Request;
const std = @import("std");
var request = try Request.builder(std.testing.allocator)
.get("https://ziglang.org/")
.header("GOTTA GO", "FAST")
.body("ᕕ( ᐛ )ᕗ");
defer request.deinit(); As of yet, the library does not contains a URI parser or a correct Header multimap implementations because I wanted to discuss with you where does the Zig HTTP story should be happening and what is missing to have a working HTTP stack. Where everything should be happening ?
What is missing in the stack ? As far as I know, we have:
What are the missing parts to have a working HTTP/1.1 client, that for a start, can be used by the package manager? For my part I wanted to start working again on a state machine implementation of the HTTP/1.1 protocol (like what's being done by the guys from python-hyper), that would allow to implement the protocol rules but without dealing with I/O yet. But before starting anything involving, I would like to have your ideas and opinions on what should be done and how. My knowledge on the matter is thin, and for example I can't answer @adontz remarks, but I am willing to help :) Anyway, hope my message make sens ! Have a nice day 🌴 |
Here are (I think) a list of requirements for an HTTP library:
I agree with #2007 (comment) that this is a huge task, and I am not sure it is sane to allocate resources to it. But I think this is important to have this in the standard library. It is a very difficult task, and has wide security and performances implications. |
We are talking of an HTTP lib for the package manager. Most of what I mentioned is required for that. There are some added feature, namely websocket, HTTP2&3 and mobile client (battery and data/cellular) that are not required, but the rest is. I know that list is 5 years from now, but that's exactly my point, we should realize that for many use case this is a list of requirements and that it's huge, that's why I think we should be pragmatic and see if we can use existing libraries. |
I second about the complexity. Also it was said the Zig stdlib won't depend on @andrewrk commented on Mar 13, 2019 in #2056:
But the aforementioned people still can use As a newbie I even think some folks might be able to translate its code from C to Zig and to try incorporating logic of |
PS. I find the The minimal http-client using The screenshot of http-client hello-world using Maybe this will shed some light during creation of the interface to $Subject : ) |
* std.http.Status.Class: add a "nonstandard" enum tag. Instead of having `class` return an optional value, it can potentially return nonstandard. * extract out std.http.Client.Connection from std.http.Client.Request - this code abstracts over plain/TLS only - this is the type that will potentially be stored in a client's LRU connection map * introduce two-staged HTTP header parsing - API users can rely on a heap-allocated buffer with a maximum limit, which defaults to 16 KB, or they can provide a static buffer that is borrowed by the Request instance. - The entire HTTP header is buffered because there are strings in there and they must be accessed later, such as with the case of HTTP redirects. - When buffering the HTTP header, the parser only looks for the \r\n\r\n pattern. Further validation is done later. - After the full HTTP header is buffered, it is parsed into components such as Content-Length and Location. * HTTP redirects are handled, with a maximum redirect count option that defaults to 3. - Connection: close is always used for now; implementing keep-alive connections and an LRU connection pool in std.http.Client is a task for another day. see #2007
Issue extracted from #910.
Note that this is in some ways blocking on:
However what is entirely possible right now is a blocking implementation of an http client. This would not go entirely to waste; it would be one component of the complete system if std lib let you write code agnostic of blocking vs event based.
It's a pretty clear case for including this in the standard library since the package manager will rely on it; however we can revisit the organization of where code lives closer to 1.0.0.
The text was updated successfully, but these errors were encountered: