python-hyper / hyper

HTTP/2 for Python.
http://hyper.rtfd.org/en/latest/
MIT License
1.05k stars 191 forks source link

Forcing Cleartext HTTP2 Without Upgrade Mechanism #427

Open iamthebot opened 4 years ago

iamthebot commented 4 years ago

Is there a way to send a request to a server that only supports HTTP2 (eg; running libnghttp2) without requiring the upgrade mechanism (which many HTTP2 only implementations do not support)?

In curl, there's a http2-prior-knowledge flag that accomplishes this.

ghost commented 4 years ago

I want this too! Any idea whether it is possible?

ghost commented 4 years ago

Note: I tried the flag with curl (--http2-prior-knowledge), but it still sends:

POST /blablbla/bla HTTP/1.1

Connection: Upgrade, HTTP2-Settings Upgrade: h2c

Any idea why?

I am using:

curl -V

curl 7.68.0 (x86_64-redhat-linux-gnu) libcurl/7.68.0 NSS/3.44 zlib/1.2.7 libpsl/0.7.0 (+libicu/50.1.2) libssh2/1.9.0 nghttp2/1.31.1 Release-Date: 2020-01-08 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz Metalink NTLM NTLM_WB PSL SPNEGO SSL UnixSockets

zetahernandez commented 4 years ago

you can bypass the protocol negotiation and talk directly with a HTTP2 only server this way.

from hyper.http20.connection import HTTP20Connection
connection = HTTP20Connection(
     host='localhost',
     port=8888,
)
request = connection.request('POST', '/', body="")
response = connection.get_response(request)
body = response.read()