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

Method __negotiatehttp

thirdparty/socks/socks.py:330–359  ·  view source on GitHub ↗

__negotiatehttp(self,destaddr,destport) Negotiates a connection through an HTTP server.

(self, destaddr, destport)

Source from the content-addressed store, hash-verified

328 self.__proxypeername = (destaddr, destport)
329
330 def __negotiatehttp(self, destaddr, destport):
331 """__negotiatehttp(self,destaddr,destport)
332 Negotiates a connection through an HTTP server.
333 """
334 # If we need to resolve locally, we do this now
335 if not self.__proxy[3]:
336 addr = socket.gethostbyname(destaddr)
337 else:
338 addr = destaddr
339 self.sendall(("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n").encode())
340 # We read the response until we get the string "\r\n\r\n"
341 resp = self.recv(1)
342 while resp.find("\r\n\r\n".encode()) == -1:
343 resp = resp + self.recv(1)
344 # We just need the first line to check if the connection
345 # was successful
346 statusline = resp.splitlines()[0].split(" ".encode(), 2)
347 if statusline[0] not in ("HTTP/1.0".encode(), "HTTP/1.1".encode()):
348 self.close()
349 raise GeneralProxyError((1, _generalerrors[1]))
350 try:
351 statuscode = int(statusline[1])
352 except ValueError:
353 self.close()
354 raise GeneralProxyError((1, _generalerrors[1]))
355 if statuscode != 200:
356 self.close()
357 raise HTTPError((statuscode, statusline[2]))
358 self.__proxysockname = ("0.0.0.0", 0)
359 self.__proxypeername = (addr, destport)
360
361 def connect(self, destpair):
362 """connect(self, despair)

Callers 1

connectMethod · 0.95

Calls 5

GeneralProxyErrorClass · 0.85
recvMethod · 0.80
findMethod · 0.80
HTTPErrorClass · 0.70
closeMethod · 0.45

Tested by

no test coverage detected