Description


http-parser


http-parser is a handy tool for parsing HTTP requests and responses in Python, and it's built in C under the MIT License. This software is based on the original http-parser created by Ryan Dahl.



How to Install http-parser


If you want to get started with http-parser, you can easily install it using pip. Just run:


pip install http-parser

If you prefer installing from source, here's what you need to do:


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


Features of http-parser


This tool gives you access to a low-level parser called HttpParser, written in C, right in your Python programs. It also has a higher-level feature called HttpStream, which lets you work with a readable, sequential io.RawIOBase object.



User-Friendly Readers Available


The http-parser makes your job easier with three types of readers in its reader module:



  • IterReader: For reading iterables.

  • StringReader: For reading strings and StringIO objects.

  • SocketReader: For reading sockets or similar objects (you'll need recv_into).


You can also use any io.RawIOBase object that suits your needs!



Create Your Own Callbacks!


You can pass your own callbacks to the C parser just like the original C http-parser. This means you can parse HTTP streams asynchronously! Here are some useful callbacks:



  • 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)






A Simple Example of Using HttpStream


You can quickly see how this works with a simple code example:


#!/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(b"GET / HTTP/1.1\r\nHost: gunicorn.org\r\n\r\n")
r = SocketReader(s)
p = HttpStream(r)
printf(p.headers())
printf(p.body_file().read())
finally:
s.close()
if __name__ == "__main__":
main()

Tags:

User Reviews for http-parser For Linux 7

  • for http-parser For Linux
    http-parser FOR LINUX provides powerful features for parsing HTTP requests/responses in Python with low-level and high-level access. Efficient for developers.
    Reviewer profile placeholder Jennifer Lopez
  • for http-parser For Linux
    This app is incredible! The HTTP parsing capabilities are seamless and incredibly efficient. Highly recommend!
    Reviewer profile placeholder Alice Johnson
  • for http-parser For Linux
    I love using http-parser for my Python projects. It makes handling HTTP requests so much easier. Five stars!
    Reviewer profile placeholder Mike Smith
  • for http-parser For Linux
    Fantastic tool for developers! The ability to access low-level parsing in Python is a game changer.
    Reviewer profile placeholder Laura Kim
  • for http-parser For Linux
    Highly effective and easy to use! The documentation is clear, making implementation a breeze. A must-have app!
    Reviewer profile placeholder James Brown
  • for http-parser For Linux
    Amazing performance! I appreciate the asynchronous capabilities, which make my applications run smoother.
    Reviewer profile placeholder Emily Davis
  • for http-parser For Linux
    Absolutely love this parser! It simplifies HTTP request handling in Python like no other library I've tried.
    Reviewer profile placeholder David Wilson