MCPcopy Create free account
hub / github.com/apache/thrift / flush

Method flush

lib/py/src/transport/THttpClient.py:145–194  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

143 self.__wbuf.write(buf)
144
145 def flush(self):
146 if self.isOpen():
147 self.close()
148 self.open()
149
150 # Pull data out of buffer
151 data = self.__wbuf.getvalue()
152 self.__wbuf = BytesIO()
153
154 # HTTP request
155 if self.using_proxy() and self.scheme == "http":
156 # need full URL of real host for HTTP proxy here (HTTPS uses CONNECT tunnel)
157 self.__http.putrequest('POST', "http://%s:%s%s" %
158 (self.realhost, self.realport, self.path))
159 else:
160 self.__http.putrequest('POST', self.path)
161
162 # Write headers
163 self.__http.putheader('Content-Type', 'application/x-thrift')
164 self.__http.putheader('Content-Length', str(len(data)))
165 if self.using_proxy() and self.scheme == "http" and self.proxy_auth is not None:
166 self.__http.putheader("Proxy-Authorization", self.proxy_auth)
167
168 if not self.__custom_headers or 'User-Agent' not in self.__custom_headers:
169 user_agent = 'Python/THttpClient'
170 script = os.path.basename(sys.argv[0])
171 if script:
172 user_agent = '%s (%s)' % (user_agent, urllib.parse.quote(script))
173 self.__http.putheader('User-Agent', user_agent)
174
175 if self.__custom_headers:
176 for key, val in self.__custom_headers.items():
177 self.__http.putheader(key, val)
178
179 # Saves the cookie sent by the server in the previous response.
180 # HTTPConnection.putheader can only be called after a request has been
181 # started, and before it's been sent.
182 if self.headers and 'Set-Cookie' in self.headers:
183 self.__http.putheader('Cookie', self.headers['Set-Cookie'])
184
185 self.__http.endheaders()
186
187 # Write payload
188 self.__http.send(data)
189
190 # Get reply to flush the request
191 self.__http_response = self.__http.getresponse()
192 self.code = self.__http_response.status
193 self.message = self.__http_response.reason
194 self.headers = self.__http_response.msg

Callers

nothing calls this directly

Calls 6

isOpenMethod · 0.95
closeMethod · 0.95
openMethod · 0.95
using_proxyMethod · 0.95
getvalueMethod · 0.80
sendMethod · 0.80

Tested by

no test coverage detected