a hU@snddlZddlZddlZddlZddlmZmZddlm Z m Z m Z m Z m Z mZeeZGdddeZdS)N) AsyncChannel ChannelError) JsonObjectget_dictget_int get_objectget_str typecheckedc@seZdZdZeejjee dddZ ee ejj dddZ eejj dd d d d Z eejj eed eejjdddZe d dddZd S) HttpChannelz http-stream2)responsebinaryreturncs0ddh|sddhfdd|DS)NZ ConnectionzTransfer-EncodingzContent-LengthZRangecsi|]\}}|vr||qSr).0keyvalueremoverA/usr/lib/python3.9/site-packages/cockpit/channels/http_channel.py )z+HttpChannel.get_headers..)updateZ getheaders)r r rrr get_headers szHttpChannel.get_headers)optionsrcCs*t|dd}t|dd}t|dd}t|dd}|durL|durLtddd|durh|durhtdd d|dur|durtdd d|durt|d d}|durt|d d}|durtj|d }qtjt|dd}nt}d|vr|dsd|_tjj|_ t j j |||dSt j j ||dSdS)NaddressZ localhostZtlsunixportprotocol-errorz#TLS on Unix socket is not supportedmessagez&no "port" or "unix" option for channelz-cannot specify both "port" and "unix" options authoritydata)Zcadatafile)ZcafileZvalidateF)rcontext)r)r rrrsslZcreate_default_contextZcheck_hostnameZ VerifyModeZ CERT_NONEZ verify_modehttpclientZHTTPSConnectionHTTPConnection)rZ opt_addressZopt_tlsopt_unixZopt_portr!r"r$rrr create_client+s.           zHttpChannel.create_clientz str | NoneN) connectionr)rcCs,|r ttj|_|j|n|dS)N)socketZAF_UNIXZsockconnect)r+r)rrrr-MszHttpChannel.connectzdict[str, str])r+methodpathheadersbodyrcCs|j|||pi|d|S)N)r0r1)requestZ getresponse)r+r.r/r0r1rrrr2XszHttpChannel.requestc sVtd|t|d}t|d}t|dddd}d|vrFtdd d ||}|d }|IdH}|durtq~||7}q\z"||j |t|d dIdHWnrt j y}ztd t |d |WYd}~nDd}~0t tfy}ztdt |d |WYd}~n d}~00z&||j||||p,i|IdH} Wn@tjjt fyz}ztdt |d |WYd}~n d}~00|jd| j| j|j| |jddzj|| j|jIdH} | sq|| IdHqtd| } | d ksJ||jIdHWn@tjjt fyH}ztdt |d |WYd}~n d}~00|dS)Nzopen %sr.r/r0cSsdd|DS)NcSsi|]\}}|t|tqSr)r str)rkvrrrrerz5HttpChannel.run....)items)drrrerz!HttpChannel.run..r+rz4connection sharing is not implemented on this bridgerrrzunknown-hostkeyz not-foundZ terminatedr )r )Zcommandstatusreasonr0zreading response done)loggerdebugr rrr*ZreadyreadZ in_threadr-r%ZSSLCertVerificationErrorr3OSErrorIOErrorr2r&r'Z HTTPExceptionZ send_controlr9r:rZ is_binaryread1Z BLOCK_SIZEwritecloseZdone) selfrr.r/r0r+r1r"excr blockrrrrun`sP      "&(&( (zHttpChannel.run)__name__ __module__ __qualname__Zpayload staticmethodr&r'Z HTTPResponseboolrrr(r*r-r3bytesr2rFrrrrr s ! r )Z http.clientr&Zloggingr,r%ZchannelrrZjsonutilrrrrr r Z getLoggerrGr;r rrrrs