MCPcopy
hub / github.com/USArmyResearchLab/Dshell / http_handler

Method http_handler

dshell/plugins/http/web.py:24–73  ·  view source on GitHub ↗
(self, conn, request, response)

Source from the content-addressed store, hash-verified

22 )
23
24 def http_handler(self, conn, request, response):
25
26 if request:
27 if request.method=="":
28 # It's impossible to have a properly formed HTTP request without a method
29 # indicating, the httpplugin is calling http_handler without a full object
30 return None
31 # Collect basics about the request, if available
32 method = request.method
33 host = request.headers.get("host", "")
34 uri = request.uri
35# useragent = request.headers.get("user-agent", None)
36# referer = request.headers.get("referer", None)
37 version = request.version
38 else:
39 method = "(no request)"
40 host = ""
41 uri = ""
42 version = ""
43
44 if response:
45 if response.status == "" and response.reason == "":
46 # Another indication of improperly parsed HTTP object in httpplugin
47 return None
48 # Collect basics about the response, if available
49 status = response.status
50 reason = response.reason
51 if self.md5:
52 hash = "(md5: {})".format(md5(response.body).hexdigest())
53 else:
54 hash = ""
55 else:
56 status = "(no response)"
57 reason = ""
58 hash = ""
59
60 data = "{} {}{} HTTP/{} {} {} {}".format(method,
61 host,
62 uri,
63 version,
64 status,
65 reason,
66 hash)
67 if not request:
68 self.write(data, method=method, host=host, uri=uri, version=version, status=status, reason=reason, hash=hash, **response.blob.info())
69 elif not response:
70 self.write(data, method=method, uri=uri, version=version, status=status, reason=reason, hash=hash, **request.headers, **request.blob.info())
71 else:
72 self.write(data, method=method, uri=uri, version=version, status=status, reason=reason, hash=hash, request_headers=request.headers, response_headers=response.headers, **request.blob.info())
73 return conn, request, response
74
75if __name__ == "__main__":
76 print(DshellPlugin())

Callers

nothing calls this directly

Calls 2

writeMethod · 0.45
infoMethod · 0.45

Tested by

no test coverage detected