0

How to get request body with content-type: Application/json using python httptools? I`m using it with uvloop.

The request class looks like this:

class HttpRequest:
    __slots__ = ('_protocol', '_url', '_headers', '_version')

    def __init__(self, protocol, url, headers, version):
        self._protocol = protocol
        self._url = url
        self._headers = headers
        self._version = version
Benyamin Jafari
  • 27,880
  • 26
  • 135
  • 150
Lem
  • 151
  • 6
  • 16
  • Are you talking about [httptools](https://github.com/MagicStack/httptools)? In that case, look at `on_body`. What have you tried? – MatsLindh Aug 27 '17 at 12:29
  • Solved! yes, thank you @MatsLindh, i add on_body method in my HttpProtocol implementation like this: def on_body(self, body): self._body = body – Lem Aug 27 '17 at 13:39

1 Answers1

2

You can add a method named on_body that will receive the body of the HTTP request as its parameter.

The supported callback functions on the object you provide when creating a HttpRequestParser with httptools are:

- on_message_begin()
- on_header(name: bytes, value: bytes)
- on_headers_complete()
- on_body(body: bytes)
- on_message_complete()
- on_chunk_header()
- on_chunk_complete()
MatsLindh
  • 49,529
  • 4
  • 53
  • 84