MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / do_open

Method do_open

thirdparty/keepalive/keepalive.py:221–270  ·  view source on GitHub ↗
(self, req)

Source from the content-addressed store, hash-verified

219
220 #### Transaction Execution
221 def do_open(self, req):
222 host = req.host
223 if not host:
224 raise _urllib.error.URLError('no host given')
225
226 try:
227 h = self._cm.get_ready_conn(host)
228 while h:
229 r = self._reuse_connection(h, req, host)
230
231 # if this response is non-None, then it worked and we're
232 # done. Break out, skipping the else block.
233 if r: break
234
235 # connection is bad - possibly closed by server
236 # discard it and ask for the next free connection
237 h.close()
238 self._cm.remove(h)
239 h = self._cm.get_ready_conn(host)
240 else:
241 # no (working) free connections were found. Create a new one.
242 h = self._get_connection(host)
243 if DEBUG: DEBUG.info("creating new connection to %s (%d)",
244 host, id(h))
245 self._cm.add(host, h, 0)
246 self._start_transaction(h, req)
247 r = h.getresponse()
248 except (socket.error, _http_client.HTTPException) as err:
249 raise _urllib.error.URLError(err)
250
251 if DEBUG: DEBUG.info("STATUS: %s, %s", r.status, r.reason)
252
253 # if not a persistent connection, don't try to reuse it
254 if r.will_close:
255 if DEBUG: DEBUG.info('server will close connection, discarding')
256 self._cm.remove(h)
257
258 r._handler = self
259 r._host = host
260 r._url = req.get_full_url()
261 r._connection = h
262 r.code = r.status
263 r.headers = r.msg
264 r.msg = r.reason
265
266 if r.status == 200 or not HANDLE_ERRORS:
267 return r
268 else:
269 return self.parent.error('http', req, r,
270 r.status, r.msg, r.headers)
271
272 def _reuse_connection(self, h, req, host):
273 """start the transaction with a re-used connection

Callers 4

http_openMethod · 0.80
https_openMethod · 0.80
https_openMethod · 0.80
https_openMethod · 0.80

Calls 9

_reuse_connectionMethod · 0.95
_get_connectionMethod · 0.95
_start_transactionMethod · 0.95
get_ready_connMethod · 0.80
removeMethod · 0.80
infoMethod · 0.80
closeMethod · 0.45
addMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected