1414 RstStreamFrame , PushPromiseFrame , AltSvcFrame
1515)
1616
17- from .config import H2Configuration
1817from .errors import STREAM_CLOSED
1918from .events import (
2019 RequestReceived , ResponseReceived , DataReceived , WindowUpdated ,
2726)
2827from .utilities import (
2928 guard_increment_window , is_informational_response , authority_from_headers ,
30- validate_headers , validate_sent_headers , normalize_sent_headers ,
29+ validate_headers , validate_outbound_headers , normalize_outbound_headers ,
3130 HeaderValidationFlags , extract_method_header
3231)
3332
@@ -672,7 +671,7 @@ class H2Stream(object):
672671 Attempts to create frames that cannot be sent will raise a
673672 ``ProtocolError``.
674673 """
675- def __init__ (self , stream_id ):
674+ def __init__ (self , stream_id , config ):
676675 self .state_machine = H2StreamStateMachine (stream_id )
677676 self .stream_id = stream_id
678677 self .max_outbound_frame_size = None
@@ -692,7 +691,7 @@ def __init__(self, stream_id):
692691 self ._authority = None
693692
694693 # The configuration for this stream.
695- self .config = H2Configuration ()
694+ self .config = config
696695
697696 @property
698697 def open (self ):
@@ -769,7 +768,8 @@ def send_headers(self, headers, encoder, end_stream=False):
769768 hf = HeadersFrame (self .stream_id )
770769 hdr_validation_flags = self ._build_hdr_validation_flags (events )
771770 frames = self ._build_headers_frames (
772- headers , encoder , hf , hdr_validation_flags )
771+ headers , encoder , hf , hdr_validation_flags
772+ )
773773
774774 if end_stream :
775775 # Not a bug: the END_STREAM flag is valid on the initial HEADERS
@@ -807,7 +807,8 @@ def push_stream_in_band(self, related_stream_id, headers, encoder):
807807 ppf .promised_stream_id = related_stream_id
808808 hdr_validation_flags = self ._build_hdr_validation_flags (events )
809809 frames = self ._build_headers_frames (
810- headers , encoder , ppf , hdr_validation_flags )
810+ headers , encoder , ppf , hdr_validation_flags
811+ )
811812
812813 return frames
813814
@@ -931,10 +932,7 @@ def receive_headers(self, headers, end_stream, header_encoding):
931932 raise ProtocolError ("Trailers must have END_STREAM set" )
932933
933934 if self .config .validate_inbound_headers :
934- hdr_validation_flags = HeaderValidationFlags (
935- is_client = self .state_machine .client ,
936- is_trailer = isinstance (events [0 ], TrailersReceived )
937- )
935+ hdr_validation_flags = self ._build_hdr_validation_flags (events )
938936 headers = validate_headers (headers , hdr_validation_flags )
939937
940938 if header_encoding :
@@ -1039,7 +1037,9 @@ def _build_hdr_validation_flags(self, events):
10391037 and validating header blocks.
10401038 """
10411039 try :
1042- is_trailer = isinstance (events [0 ], _TrailersSent )
1040+ is_trailer = isinstance (
1041+ events [0 ], (_TrailersSent , TrailersReceived )
1042+ )
10431043 except IndexError :
10441044 is_trailer = False
10451045
@@ -1058,10 +1058,14 @@ def _build_headers_frames(self,
10581058 """
10591059 # We need to lowercase the header names, and to ensure that secure
10601060 # header fields are kept out of compression contexts.
1061- if self .config .normalize_sent_headers :
1062- headers = normalize_sent_headers (headers , hdr_validation_flags )
1063- if self .config .validate_sent_headers :
1064- headers = validate_sent_headers (headers , hdr_validation_flags )
1061+ if self .config .normalize_outbound_headers :
1062+ headers = normalize_outbound_headers (
1063+ headers , hdr_validation_flags
1064+ )
1065+ if self .config .validate_outbound_headers :
1066+ headers = validate_outbound_headers (
1067+ headers , hdr_validation_flags
1068+ )
10651069
10661070 encoded_headers = encoder .encode (headers )
10671071
0 commit comments