File: //usr/lib/python3/dist-packages/twisted/protocols/haproxy/__pycache__/_wrapper.cpython-38.pyc
U
W[� � @ s~ d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZ G d d
� d
ej
e�ZG dd� dej�Zd
d� ZdS )z@
Protocol wrapper that provides HAProxy PROXY protocol support.
� )�policies)�
interfaces)�_WrapperServerEndpoint� )�InvalidProxyHeader)�V1Parser)�V2Parserc @ s0 e Zd ZdZdd� Zdd� Zdd� Zdd � Zd
S )�HAProxyProtocolWrappera
A Protocol wrapper that provides HAProxy support.
This protocol reads the PROXY stream header, v1 or v2, parses the provided
connection data, and modifies the behavior of getPeer and getHost to return
the data provided by the PROXY header.
c C s t j�| ||� d | _d | _d S �N)r �ProtocolWrapper�__init__�
_proxyInfo�_parser)�self�factory�wrappedProtocol� r �D/usr/lib/python3/dist-packages/twisted/protocols/haproxy/_wrapper.pyr s zHAProxyProtocolWrapper.__init__c C s� | j d k r| j�|�S | jd kr�t|�dkr`|d d� tjkr`t|dd� �d@ dkr`t� | _n4t|�dkr�|d d� tj kr�t� | _n| �
� d S z&| j�|�\| _ }|r�| j�|� W n tk
r� | �
� Y nX d S )N� � �
�� � � � )
r
r �dataReceivedr �lenr ZPREFIX�ordr ZPROXYSTRZloseConnectionZfeedr )r �dataZ remainingr r r r # s(
���
z#HAProxyProtocolWrapper.dataReceivedc C s | j r| j jr| j jS | j�� S r
)r
�source� transport�getPeer�r r r r r! <