
    <gsw                     j   d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
 d dlZd dlmZmZ d dlZd dlmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZmZmZ d d	lmZmZ d d
l m!Z!  G d dejD                        Z# G d dejH                        Z%d Z& G d dejN                  ejP                        Z)y)    N)AnyCallableDictListOptional)
connectionevents)connections
exceptionshttp)flow)
basethread)tcp)headershttp2url)r   base)humanc                        e Zd Z fdZdedefdZdedefdZdeeef   fdZ	d	e
ded
ej                  fdZdd	e
dedee   fdZ xZS )SafeH2Connectionc                 d    t        |   |i | || _        t        j                         | _        y N)super__init__conn	threadingRLocklock)selfr   argskwargs	__class__s       k/var/www/html/myenv/lib/python3.12/site-packages/seleniumwire/thirdparty/mitmproxy/server/protocol/http2.pyr   zSafeH2Connection.__init__   s*    $)&)	OO%	    acknowledged_size	stream_idc                     |dk(  ry | j                   5  | j                  ||       | j                  j                  | j	                                d d d        y # 1 sw Y   y xY wNr   )r   acknowledge_received_datar   senddata_to_send)r   r%   r&   s      r#   safe_acknowledge_received_dataz/SafeH2Connection.safe_acknowledge_received_data   sS    !YY 	0**+<iHIINN4,,./	0 	0 	0s   <AA!
error_codec                    | j                   5  	 | j                  ||       | j
                  j                  | j                                d d d        y # t        j                  j                  $ r Y Qw xY w# 1 sw Y   y xY wr   )r   reset_streamh2r   StreamClosedErrorr   r*   r+   )r   r&   r-   s      r#   safe_reset_streamz"SafeH2Connection.safe_reset_stream$   sq    YY 	0!!)Z8 IINN4,,./	0 	0 ==22 	0 	0s-   A6A)A6A30A62A33A66A?new_settingsc                     | j                   5  | j                  |       | j                  j                  | j	                                d d d        y # 1 sw Y   y xY wr   )r   update_settingsr   r*   r+   )r   r3   s     r#   safe_update_settingsz%SafeH2Connection.safe_update_settings-   sE    YY 	0  .IINN4,,./	0 	0 	0s   ;AAraise_zombier   c                     | j                   5   |         | j                  ||j                  fi | | j                  j	                  | j                                d d d        y # 1 sw Y   y xY wr   )r   send_headersfieldsr   r*   r+   )r   r7   r&   r   r!   s        r#   safe_send_headersz"SafeH2Connection.safe_send_headers2   sW    YY 	0NDiB6BIINN4,,./	0 	0 	0s   AA%%A.chunksc                 l   |D ]  }d}|t        |      k  s| j                  j                           || j                  j                         | j                  }||||z    }| j                  |      t        |      k  r0| j                  j                          t        j                  d       | j                  ||       	 | j                  j                  | j                                	 | j                  j                          ||z  }|t        |      k  r |rW| j                  5   |        | j                  |       | j                  j                  | j                                d d d        y y # t        $ r}	|	d }	~	ww xY w# | j                  j                          w xY w# 1 sw Y   y xY w)Nr   皙?)lenr   acquirereleasemax_outbound_frame_sizelocal_flow_control_windowtimesleep	send_datar   r*   r+   	Exception
end_stream)
r   r7   r&   r<   rH   chunkpositionrB   frame_chunkes
             r#   safe_send_bodyzSafeH2Connection.safe_send_body8   sn    	4EHSZ'		!!#TYY../*.*F*F'#HX8O-OP11)<s;?OOII%%'JJsOy+6(IINN4#4#4#67 II%%'33! SZ'	4&  4	*		t00234 4  ! G II%%'4 4s1   )E8,AF*8	FFFFF'*F3)T)__name__
__module____qualname__r   intr,   r2   r   r   r6   r   r   Headersr;   r   bytesrM   __classcell__r"   s   @r#   r   r      s    &
0 0PS 003 0C 00c3h 0
0h 03 0QXQ`Q` 048 4 4TRW[ 4r$   r   c                        e Zd ZU 	  G d d      Zdeddf fdZ	d Z
d Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z xZS )
Http2LayerNc                       e Zd Zd Zd Zd Zy)Http2Layer.H2ConnLoggerc                      || _         || _        y r   )namelog)r   r[   r\   s      r#   r   z Http2Layer.H2ConnLogger.__init__Z   s    DIDHr$   c                 f    dj                  | j                  ||z        }| j                  |d       y )NzH2Conn {}: {}debug)formatr[   r\   )r   fmtstrr    msgs       r#   r^   zHttp2Layer.H2ConnLogger.debug^   s*    !((FTMBCHHS'"r$   c                      y r    )r   r`   r    s      r#   tracezHttp2Layer.H2ConnLogger.traceb   s    r$   N)rN   rO   rP   r   r^   rd   rc   r$   r#   H2ConnLoggerrY   Y   s    		#	r$   re   modereturnc           
      X   t         |   |       || _        t               | _        t        dg      | _        i | _        t        j                  j                  dddd| j                  d| j                              }t        | j                  |      | j                  | j                  <   y )N)r   r   Fclientclient_sideheader_encodingvalidate_outbound_headersvalidate_inbound_headersloggerconfig)r   r   rf   dictstreamsserver_to_client_stream_idsr
   r0   rq   H2Configurationre   r\   r   client_conn)r   ctxrf   rq   r"   s       r#   r   zHttp2Layer.__init__e   s    	:>&;?>(;=**!&+%*$$Xtxx8 + : .>d>N>NW]-^))*r$   c           
         | j                   j                         rlt        j                  j	                  dddd| j                  d| j                              }t        | j                   |      | j                  | j                   <   | j                  | j                      j                          | j                   j                  | j                  | j                      j                                y )NTFserverrj   rp   )server_conn	connectedr0   rq   ru   re   r\   r   r
   initiate_connectionr*   r+   )r   rq   s     r#   _initiate_server_connz Http2Layer._initiate_server_connt   s    %%'YY..  %*/).((488< / >F 2B$BRBR[a1bDT--.))*>>@d..t/?/?@MMOPr$   c                 l   | j                   j                  j                  d      }| j                  | j                      j	                          | j                  | j                      j                  |       | j                   j                  | j                  | j                      j                                y )N   )rv   rfilereadr
   r|   receive_datar*   r+   )r   preambles     r#   _complete_handshakezHttp2Layer._complete_handshake   s    ##))..r2))*>>@))*77Ad..t/?/?@MMOPr$   c                     t               r   )NotImplementedErrorr   s    r#   
next_layerzHttp2Layer.next_layer   s     "##r$   c                 j   | j                  dj                  |rdnd      dt        |      g       d }t        |d      r:|r,|j                  dz  dk(  r| j
                  |j                     }n|j                  }t        |t        j                        r| j                  ||      S t        |t        j                        r| j                  ||      S t        |t        j                        r| j                  |||      S t        |t        j                        r| j                  |      S t        |t        j                         r| j#                  ||||      S t        |t        j$                        r| j'                  ||      S t        |t        j(                        r| j+                  ||      S t        |t        j,                        r| j/                  |      S t        |t        j0                        r| j3                  ||      S t        |t        j4                        r| j7                  ||||      S y)	NzHTTP2 Event from {}ry   ri   r^   r&         T)r\   r_   reprhasattrr&   rt   
isinstancer	   RequestReceived_handle_request_receivedResponseReceived_handle_response_receivedDataReceived_handle_data_receivedStreamEnded_handle_stream_endedStreamReset_handle_stream_resetRemoteSettingsChanged_handle_remote_settings_changedConnectionTerminated_handle_connection_terminatedPushedStreamReceived_handle_pushed_stream_receivedPriorityUpdated_handle_priority_updatedTrailersReceived_handle_trailers)r   eventsource_conn
other_conn	is_servereids         r#   _handle_eventzHttp2Layer._handle_event   s   !((YHM%[M	
 5+&U__q0A566uGooeV33400e<<v66711#u==v223--c5+FFv112,,S11v112,,S%JOOv;;<77zJJv::;55eYGGv::;66u==v55600e<<v667((eY
KK r$   c                 X   t         j                  j                  j                  j                  j                  |j                  D cg c]	  \  }}||g c}}      }t        | | j                  | j                     ||      | j                  |<   t        j                         | j                  |   _        |j                  |j                  j                  | j                  |   _        |j                  j                   | j                  |   _        |j                  j$                  | j                  |   _        |j                  | j                  |   _        | j                  |   j+                          | j                  |   j,                  j.                  j1                          yc c}}w NT)seleniumwire
thirdparty	mitmproxynetr   rR   r   Http2SingleStreamLayerr
   rv   rs   rD   timestamp_startpriority_updated	exclusivepriority_exclusive
depends_onpriority_depends_onweightpriority_weighthandled_priority_eventstartrequest_messagearrivedsetr   r   r   kvr   s         r#   r   z#Http2Layer._handle_request_received   sD   ))3377<<DDY^YfYfEgQUQRTUq!fEgh249I9I$JZJZ9[]`bijS,0IIKS)!!-383I3I3S3SDLL0494J4J4U4UDLL1050F0F0M0MDLL-7<7M7MDLL4S!S))11557 Fhs   F&
c                    t         j                  j                  j                  j                  j                  |j                  D cg c]	  \  }}||g c}}      }d| j                  |   _        t        j                         | j                  |   _
        || j                  |   j                  _        | j                  |   j                  j                  j                          yc c}}w )Nr   T)r   r   r   r   r   rR   r   rs   queued_data_lengthrD   r   response_messager   r   r   s         r#   r   z$Http2Layer._handle_response_received   s    ))3377<<DDY^YfYfEgQUQRTUq!fEgh/0S,,0IIKS)5<S**2S**22668 Fhs   C'
c                    t        j                  | j                  j                  j                        }|r| j
                  |   j                  |kD  r| j
                  |   j                          | j                  |   j                  |j                  t        j                  j                  j                         | j                  dj!                  |      d       ng| j
                  |   j"                  j%                  |j&                         | j
                  |   xj                  t)        |j&                        z  c_        | j                  |   j+                  |j,                  |j                         y)Nz!HTTP body too large. Limit is {}.infoT)r   
parse_sizerq   optionsbody_size_limitrs   r   killr
   r2   r&   r0   errors
ErrorCodesREFUSED_STREAMr\   r_   
data_queueputdatar?   r,   flow_controlled_length)r   r   r   r   bsls        r#   r   z Http2Layer._handle_data_received   s   t{{22BBC4<<$77#=LL""$[);;		$$33 HH8??DfMLL((,,UZZ8LL00C

OC0 	%DD((OO	
 r$   c                     t        j                          | j                  |   _        | j                  |   j                  j	                          yr   )rD   rs   timestamp_endstream_endedr   )r   r   s     r#   r   zHttp2Layer._handle_stream_ended   s7    *.))+S'S&&**,r$   c                    || j                   v r}| j                   |   j                          |r| j                   |   j                  }n| j                   |   j                  }|)| j                  |   j                  ||j                         yr   )rs   r   client_stream_idserver_stream_idr
   r2   r-   )r   r   r   r   r   other_stream_ids         r#   r   zHttp2Layer._handle_stream_reset   sy    $,,LL""$"&,,s"3"D"D"&,,s"3"D"D*  ,>>PUP`P`ar$   c                     t         j                  j                  j                  j                  j                  |j                  D cg c]	  \  }}||g c}}      }|| j                  |   _        yc c}}w r   )	r   r   r   r   r   rR   r   rs   trailers)r   r   r   r   r   r   r   r   s           r#   r   zHttp2Layer._handle_trailers   sb    **4488==EEZ_ZgZgFhRVRSUV1vFhi%-S" Gis   A2
c                     t        |j                  j                         D cg c]  \  }}||j                  f c}}      }| j                  |   j                  |       yc c}}w r   )rr   changed_settingsitems	new_valuer
   r6   )r   r   r   keycsr3   s         r#   r   z*Http2Layer._handle_remote_settings_changed   sU    %BXBXB^B^B`aYc2c2<<0ab$99,G bs   A"
c                 (   | j                  dj                  |rdnd|j                  |j                  |j                        d       |j                  t
        j                  j                  j                  k7  r| j                  | j                     j                  |j                  |j                  |j                         | j                  j                  | j                  | j                     j                                | j                          y	 y)Nz[HTTP/2 connection terminated by {}: error code: {}, last stream id: {}, additional data: {}ry   ri   r   )r-   last_stream_idadditional_dataF)r\   r_   r-   r   r   r0   r   r   NO_ERRORr
   rv   close_connectionr*   r+   _kill_all_streams)r   r   r   s      r#   r   z(Http2Layer._handle_connection_terminated   s    nuu!Hx  !!	# %+		, ryy33<<<T--.?? ++$33 % 5 5 @ 
 !!$"2"243C3C"D"Q"Q"ST""$ 	 r$   c                 j   | j                   |j                     }| j                  | j                     j                  5  | j                  | j                     j                  ||j                  |j                         | j                  j                  | j                  | j                     j                                d d d        t        j                  j                  j                  j                  j                  |j                  D cg c]	  \  }}||g c}}      }t!        | | j                  | j                     |j                  |      }|| j"                  |j                  <   t%        j$                         | j"                  |j                     _        d| j"                  |j                     _        || j"                  |j                     _        t%        j$                         | j"                  |j                     _        | j"                  |j                     j,                  j.                  j1                          | j"                  |j                     j,                  j2                  j1                          | j"                  |j                     j5                          y# 1 sw Y   xY wc c}}w r   )rt   parent_stream_idr
   rv   r   push_streampushed_stream_idr   r*   r+   r   r   r   r   r   rR   r   rs   rD   r   pushedr   r   r   r   r   r   )r   r   
parent_eidr   r   r   layers          r#   r   z)Http2Layer._handle_pushed_stream_received  s	    55e6L6LM
d../44 	UT--.:::uG]G]_d_l_lm!!$"2"243C3C"D"Q"Q"ST	U ))3377<<DDY^YfYfEgQUQRTUq!fEgh&tT-=-=d>N>N-OQVQgQgipq/4U++,?Cyy{U++,<6:U++,3@JU++,==AYY[U++,:U++,<<DDHHJU++,<<IIMMOU++,224	U 	U Fhs   A?J"
J/
"J,c           	         | j                   j                  j                  s| j                  dd       y|| j                  v r| j                  |   j
                  |u ry| j                  | j                     j                  5  |j                  }|| j                  v r2| j                  |   j                  r| j                  |   j                  }|| j                  v rZ|j                  | j                  |   _        |j                  | j                  |   _        |j                  | j                  |   _        | j                  | j                     j#                  ||j                  | j%                  ||j                        |j                         | j                  j'                  | j                  | j                     j)                                d d d        y# 1 sw Y   yxY w)NzLHTTP/2 PRIORITY frame suppressed. Use --http2-priority to enable forwarding.r^   T)r   r   r   )rq   r   http2_priorityr\   rs   r   r
   rz   r   r&   r   r   r   r   r   r   r   
prioritize_map_depends_on_stream_idr*   r+   )r   r   r   mapped_stream_ids       r#   r   z#Http2Layer._handle_priority_updated   s   {{""11HHcelm$,,4<<#4#K#Ku#T d../44 	U$4<</DLLAQ4R4c4c $(<<0@#A#R#R dll"7<S!48=8H8HS!549LLS!1T--.99 ||99:JEL\L\]//	 :  !!$"2"243C3C"D"Q"Q"ST%	U& '	U& s   EGG"c                     |}|| j                   v r2| j                   |   j                  r| j                   |   j                  }||k(  r|dz  }|S )Nr   )rs   r   )r   r&   r   mapped_depends_ons       r#   r   z$Http2Layer._map_depends_on_stream_id?  sZ    &,>O1P1a1a !%-> ? P P)) "  r$   c                 `   t        j                          dz
  }t        | j                  j                               D cg c]  \  }}|j                  s||f }}}|D cg c]  \  }}|j                  |k  s| }}}|D ]  }| j                  j                  |d          y c c}}w c c}}w )N
   )rD   listrs   r   zombiepop)r   
death_timer&   streamzombie_streamsoutdated_streamss         r#   _cleanup_streamszHttp2Layer._cleanup_streamsK  s    YY[2%
GKDLLL^L^L`Gas2C)Vekerer9f-ss?Mm*;)VQWQ^Q^blQlImm) 	.ILLY-	. tms   B$B$!B*9B*c                 b    | j                   j                         D ]  }|j                           y r   )rs   valuesr   )r   r   s     r#   r   zHttp2Layer._kill_all_streamsT  s'    ll))+ 	FKKM	r$   c           	      >   | j                          | j                          | j                  j                         D cg c]  }|j                   }}	 	 t        j                  |d      }|D ]  }|| j                  j                  k(  r| j                  n| j                  }|| j                  j                  k(  r| j                  n| j                  }|| j                  k(  }| j                  |   j                  5  	 dj                  t        j                  |j                              }| j                  |   j                  j                   t"        j                  j$                  j&                  k(  r| j)                  dd       	 d d d         y | j                  |   j+                  |      }	|j-                  | j                  |   j/                                |	D ]1  }
| j1                  |
|||      r| j                           d d d         y  	 d d d        | j3                           c c}w #  | j                          Y d d d         y xY w# 1 sw Y   CxY w# t4        $ r5}| j)                  t7        |      d       | j                          Y d }~y d }~ww xY w)Nr>   r$   z.HTTP/2 connection entered closed state alreadyr^   r   )r}   r   r
   keysr   r   ssl_read_selectrv   rz   r   joinr   read_raw_framer   r   state_machinestater0   ConnectionStateCLOSEDr\   r   r*   r+   r   r   rG   r   )r   cconnsrr   r   r   r   	raw_frameincoming_eventsr   rL   s               r#   __call__zHttp2Layer.__call__X  sM   ""$  "'+'7'7'<'<'>?!?? 	%''s3 ,D6:d>N>N>Y>Y6Y$"2"2_c_o_oK59T=M=M=X=X5X!1!1^b^n^nJ!,0@0@!@I))+6;; '#(+1E1EkFWFW1X(YI  ++K8FFLLPRP]P]PmPmPtPtt HH%UW^_"' ' +/*:*:;*G*T*TU^*_#(()9)9+)F)S)S)UV%4 'E#'#5#5e[*V_#` $ 6 6 8 &'' '''* ))+5,  @# 224"' ' ' ',  	%HHT!Wf%""$$	%sz   H-B'I :I<.H2*AI	I A#I3I	I II 2II	I II	I 	J'+JJ)rN   rO   rP   rv   r
   ClientConnection__annotations__re   strr   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  rT   rU   s   @r#   rW   rW   S   s    
 
_# _$ _
QQ$
$L(
	

.*>
!.&%r$   rW   c                 B     t        j                          fd       }|S )Nc                 `    | j                           | g|i |}| j                          |S r   )r7   )r   r    r!   resultfuncs       r#   wrapperz%detect_zombie_stream.<locals>.wrapper  s4    d,T,V,r$   )	functoolswraps)r  r  s   ` r#   detect_zombie_streamr    s%    __T  Nr$   c                   4    e Zd Z G d d      Zdedej                  j                  j                  j                  j                  ddf fdZd Zd	 Zd
 Zd Zd Zed        Zed        Zej(                  d        Zed        Zed        Zej(                  d        Zd$dZed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Z ed        Z!ed        Z"ed        Z#ed        Z$ed         Z%d! Z&d" Z'd# Z( xZ)S )%r   c                       e Zd ZddZy)Http2SingleStreamLayer.MessageNc                     || _         t        j                         | _        d| _        d | _        t        j                         | _        t        j                         | _	        y r(   )
r   queueQueuer   r   r   r   Eventr   r   )r   r   s     r#   r   z'Http2SingleStreamLayer.Message.__init__  sB    Y`DL27++-DO&'D#Z^DM$??,DL ) 1Dr$   r   )rN   rO   rP   r   rc   r$   r#   Messager    s    	2r$   r!  r&   request_headersrg   Nc                 ,   t         |   |dj                  |             || _        d | _        || _        d | _        d| _        d | _        d | _	        | j                  |      | _        | j                         | _        |  d | _        d | _        d | _        y )NzHttp2SingleStreamLayer-{})r[   F)r   r   r_   h2_connectionr   r   r   r   r   r   r!  r   r   r   r   r   )r   rw   r$  r&   r"  r"   s        r#   r   zHttp2SingleStreamLayer.__init__  s    188C 	 	
 +'+%./304.2#||O< $26 .2+/#r$   c                 p   | j                   st        j                         | _         | j                  j                  j	                          | j                  j
                  j	                          | j                  j
                  j	                          | j                  j                  j	                          y y r   )r   rD   r   r   r   r   r   r   s    r#   r   zHttp2SingleStreamLayer.kill  s{    {{))+DK  --113  ((,,.!!))--/!!..224 r$   c                 ,    t        j                  d      )Nz-HTTP2 layer should already have a connection.r   Http2ProtocolExceptionr   s    r#   connectzHttp2SingleStreamLayer.connect  s    //0_``r$   c                 ,    t        j                  d      )Nz.Cannot dis- or reconnect in HTTP2 connections.r'  r   s    r#   
disconnectz!Http2SingleStreamLayer.disconnect  s    //0`aar$   c                 >    t        j                  t        |            r   )r   SetServerNotAllowedExceptionr   )r   addresss     r#   
set_serverz!Http2SingleStreamLayer.set_server  s    55d7mDDr$   c                      yr   rc   )r   r   s     r#   check_close_connectionz-Http2SingleStreamLayer.check_close_connection  s     r$   c                     | j                   j                  j                         r| j                   j                  S | j                  j                  S r   )r   r   is_setr   r   r   s    r#   r   z!Http2SingleStreamLayer.data_queue  s>      ((//1((333''222r$   c                     | j                   j                  j                         r| j                   j                  S | j                  j                  S r   )r   r   r3  r   r   r   s    r#   r   z)Http2SingleStreamLayer.queued_data_length  s>      ((//1((;;;'':::r$   c                 &    || j                   _        y r   )r   r   r   r   s     r#   r   z)Http2SingleStreamLayer.queued_data_length  s    23/r$   c                     | j                   j                  j                         r| j                   j                  S | j                  j                  S r   )r   r   r3  r   r   r   s    r#   r   z#Http2SingleStreamLayer.stream_ended  s@       ((//1((555''444r$   c                     | j                   j                  j                         r| j                   j                  S | j                  j                  S r   r   r   r3  r   r   r   s    r#   r   zHttp2SingleStreamLayer.trailers  s>      ((//1((111''000r$   c                     | j                   j                  j                         r|| j                   _        y || j                  _        y r   r9  r6  s     r#   r   zHttp2SingleStreamLayer.trailers  s6      ((//1-.D!!*,-D  )r$   c                    | j                   j                  j                  t        j                  j
                  j                  k(  }| j                  |r8| |        t        j                  dj                  | j                  |            y )Nz)Connection or stream already dead: {}, {})r$  r  r  r0   r   r  r  r   r   Http2ZombieExceptionr_   )r   pre_commandconnection_closeds      r#   r7   z#Http2SingleStreamLayer.raise_zombie  s     ..<<BBbmmFcFcFjFjj;;"&7&112]2d2deiepep  sD  3E  F  F '8r$   c                 8   | j                   j                  j                          | j                          | j                  rd|j
                  d<   | j                   j                  j                  dd      }| j                   j                  j                  d      }| j                   j                  j                  d      }| j                   j                  j                  d      }t        j                  |d      \  }}|xs t        j                  |      xs d	}t        j                  |||j                         |j                         |j                         |j                         d
| j                   j                  d d | j                  | j                        S )NTzh2-pushed-stream
:authority :method:scheme:path)checkr      HTTP/2.0)r   r   waitr7   r   metadatar   r   r   parse_authoritydefault_portr   HTTPRequestencoder   r   )r   r   	authoritymethodschemepathhostports           r#   read_request_headersz+Http2SingleStreamLayer.read_request_headers  sJ   $$))+;;04DMM,- ((0044\2F	%%--11)<%%--11)<##++//8(($?
d4s''/41MMOMMOKKM  ((  
 	
r$   c              #   f  K   |j                   s$| j                  j                  j                          	 	 | j                  j                  j                  d       | j                  j                  j                         r| j                          | j                  j                  j                         dkD  rN| j                  j                  j                          | j                  j                  j                         dkD  rNy | j                          # t        j                  $ r Y w xY wwNr>   )timeoutr   )r   r   r   rG  r   getr  Emptyr3  r7   qsizer   requests     r#   read_request_bodyz(Http2SingleStreamLayer.read_request_body  s     ~~  --224**5599#9FF ##00779!!#**55;;=A..99==?? **55;;=A  ;; s/   2D1(D B(D1D1D.+D1-D..D1c                 .    | j                   j                  S r   )r   r   rZ  s     r#   read_request_trailersz,Http2SingleStreamLayer.read_request_trailers$  s    ##,,,r$   c           	         | j                   ry 	 | j                          | j                  | j                     j                  j                          | j                  | j                     j                  j                  }| j                  | j                     j                  dz   |k\  rG| j                  | j                     j                  j                          t        j                  d       	 | j                          | j                  | j                     j                         | _        | j                  | j                  | j                  <   |j                   j#                         }|j$                  r |j&                  dd|j$                          |j&                  dd|j(                          |j&                  dd|j*                          |j&                  dd|j,                         d }d }d }| j.                  rq| j0                  j2                  j4                  s| j7                  d	d
       n>| j8                  }| j;                  | j                  | j<                        }| j>                  }	 | j                  | j                     jA                  | j                  | j                  ||jB                  s|jD                  s|jF                  rdnd|||       	 | j                          | j                  | j                     j                  j                          y # tH        $ r}|d }~ww xY w# | j                          | j                  | j                     j                  j                          w xY w)NTr   r>   r   r@  rD  rB  rC  zcHTTP/2 PRIORITY information in HEADERS frame suppressed. Use --http2-priority to enable forwarding.r^   F)rH   r   r   r   )%r   r7   r
   rz   r   r@   remote_settingsmax_concurrent_streamsopen_outbound_streamsrA   rD   rE   get_next_available_stream_idr   r   rt   r   copyrM  insertrP  rN  rO  r   rq   r   r   r\   r   r   r   r   r;   contentr   r   rG   )r   r[  max_streamsr   r   r   r   rL   s           r#   send_request_headersz+Http2SingleStreamLayer.send_request_headers(  s   ;;T--.33;;=**4+;+;<LLccK 0 01GG!K{Z  !1!1277??A

3  	 $ 0 01A1A B _ _ aBFBWBW(()>)>?//&&(GNN1lG,=,=>q'7<<0q)W^^4q)W^^4!"&& ;;&&55~  AH  I%)%<%<"&*&D&DTEZEZ\`\t\t&u#"&"6"6	>T--.@@!!%%%,__8H8HGNNE`d#5$7 / A  T--.33;;=	  	G	 T--.33;;=s&   /A)L 	L+$L&&L++L. .AM1c                     | j                   ry t        |t        j                        s|rS|d   rM| j                  | j
                     j                  | j                  | j                  ||j                  d u        y y y )Nr   rH   )
r   r   typesGeneratorTyper
   rz   rM   r7   r   r   )r   r[  r<   s      r#   send_request_bodyz(Http2SingleStreamLayer.send_request_bodyf  st    ;;fe112v&)T--.==!!%%#,,4	 >  CLvr$   c                 P    | j                  | j                  |j                         y r   )_send_trailersrz   r   rZ  s     r#   send_request_trailersz,Http2SingleStreamLayer.send_request_trailerst  s    D,,g.>.>?r$   c                     | j                  |       | j                  ||j                  g       | j                  |       y r   )rh  rm  rf  rp  rZ  s     r#   send_requestz#Http2SingleStreamLayer.send_requestx  s5    !!'*w(9:""7+r$   c           
         | j                   j                  j                          | j                          t	        | j                   j
                  j                  dd            }| j                   j
                  j                         } |j                  dd        t        j                  d|d|d d | j                  | j                        S )N:statusi  rF  r$   )http_versionstatus_codereasonr   rf  r   r   r   )r   r   rG  r7   rQ   r   rW  rd  r   r   HTTPResponser   r   )r   rv  r   s      r#   read_response_headersz,Http2SingleStreamLayer.read_response_headers~  s    %%**,$//77;;IsKL''//446It$  $# 00,,	
 		
r$   c              #     K   	 	 | j                   j                  j                  d       | j                   j
                  j                         r| j                          | j                   j                  j                         dkD  rN| j                   j                  j                          | j                   j                  j                         dkD  rNy | j                          # t        j                  $ r Y w xY wwrU  )	r   r   rW  r  rX  r   r3  r7   rY  r   r[  responses      r#   read_response_bodyz)Http2SingleStreamLayer.read_response_body  s     ++66::3:GG $$1188:!!#++66<<>B//::>>@@ ++66<<>B  ;; s.   D(C( B(DD(C>;D=C>>Dc                 .    | j                   j                  S r   )r   r   r{  s      r#   read_response_trailersz-Http2SingleStreamLayer.read_response_trailers  s    $$---r$   c                 r   |j                   j                         } |j                  ddt        |j                               | j
                  | j                     j                  5  | j
                  | j                     j                  | j                  | j                  |       d d d        y # 1 sw Y   y xY w)Nr   rt  )r   rd  re  r  rv  r
   rv   r   r;   r7   r   )r   r|  r   s      r#   send_response_headersz,Http2SingleStreamLayer.send_response_headers  s    ""'')q)S)=)=%>?d../44 	T--.@@!!%%	 	 	s   %?B--B6c                     | j                   | j                     j                  | j                  | j                  ||j
                  d u        y )Nrj  )r
   rv   rM   r7   r   r   )r   r|  r<   s      r#   send_response_bodyz)Http2SingleStreamLayer.send_response_body  sI    ))*99!! ))T1	 	: 	
r$   c                 P    | j                  | j                  |j                         y r   )ro  rv   r   )r   r|  s     r#   send_response_trailersz-Http2SingleStreamLayer.send_response_trailers  s    D,,h.?.?@r$   c                     |sy | j                   |   j                  5  | j                   |   j                  | j                  | j                  |d       d d d        y # 1 sw Y   y xY w)NTrj  )r
   r   r;   r7   r   )r   r   r   s      r#   ro  z%Http2SingleStreamLayer._send_trailers  sg    d#(( 	T"44!!%%	 5 	 	 	s   7AA&c                     t        d      )Nz,Http2SingleStreamLayer must be run as thread)EnvironmentErrorr   s    r#   r  zHttp2SingleStreamLayer.__call__  s    MNNr$   c                    t        j                  | | j                        }	  |        | j                          y # t        j                  $ r Y y t        j
                  $ r%}| j                  t        |      d       Y d }~Xd }~wt        j                  $ r+}| j                  dj                  |      d       Y d }~d }~wt        j                  $ r- | j                  t        j                  j                  d       Y w xY w)Nr   z?Changing the Host server for HTTP/2 connections not allowed: {})httpbase	HttpLayerrf   r   r<  ProtocolExceptionr\   r   r-  r_   Killr   ErrorKILLED_MESSAGEr   )r   r   rL   s      r#   runzHttp2SingleStreamLayer.run  s    ""43
	8G 			 .. 	++ 	&HHT!Wf%%66 	jHHV]]^_`bhii 	8HHTZZ..7	8s.   : D D !BD !B==A D ?D r   )*rN   rO   rP   r!  rQ   r   r   r   r   r   rR   r   r   r)  r+  r/  r1  propertyr   r   setterr   r   r7   r  rS  r\  r^  rh  rm  rp  rr  ry  r}  r  r  r  r  ro  r  r  rT   rU   s   @r#   r   r     s   2 20c 0LLcLcLmLmLqLqLvLvL~L~ 0  DH 0*5abE
 3 3 ; ; 4 4 5 5 1 1 __. .F 
 
>      - - ;> ;>z   @ @ , ,
 
 
(     . .   
 
 A A	Or$   r   )*r  r  r   rD   rk  typingr   r   r   r   r   h2.exceptionsr0   r   r	   *seleniumwire.thirdparty.mitmproxy.net.httpr   !seleniumwire.thirdparty.mitmproxyr
   r   r   r   +seleniumwire.thirdparty.mitmproxy.coretypesr   %seleniumwire.thirdparty.mitmproxy.netr   r   r   r   1seleniumwire.thirdparty.mitmproxy.server.protocolr  r   'seleniumwire.thirdparty.mitmproxy.utilsr   H2Connectionr   LayerrW   r  _HttpTransmissionLayer
BaseThreadr   rc   r$   r#   <module>r     s         6 6  ! 1 K K 2 B 5 J J T 9;4z.. ;4|k% k%\	NX<<j>S>S Nr$   