ducaale / xh

Friendly and fast tool for sending HTTP requests
MIT License
5.49k stars 96 forks source link

support http2-prior-knowledge #356

Closed zuisong closed 6 months ago

zuisong commented 6 months ago

--http2-prior-knowledge (HTTP) Issue a non-TLS HTTP requests using HTTP/2 directly without HTTP/1.1 Upgrade. It requires prior knowledge that the server supports HTTP/2 straight away. HTTPS requests still do HTTP/2 the standard way with negotiated protocol version in the TLS handshake.

https://curl.se/docs/manpage.html#--http2-prior-knowledge

current:

❯ xh --http-version=2 http://x.com -v
GET / HTTP/2.0
accept: */*
accept-encoding: gzip, deflate, br
host: x.com
user-agent: xh/0.21.0

xh: error: error sending request for url (http://x.com/): request has unsupported HTTP version

Caused by:
    request has unsupported HTTP version

xh on http2_prior_knowledge:master [⇡] is 📦 v0.21.0 via 🦀 v1.76.0 

after:

❯ cargo run -- --http-version=2-prior-knowledge  http://x.com -v
    Finished dev [unoptimized + debuginfo] target(s) in 0.31s
     Running `/Users/xxx/.rust-target/debug/xh --http-version=2-prior-knowledge 'http://x.com' -v`
GET / HTTP/2.0
accept: */*
accept-encoding: gzip, deflate, br
host: x.com
user-agent: xh/0.21.0

HTTP/2.0 301 Moved Permanently
cache-control: no-cache, no-store, max-age=0
content-length: 0
date: Fri, 22 Mar 2024 04:22:32 GMT
location: https://x.com/
perf: 7469935968
server: tsa_q
x-connection-hash: 7a464c1a076a5af16cde9cf3594760f6edde4ea5c7f91ef75c564d470b595130
x-response-time: 119
x-transaction-id: 9d05eb595bc41b2e