File: httpstream.py

package info (click to toggle)
python-http-parser 0.9.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: ansic: 1,860; python: 1,072; makefile: 6
file content (24 lines) | stat: -rwxr-xr-x 515 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python
import socket

from http_parser.http import HttpStream
from http_parser.reader import SocketReader

from http_parser.util import b

def main():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    try:
        s.connect(('gunicorn.org', 80))
        s.send(b("GET / HTTP/1.1\r\nHost: gunicorn.org\r\n\r\n"))
        p = HttpStream(SocketReader(s))
        print(p.headers())

        print(p.body_file().read())
    finally:
        s.close()

if __name__ == "__main__":
    main()