コード例 #1
0
ファイル: flow.py プロジェクト: tinius/mitmproxy
 def add(self, app, domain, port):
     """
         Add a WSGI app to the registry, to be served for requests to the
         specified domain, on the specified port.
     """
     self.apps[(domain, port)] = wsgi.WSGIAdaptor(app, domain, port,
                                                  version.NAMEVERSION)
コード例 #2
0
    def test_make_environ(self):
        w = wsgi.WSGIAdaptor(None, "foo", 80, "version")
        tf = tflow()
        assert w.make_environ(tf, None)

        tf.request.path = "/foo?bar=voing"
        r = w.make_environ(tf, None)
        assert r["QUERY_STRING"] == "bar=voing"
コード例 #3
0
 def _serve(self, app):
     w = wsgi.WSGIAdaptor(app, "foo", 80, "version")
     f = tflow()
     f.request.host = "foo"
     f.request.port = 80
     wfile = cStringIO.StringIO()
     err = w.serve(f, wfile)
     return wfile.getvalue()
コード例 #4
0
 def _serve(self, app):
     w = wsgi.WSGIAdaptor(app, "foo", 80, "version")
     r = treq()
     r.host = "foo"
     r.port = 80
     wfile = cStringIO.StringIO()
     err = w.serve(r, wfile)
     return wfile.getvalue()
コード例 #5
0
 def serve(self, app, flow):
     """
         Serves app on flow, and prevents further handling of the flow.
     """
     app = wsgi.WSGIAdaptor(app, flow.request.pretty_host,
                            flow.request.port, version.MITMPROXY)
     err = app.serve(flow, flow.client_conn.wfile,
                     **{"mitmproxy.master": ctx.master})
     if err:
         ctx.log.warn("Error in wsgi app. %s" % err, "error")
     flow.reply.kill()
     raise exceptions.AddonHalt()
コード例 #6
0
    def test_serve(self):
        ta = TestApp()
        w = wsgi.WSGIAdaptor(ta, "foo", 80, "version")
        f = tflow()
        f.request.host = "foo"
        f.request.port = 80

        wfile = cStringIO.StringIO()
        err = w.serve(f, wfile)
        assert ta.called
        assert not err

        val = wfile.getvalue()
        assert "Hello world" in val
        assert "Server:" in val
コード例 #7
0
ファイル: http.py プロジェクト: firebitsbr/bdfproxy-1
 def handle_http_app(self, method, path, headers, body, lg):
     """
         Handle a request to the built-in app.
     """
     if self.pathod_handler.server.noweb:
         crafted = self.pathod_handler.make_http_error_response(
             "Access Denied")
         language.serve(crafted, self.pathod_handler.wfile,
                        self.pathod_handler.settings)
         return None, dict(type="error",
                           msg="Access denied: web interface disabled")
     lg("app: %s %s" % (method, path))
     req = wsgi.Request("http", method, path, b"HTTP/1.1", headers, body)
     flow = wsgi.Flow(self.pathod_handler.address, req)
     sn = self.pathod_handler.connection.getsockname()
     a = wsgi.WSGIAdaptor(self.pathod_handler.server.app, sn[0],
                          self.pathod_handler.server.address.port,
                          version.NAMEVERSION)
     a.serve(flow, self.pathod_handler.wfile)
     return self.pathod_handler.handle_http_request, None
コード例 #8
0
                crafted = language.make_error_response(
                    "Parse Error",
                    "Error parsing response spec: %s\n" % v.msg + v.marked())
            again, retlog["response"] = self.serve_crafted(crafted)
            return again, retlog
        elif self.server.noweb:
            crafted = language.make_error_response("Access Denied")
            language.serve(crafted, self.wfile, self.server.request_settings)
            return False, dict(type="error",
                               msg="Access denied: web interface disabled")
        else:
            self.info("app: %s %s" % (method, path))
            req = wsgi.Request("http", method, path, headers, content)
            flow = wsgi.Flow(self.address, req)
            sn = self.connection.getsockname()
            a = wsgi.WSGIAdaptor(self.server.app, sn[0],
                                 self.server.address.port, version.NAMEVERSION)
            a.serve(flow, self.wfile)
            return True, None

    def _log_bytes(self, header, data, hexdump):
        s = []
        if hexdump:
            s.append("%s (hex dump):" % header)
            for line in netlib.utils.hexdump(data):
                s.append("\t%s %s %s" % line)
        else:
            s.append("%s (unprintables escaped):" % header)
            s.append(netlib.utils.cleanBin(data))
        self.info("\n".join(s))

    def handle(self):