How to use the h11.ConnectionClosed function in h11

To help you get started, we’ve selected a few h11 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pgjones / hypercorn / tests / asyncio / test_wsproto.py View on Github external
def get_events(self) -> list:
        events = []
        self.client.receive_data(self.transport.data)
        while True:
            event = self.client.next_event()
            if event in (h11.NEED_DATA, h11.PAUSED):
                break
            events.append(event)
            if isinstance(event, h11.ConnectionClosed):
                break
        return events
github pgjones / hypercorn / tests / trio / test_wsproto.py View on Github external
async def get_events(self) -> list:
        events = []
        self.client.receive_data(await self.client_stream.receive_some(2 ** 16))
        while True:
            event = self.client.next_event()
            if event in (h11.NEED_DATA, h11.PAUSED):
                break
            events.append(event)
            if isinstance(event, h11.ConnectionClosed):
                break
        return events
github pgjones / hypercorn / tests / asyncio / test_h11.py View on Github external
def get_events(self) -> list:
        events = []
        self.client.receive_data(self.transport.data)
        while True:
            event = self.client.next_event()
            if event in (h11.NEED_DATA, h11.PAUSED):
                break
            events.append(event)
            if isinstance(event, h11.ConnectionClosed):
                break
        return events
github pgjones / hypercorn / tests / trio / test_h11.py View on Github external
async def get_events(self) -> list:
        events = []
        self.client.receive_data(await self.client_stream.receive_some(2 ** 16))
        while True:
            event = self.client.next_event()
            if event in (h11.NEED_DATA, h11.PAUSED):
                break
            events.append(event)
            if isinstance(event, h11.ConnectionClosed):
                break
        return events
github pgjones / hypercorn / hypercorn / protocol / h11.py View on Github external
else:
                if isinstance(event, h11.Request):
                    await self._check_protocol(event)
                    await self._create_stream(event)
                elif isinstance(event, h11.Data):
                    await self.stream.handle(Body(stream_id=STREAM_ID, data=event.data))
                elif isinstance(event, h11.EndOfMessage):
                    await self.stream.handle(EndBody(stream_id=STREAM_ID))
                elif isinstance(event, Data):
                    # WebSocket pass through
                    await self.stream.handle(event)
                elif event is h11.PAUSED:
                    await self.send(Updated())
                    await self.can_read.clear()
                    await self.can_read.wait()
                elif isinstance(event, h11.ConnectionClosed) or event is h11.NEED_DATA:
                    break
github mike820324 / microProxy / microproxy / protocol / http1.py View on Github external
path=self._req.target,
                            headers=self._req.headers,
                            body=b"".join(self._body_chunks)))
                    else:
                        if not self._resp:  # pragma: no cover
                            # NOTE: guess that never happen because h11 should help us handle http state
                            raise ProtocolError("EndOfMessage received, but not response found")
                        self.on_response(HttpResponse(
                            version=self._parse_version(self._resp),
                            reason=self._resp.reason,
                            code=str(self._resp.status_code),
                            headers=self._resp.headers,
                            body=b"".join(self._body_chunks)))
                    self._cleanup_after_received()
                    break
                elif isinstance(event, ConnectionClosed):  # pragma: no cover
                    raise ProtocolError("Should closed the connection")
                elif event is h11.NEED_DATA:
                    break
                elif event is h11.PAUSED:  # pragma: no cover
                    break
                else:  # pragma: no cover
                    logger.warning("event recevied was not handled from {0}: {1}".format(self.conn_type, repr(event)))
        except Exception as e:  # pragma: no cover
            if raise_exception:
                raise
            logger.error("Exception on {0}".format(self.conn_type))
            logger.exception(e)
github sorcio / trio-asgi / trio_web / h11server.py View on Github external
async def send(self, event):
        # The code below doesn't send ConnectionClosed, so we don't bother
        # handling it here either -- it would require that we do something
        # appropriate when 'data' is None.
        assert type(event) is not h11.ConnectionClosed
        data = self.conn.send(event)
        await self.stream.send_all(data)
github python-hyper / h11 / fuzz / afl-server.py View on Github external
def process_all(c):
    while True:
        event = c.next_event()
        if event is h11.NEED_DATA or event is h11.PAUSED:
            break
        if type(event) is h11.ConnectionClosed:
            break
github encode / httpx / httpx / dispatch / http11.py View on Github external
import h11

from ..concurrency.base import BaseSocketStream
from ..config import Timeout
from ..exceptions import ConnectionClosed, ProtocolError
from ..models import Request, Response
from ..utils import get_logger
from .base import OpenConnection

H11Event = typing.Union[
    h11.Request,
    h11.Response,
    h11.InformationalResponse,
    h11.Data,
    h11.EndOfMessage,
    h11.ConnectionClosed,
]


# Callback signature: async def callback() -> None
# In practice the callback will be a functools partial, which binds
# the `ConnectionPool.release_connection(conn: HTTPConnection)` method.
OnReleaseCallback = typing.Callable[[], typing.Awaitable[None]]


logger = get_logger(__name__)


class HTTP11Connection(OpenConnection):
    READ_NUM_BYTES = 4096

    def __init__(
github encode / httpx / httpx / dispatch / http11.py View on Github external
async def close(self) -> None:
        event = h11.ConnectionClosed()
        try:
            logger.trace(f"send_event event={event!r}")
            self.h11_state.send(event)
        except h11.LocalProtocolError:  # pragma: no cover
            # Premature client disconnect
            pass
        await self.socket.close()