MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / __negotiatehttp

Method __negotiatehttp

src/socks/__init__.py:360–389  ·  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

358 self.__proxypeername = (destaddr, destport)
359
360 def __negotiatehttp(self, destaddr, destport):
361 """__negotiatehttp(self,destaddr,destport)
362 Negotiates a connection through an HTTP server.
363 """
364 # If we need to resolve locally, we do this now
365 if not self.__proxy[3]:
366 addr = socket.gethostbyname(destaddr)
367 else:
368 addr = destaddr
369 self.sendall(("CONNECT " + addr + ":" + str(destport) + " HTTP/1.1\r\n" + "Host: " + destaddr + "\r\n\r\n").encode())
370 # We read the response until we get the string "\r\n\r\n"
371 resp = self.recv(1)
372 while resp.find("\r\n\r\n".encode()) == -1:
373 resp = resp + self.recv(1)
374 # We just need the first line to check if the connection
375 # was successful
376 statusline = resp.splitlines()[0].split(" ".encode(), 2)
377 if statusline[0] not in ("HTTP/1.0".encode(), "HTTP/1.1".encode()):
378 self.close()
379 raise GeneralProxyError((1, _generalerrors[1]))
380 try:
381 statuscode = int(statusline[1])
382 except ValueError:
383 self.close()
384 raise GeneralProxyError((1, _generalerrors[1]))
385 if statuscode != 200:
386 self.close()
387 raise HTTPError((statuscode, statusline[2]))
388 self.__proxysockname = ("0.0.0.0", 0)
389 self.__proxypeername = (addr, destport)
390
391 def connect(self, destpair):
392 """connect(self, despair)

Callers 1

connectMethod · 0.95

Calls 5

HTTPErrorClass · 0.85
GeneralProxyErrorClass · 0.70
encodeMethod · 0.45
recvMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected