http-parser icon

http-parser For Linux

  n/a
MIT/X Consortium License    

HTTP request/response parser. #HTTP request parser  #HTTP response parser  #HTTP  #Request  #Response  #Parser  

Description

Free Download

http-parser is a HTTP request/response parser for Python in C under MIT License, based on http-parser from Ryan Dahl.

pip install http-parser

Or install from source:

git clone git://github.com/benoitc/http-parser.git cd http-parser && python setup.py install

http-parser provide you parser.HttpParser low-level parser in C that you can access in your python program and http.HttpStream providing higher-level access to a readable,sequential io.RawIOBase object.

To help you in your day work, http-parser prvides you 3 kind of readers in the reader module: IterReader to read iterables, StringReader to reads strings and StringIO objects, SocketReader to read sockets or objects with the same aî (recv_into needed). You cnan of course use any io.RawIOBase object.

Likre http-parser in C you can pass your own callbacks to the C parser, so you can eventually parse asynchronously any HTTP stream. Callbacks are:

on_message_begin() on_path(path) on_query_string(query_string) on_url(url) on_fragment(fragment) on_header_field(field, last_was_value) on_header_value(key, value) on_headers_complete() on_body(chunk) on_message_complete()

Example of HttpStream ex:

#!/usr/bin/env python import socket

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

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

if __name__ == "__main__":  main()

Example of HttpParser:

#!/usr/bin/env python import socket

from http_parser.parser import HttpParser

def main():

p = HttpParser()  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  body = []  try:  s.connect(('gunicorn.org', 80))  s.send("GET / HTTP/1.1\r\nHost: gunicorn.org\r\n\r\n")

while True:  data = s.recv(1024)  if not data:  break

recved = len(data)  nparsed = p.execute(data, recved)  assert nparsed == recved

if p.is_headers_complete():  print p.get_headers()

if p.is_partial_body():  body.append(p.recv_body())

if p.is_message_complete():  break

print "".join(body)

finally:  s.close()

if __name__ == "__main__":  main()

You can find more docs in the code (or use a doc genererator).

System requirements

  • Python
  • Cython if you need to rebuild the C code

http-parser 0.8.3

add to watchlist add to download basket send us an update REPORT
  runs on:
Linux
  filename:
http-parser-0.8.3.tar.gz
  main category:
Internet
  developer:
  visit homepage

paint.net 5.0.13 (5.13.8830.42291)

Packed with an array of options and an intuitive interface, this application enables you to create professional-looking photographs
paint.net

ShareX 16.0.1

Capture your screen, create GIFs, and record videos through this versatile solution that includes various other amenities: an OCR scanner, image uploader, URL shortener, and much more
ShareX

IrfanView 4.67

With support for a long list of plugins, this minimalistic utility helps you view images, as well as edit and convert them using a built-in batch mode
IrfanView

Zoom Client 6.0.0.37205

The official desktop client for Zoom, the popular video conferencing and collaboration tool used by millions of people worldwide
Zoom Client

4k Video Downloader 1.5.3.0080 Plus / 4.30.0.5655

Export your favorite YouTube videos and playlists with this intuitive, lightweight program, built to facilitate downloading clips from the popular website
4k Video Downloader

calibre 7.8.0

Effortlessly keep your e-book library thoroughly organized with the help of the numerous features offered by this efficient and capable manager
calibre

Microsoft Teams 24060.2623.2790.8046 Home / 1.7.00.7956 Work

Effortlessly chat, collaborate on projects, and transfer files within a business-like environment by employing this Microsoft-vetted application
Microsoft Teams

Bitdefender Antivirus Free 27.0.35.146

Feather-light and free antivirus solution from renowned developer that keeps the PC protected at all times from malware without requiring user configuration
Bitdefender Antivirus Free

7-Zip 23.01 / 24.04 Beta

An intuitive application with a very good compression ratio that can help you not only create and extract archives, but also test them for errors
7-Zip

Windows Sandbox Launcher 1.0.0

Set up the Windows Sandbox parameters to your specific requirements, with this dedicated launcher that features advanced parametrization
Windows Sandbox Launcher

38% discount
Bitdefender Antivirus Free
  • Bitdefender Antivirus Free
  • 7-Zip
  • Windows Sandbox Launcher
  • paint.net
  • ShareX
  • IrfanView
  • Zoom Client
  • 4k Video Downloader
  • calibre
  • Microsoft Teams
essentials


User Comments
This enables Disqus, Inc. to process some of your data. Disqus privacy policy