Module refinery.units.formats.httpresponse

Expand source code Browse git
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from io import BytesIO
from http.client import HTTPResponse

from ... import Unit


class SockWrapper(BytesIO):
    def makefile(self, _): return self


class httpresponse(Unit):
    """
    Parses HTTP response text, as you would obtain from a packet dump. This can be
    useful if chunked or compressed transfer encoding was used.
    """
    def process(self, data):
        with SockWrapper(data) as mock:
            mock.seek(0)
            parser = HTTPResponse(mock)
            parser.begin()
            return parser.read()

Classes

class SockWrapper (*args, **kwargs)

Buffered I/O implementation using an in-memory bytes buffer.

Expand source code Browse git
class SockWrapper(BytesIO):
    def makefile(self, _): return self

Ancestors

  • _io.BytesIO
  • _io._BufferedIOBase
  • _io._IOBase

Methods

def makefile(self, _)
Expand source code Browse git
def makefile(self, _): return self
class httpresponse

Parses HTTP response text, as you would obtain from a packet dump. This can be useful if chunked or compressed transfer encoding was used.

Expand source code Browse git
class httpresponse(Unit):
    """
    Parses HTTP response text, as you would obtain from a packet dump. This can be
    useful if chunked or compressed transfer encoding was used.
    """
    def process(self, data):
        with SockWrapper(data) as mock:
            mock.seek(0)
            parser = HTTPResponse(mock)
            parser.begin()
            return parser.read()

Ancestors

Inherited members