def send(self, arg1, arg2, arg3, headers=None, traceflag=None, retry_limit=None, ttl=None): arg1, arg2, arg3 = map(maybe_stream, [arg1, arg2, arg3]) endpoint = yield read_full(arg1) headers = headers or {} headers.setdefault('as', self.arg_scheme) vcr_request = proxy.Request( serviceName=self.service.encode('utf-8'), hostPort=self.hostport, knownPeers=self.original_tchannel.peers.hosts, endpoint=endpoint, headers=(yield read_full(arg2)), body=(yield read_full(arg3)), argScheme=getattr(proxy.ArgScheme, self.arg_scheme.upper()), transportHeaders=[ proxy.TransportHeader(bytes(k), bytes(v)) for k, v in headers.items() ], ) # TODO what to do with traceflag, attempt-times, ttl # TODO catch protocol errors from tchannel import TChannel tchannel = TChannel('proxy-client') with force_reset(): vcr_response_future = tchannel.thrift( proxy.VCRProxy.send(vcr_request), hostport=self.vcr_hostport, ) try: vcr_response = yield vcr_response_future except proxy.RemoteServiceError as e: raise TChannelError.from_code( e.code, description=("The remote service threw a protocol error: %s" % e.message)) response = Response( code=vcr_response.body.code, argstreams=[ maybe_stream(endpoint), maybe_stream(vcr_response.body.headers), maybe_stream(vcr_response.body.body), ], # TODO headers=vcr_response.transportHeaders, ) raise gen.Return(response)
def send(self, arg1, arg2, arg3, headers=None, traceflag=None, retry_limit=None, ttl=None): arg1, arg2, arg3 = map(maybe_stream, [arg1, arg2, arg3]) endpoint = yield read_full(arg1) headers = headers or {} headers.setdefault('as', self.arg_scheme) vcr_request = proxy.Request( serviceName=self.service.encode('utf-8'), hostPort=self.hostport, knownPeers=self.original_tchannel.peers.hosts, endpoint=endpoint, headers=(yield read_full(arg2)), body=(yield read_full(arg3)), argScheme=getattr(proxy.ArgScheme, self.arg_scheme.upper()), transportHeaders=[ proxy.TransportHeader(bytes(k), bytes(v)) for k, v in headers.items() ], ) # TODO what to do with traceflag, attempt-times, ttl # TODO catch protocol errors from tchannel import TChannel tchannel = TChannel('proxy-client') with force_reset(): vcr_response_future = tchannel.thrift( proxy.VCRProxy.send(vcr_request), hostport=self.vcr_hostport, ) try: vcr_response = yield vcr_response_future except proxy.RemoteServiceError as e: raise TChannelError.from_code( e.code, description=( "The remote service threw a protocol error: %s" % e.message ) ) response = Response( code=vcr_response.body.code, argstreams=[ maybe_stream(endpoint), maybe_stream(vcr_response.body.headers), maybe_stream(vcr_response.body.body), ], # TODO headers=vcr_response.transportHeaders, ) raise gen.Return(response)
def send(self, arg1, arg2, arg3, headers=None, ttl=None, **kwargs): arg1, arg2, arg3 = list(map(maybe_stream, [arg1, arg2, arg3])) endpoint = yield read_full(arg1) headers = headers or {} headers.setdefault('as', self.arg_scheme) vcr_request = proxy.Request( serviceName=self.service.encode('utf-8'), hostPort=self.hostport, knownPeers=self.original_tchannel.peers.hosts, endpoint=endpoint, headers=(yield read_full(arg2)), body=(yield read_full(arg3)), argScheme=getattr(proxy.ArgScheme, self.arg_scheme.upper()), transportHeaders=[ proxy.TransportHeader(bytes(k.encode('utf8')), bytes(v.encode('utf8'))) for k, v in headers.items() ], ) # TODO what to do with traceflag, attempt-times, ttl # TODO catch protocol errors from tchannel import TChannel tchannel = TChannel('proxy-client') with force_reset(): vcr_response_future = tchannel.thrift( proxy.VCRProxy.send(vcr_request), hostport=self.vcr_hostport, timeout=float(ttl) * 1.1 if ttl else ttl, # If a timeout was specified, use that plus 10% to give some # leeway to the VCR proxy request itself. ) try: vcr_response = yield vcr_response_future except proxy.RemoteServiceError as e: raise TChannelError.from_code( e.code, description=("The remote service threw a protocol error: %s" % (e, ))) response = Response( code=vcr_response.body.code, argstreams=[ maybe_stream(endpoint), maybe_stream(vcr_response.body.headers), maybe_stream(vcr_response.body.body), ], # TODO headers=vcr_response.transportHeaders, ) raise gen.Return(response)
def send(self, arg1, arg2, arg3, headers=None, traceflag=None, retry_limit=None, ttl=None): arg1, arg2, arg3 = map(maybe_stream, [arg1, arg2, arg3]) endpoint = yield read_full(arg1) headers = headers or {} headers.setdefault('as', self.arg_scheme) vcr_request = VCRProxy.Request( serviceName=self.service.encode('utf-8'), hostPort=self.hostport, endpoint=endpoint, headers=(yield read_full(arg2)), body=(yield read_full(arg3)), argScheme=getattr(VCRProxy.ArgScheme, self.arg_scheme.upper()), transportHeaders=[ VCRProxy.TransportHeader(k, v) for k, v in headers.items() ], ) # TODO what to do with traceflag, attempt-times, ttl # TODO catch protocol errors with force_reset(): vcr_response_future = self.vcr_client.send(vcr_request) try: vcr_response = yield vcr_response_future except VCRProxy.RemoteServiceError as e: raise ProtocolError( code=e.code, description=( "The remote service threw a protocol error: %s" % e.message ) ) response = Response( code=vcr_response.code, argstreams=[ maybe_stream(endpoint), maybe_stream(vcr_response.headers), maybe_stream(vcr_response.body), ], # TODO headers=vcr_response.transportHeaders, ) raise gen.Return(response)
def send(self, arg1, arg2, arg3, headers=None, traceflag=None, retry_limit=None, ttl=None): arg1, arg2, arg3 = map(maybe_stream, [arg1, arg2, arg3]) endpoint = yield read_full(arg1) headers = headers or {} headers.setdefault('as', self.arg_scheme) vcr_request = VCRProxy.Request( serviceName=self.service.encode('utf-8'), hostPort=self.hostport, endpoint=endpoint, headers=(yield read_full(arg2)), body=(yield read_full(arg3)), argScheme=getattr(VCRProxy.ArgScheme, self.arg_scheme.upper()), transportHeaders=[ VCRProxy.TransportHeader(k, v) for k, v in headers.items() ], ) # TODO what to do with traceflag, attempt-times, ttl # TODO catch protocol errors with force_reset(): vcr_response_future = self.vcr_client.send(vcr_request) try: vcr_response = yield vcr_response_future except VCRProxy.RemoteServiceError as e: raise ProtocolError( code=e.code, description=("The remote service threw a protocol error: %s" % e.message)) response = Response( code=vcr_response.code, argstreams=[ maybe_stream(endpoint), maybe_stream(vcr_response.headers), maybe_stream(vcr_response.body), ], # TODO headers=vcr_response.transportHeaders, ) raise gen.Return(response)
def test_maybe_stream(s, expected): got = yield read_full(tpeer.maybe_stream(s)) assert expected == got