예제 #1
0
 def store(self, flows):
     blobs = []
     for flow in flows:
         blobs.append((protobuf.dumps(flow), ))
     with self._con:
         self._con.executemany('INSERT INTO FLOWS (pbuf_blob) values (?)',
                               blobs)
예제 #2
0
 def store_flows(self, flows):
     body_buf = []
     flow_buf = []
     for flow in flows:
         self.id_ledger.add(flow.id)
         self._disassemble(flow)
         f = copy.copy(flow)
         f.request = copy.deepcopy(flow.request)
         if flow.response:
             f.response = copy.deepcopy(flow.response)
         f.id = flow.id
         if len(f.request.content
                ) > self.content_threshold and f.id not in self.body_ledger:
             body_buf.append((f.id, 1, f.request.content))
             f.request.content = b""
             self.body_ledger.add(f.id)
         if f.response and f.id not in self.body_ledger:
             if len(f.response.content) > self.content_threshold:
                 body_buf.append((f.id, 2, f.response.content))
                 f.response.content = b""
         flow_buf.append((f.id, protobuf.dumps(f)))
     self.con.executemany("INSERT OR REPLACE INTO flow VALUES(?, ?);",
                          flow_buf)
     if body_buf:
         self.con.executemany(
             "INSERT INTO body (flow_id, type_id, content) VALUES(?, ?, ?);",
             body_buf)
     self.con.commit()
예제 #3
0
 def store_flows(self, flows):
     body_buf = []
     flow_buf = []
     for flow in flows:
         self.id_ledger.add(flow.id)
         self._disassemble(flow)
         f = copy.copy(flow)
         f.request = copy.deepcopy(flow.request)
         if flow.response:
             f.response = copy.deepcopy(flow.response)
         f.id = flow.id
         if len(f.request.content) > self.content_threshold and f.id not in self.body_ledger:
             body_buf.append((f.id, 1, f.request.content))
             f.request.content = b""
             self.body_ledger.add(f.id)
         if f.response and f.id not in self.body_ledger:
             if len(f.response.content) > self.content_threshold:
                 body_buf.append((f.id, 2, f.response.content))
                 f.response.content = b""
         flow_buf.append((f.id, protobuf.dumps(f)))
     self.con.executemany("INSERT OR REPLACE INTO flow VALUES(?, ?);", flow_buf)
     if body_buf:
         self.con.executemany("INSERT INTO body (flow_id, type_id, content) VALUES(?, ?, ?);", body_buf)
     self.con.commit()
예제 #4
0
 def test_roundtrip_http_flow_only_req(self):
     f = tflow.tflow()
     f.reply = None
     pf = protobuf.dumps(f)
     lf = protobuf.loads(pf, "http")
     assert f.__dict__ == lf.__dict__
예제 #5
0
 def test_unsupported_dumps(self):
     w = tflow.twebsocketflow()
     with pytest.raises(exceptions.TypeError):
         protobuf.dumps(w)
예제 #6
0
 def test_roundtrip_http_flow_only_req(self):
     f = tflow.tflow()
     f.reply = None
     pf = protobuf.dumps(f)
     lf = protobuf.loads(pf, "http")
     assert f.__dict__ == lf.__dict__
예제 #7
0
 def test_unsupported_dumps(self):
     w = tflow.twebsocketflow()
     with pytest.raises(exceptions.TypeError):
         protobuf.dumps(w)
예제 #8
0
파일: db.py 프로젝트: mitmproxy/mitmproxy
 def store(self, flows):
     blobs = []
     for flow in flows:
         blobs.append((protobuf.dumps(flow),))
     with self._con:
         self._con.executemany('INSERT INTO FLOWS (pbuf_blob) values (?)', blobs)