How to send a http2 request headers with python socket

583 Views Asked by At

In python:

the http/1.1 request header is :

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

request_header = 'GET {} HTTP/1.1\r\nhost: {}\r\nConnection: close\r\n' \
          'Accept-Encoding: gzip,deflate\r\n\r\n'.format(path, host)

s = s.send(request_header.encode())

In my question is , what does the http/2 request_header like?

anyone can help me !! thanks

I've been looking at a lot of resources, but there are no examples of how to create HTTP/2 requests using sockets

1

There are 1 best solutions below

2
Eugene Yalansky On

Well if you are interested in stable implementation you could take a look at h2. They have an example on plain sockets. If you are interested in educational purposes poke around with tcpdump / wireshark (wshrk http2 wiki page). So you can read how the actual communication looks like in a propper tool, and implement your own version based on the example.