Hyper – A fast and correct HTTP implementation for Rust
crates.io
crates.io
Interestingly, Cloudflare wanted to use hyper but found that it was too correct, so they had to build their own [1].
[1] https://blog.cloudflare.com/how-we-built-pingora-the-proxy-t...
The only downside is that you have to install sqlx-cli and you have to run a couple of special commands to make your binary compile offline or on CI/CD where you don’t provide that database connection.
You can adapt from async to sync but there is a definite complexity tax with all the pinning plus the runtime cost of the extra pinning.
Async is great for more proxy like use cases though.
Interesting, I'm curious about the details here. Does the lb reuse connections for multiple requests or something?
I'm curious too. There must be more to it than that because LBs reusing backhaul connections is standard practice. It's not only an optimization but in many cases you'll quickly hit ephemeral port exhaustion if you don't. TCP connections are distinguished by (src_ip, src_port, dst_ip, dst_port) tuple. For this leg you're probably only varying the src_port portion, and all of the valid options are cooling in time_wait state.
Maybe I need more time or a favorable comparison to another framework to appreciate it.
"A fast an correct HTTP implementation" makes sense for Deno, as Deno is founded by the same person who founded Node.js and the correctness of Node's HTTP server was different from that of other scripting languages.
I'm pretty sure Deno is contributing significantly to Hyper.
Deno's HTTP server is more balanced when it comes to tradeoffs than node's I think. Node is optimized for IO-bound programs is what I have heard.
When would I use Hyper instead of Rocket?
It's kind of like that difference between Photoshop and libpng.
Hyper is a dependency:
https://github.com/SergioBenitez/Rocket/blob/v0.5-rc/core/ht...
From template-benchmark-rs [0] I found sailfish [1] (fast, but no fragments(?)). render-rs [2] and syn-rsx [3] both let you write html in rust macros which is cool (maybe that can substitute for fragments?). Then there's gtmpl-rust [4] which is just Go templates reimplemented in rust.
[0]: https://github.com/rosetta-rs/template-benchmarks-rs
[1]: https://github.com/rust-sailfish/sailfish
[2]: https://github.com/render-rs/render.rs last updated Jul 2020
[3]: https://github.com/stoically/syn-rsx last updated Nov 2022
This is a go template for an interactive todos app [1] that I'm experimenting with. The html content of the entire page is present in one template definition which is split into 6 inline {{block}} definitions / "fragments". The page supports 5 interactions indicated by {{define}} definitions, each of which reuse various block fragments relevant to that interaction. I'm in the process of converting it to use embedded cozodb [2] queries which act as a server side data store. The idea here is that the entire 'app', including all html fragments, styles, http requests and responses, db schema, and queries are embedded into this single 100-line file.
[0]: https://htmx.org/essays/template-fragments/
[1]: https://github.com/infogulch/go-htmx/blob/master/templates/t...
Same as partials in Rails, maybe. A while since I used it.
Maybe this?
It's roughly equal to saying that you are doing something strictly by the rules (and the rules don't have to be contained in a book or even exist in text form).
Some uses would be like: "My boss insists on doing everything by the book".
Sitting down with an RFC and coding up what it says is nowhere near as simple as it seems like it should be:
* RFCs are often ambiguous, I've seen teams implement a protocol in a way that certainly seems to follow the RFC but won't be widely interoperable.
* RFCs are often incomplete, many protocols are specified across a lot of different RFCs, and by different authors, so it's easy to miss important details or even whole RFCs exacerbating the above point.
* RFCs are regularly released as protocols evolve and invalidate older versions of the protocol (or early experimental versions of the protocol, etc) often. Sometimes the newest RFC does a lot of work to disambiguate what would be allowed by older versions see for example this recent RFC https://httpwg.org/specs/rfc9110.html
* Independent of what the RFC says, there's what Cisco does (or MS or Google or other large influential imlementors).
* A lot of protocol implementations don't implement the full protocol (that is various extensions or rarely used features).
* A lot of protocol implementations implement what the RFC says in the most commonly aggreed on way, plus a compatibility options for other commonly used implementations, plus some oddball interpretations of the RFC that the authors like.
* There's vendor-specific extensions.
* There's common but unspecified behaviors that implementations tend to converge on, but which aren't easy to intuit.
* There's implementations that handle mixtures of versions (e.g. implementations of http 1.1 that handle 1.0 or 0.9 just fine are common).
And so on. So to answer the question "is 'it's correct' worth mentioning?" - yes, something along these lines tends to be important.
Of course "what does correct mean" is a giant can of worms....
In the case of hyper I think it means: an attempt to be extremely precise in what is allowed (and as close to the disambiguated RFCs as possible), and strict as well - not being particularly loose in what it accepts as input. That's my interpretation anway.
I learned this for myself when I tried coding an IRC server for fun. Quickly found that I made more progress, faster by just using Wireshark to see what an established server was doing and copying that.
But you also can't interact with everyone else anymore, because a whole lot of people run slightly off-spec software, successfully, and sometimes without knowing it.
EDIT: also maybe take a look at this? https://github.com/rousan/AndroidWithRust
"tokio jni" is the search term that turned these up for me
I currently use "ureq" client side, due to async contamination in Hyper.
I myself would still want to use a reverse proxy such as Envoy, Nginx, or Traefik.
If someone from Linkerd would like to weigh in on this, that would be great.