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

Method connection_handler

dshell/plugins/httpplugin.py:208–248  ·  view source on GitHub ↗

Goes through each Blob in a Connection, assuming they appear in pairs of requests and responses, and builds HTTPRequest and HTTPResponse objects. After a response (or only a request at the end of a connection), http_handler is called. If it returns nothing,

(self, conn)

Source from the content-addressed store, hash-verified

206 self.gunzip = kwargs.get("gunzip", False)
207
208 def connection_handler(self, conn):
209 """
210 Goes through each Blob in a Connection, assuming they appear in pairs
211 of requests and responses, and builds HTTPRequest and HTTPResponse
212 objects.
213
214 After a response (or only a request at the end of a connection),
215 http_handler is called. If it returns nothing, the respective blobs
216 are marked as hidden so they won't be passed to additional plugins.
217 """
218 request = None
219 response = None
220 for blob in conn.blobs:
221 # blob.reassemble(allow_overlap=True, allow_padding=True)
222 if not blob.data:
223 continue
224 if blob.direction == 'cs':
225 # client-to-server request
226 request = HTTPRequest(blob)
227 for req_error in request.errors:
228 self.debug("Request Error: {!r}".format(req_error))
229 elif blob.direction == 'sc':
230 # server-to-client response
231 response = HTTPResponse(blob)
232 for rep_error in response.errors:
233 self.debug("Response Error: {!r}".format(rep_error))
234 if self.gunzip:
235 response.decompress_gzip_content()
236 http_handler_out = self.http_handler(conn=conn, request=request, response=response)
237 if not http_handler_out:
238 if request:
239 request.blob.hidden = True
240 if response:
241 response.blob.hidden = True
242 request = None
243 response = None
244 if request and not response:
245 http_handler_out = self.http_handler(conn=conn, request=request, response=None)
246 if not http_handler_out:
247 blob.hidden = True
248 return conn
249
250 def http_handler(self, conn, request, response):
251 """

Callers

nothing calls this directly

Calls 5

http_handlerMethod · 0.95
HTTPRequestClass · 0.85
HTTPResponseClass · 0.85
debugMethod · 0.80

Tested by

no test coverage detected