MCPcopy Create free account
hub / github.com/sqlmapproject/sqlmap / _reuse_connection

Method _reuse_connection

thirdparty/keepalive/keepalive.py:272–313  ·  view source on GitHub ↗

start the transaction with a re-used connection return a response object (r) upon success or None on failure. This DOES not close or remove bad connections in cases where it returns. However, if an unexpected exception occurs, it will close and remove the connection

(self, h, req, host)

Source from the content-addressed store, hash-verified

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
274 return a response object (r) upon success or None on failure.
275 This DOES not close or remove bad connections in cases where
276 it returns. However, if an unexpected exception occurs, it
277 will close and remove the connection before re-raising.
278 """
279 try:
280 self._start_transaction(h, req)
281 r = h.getresponse()
282 # note: just because we got something back doesn't mean it
283 # worked. We'll check the version below, too.
284 except (socket.error, _http_client.HTTPException):
285 r = None
286 except:
287 # adding this block just in case we've missed
288 # something we will still raise the exception, but
289 # lets try and close the connection and remove it
290 # first. We previously got into a nasty loop
291 # where an exception was uncaught, and so the
292 # connection stayed open. On the next try, the
293 # same exception was raised, etc. The tradeoff is
294 # that it's now possible this call will raise
295 # a DIFFERENT exception
296 if DEBUG: DEBUG.error("unexpected exception - closing " + \
297 "connection to %s (%d)", host, id(h))
298 self._cm.remove(h)
299 h.close()
300 raise
301
302 if r is None or r.version == 9:
303 # httplib falls back to assuming HTTP 0.9 if it gets a
304 # bad header back. This is most likely to happen if
305 # the socket has been closed by the server since we
306 # last used the connection.
307 if DEBUG: DEBUG.info("failed to re-use connection to %s (%d)",
308 host, id(h))
309 r = None
310 else:
311 if DEBUG: DEBUG.info("re-using connection to %s (%d)", host, id(h))
312
313 return r
314
315 def _start_transaction(self, h, req):
316 try:

Callers 1

do_openMethod · 0.95

Calls 5

_start_transactionMethod · 0.95
removeMethod · 0.80
infoMethod · 0.80
errorMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected