Exemplo n.º 1
0
 def request(self, flow: HTTPFlow):
     if flow.request.host == 'dummy-upstream':
         flow.error = Error('No upstream is configured.')
         flow.response = make_error_response(
             400,
             'No upstream is configured.',
         )
Exemplo n.º 2
0
    def replay_request(
            self,
            f: http.HTTPFlow,
            block: bool=False
    ) -> http_replay.RequestReplayThread:
        """
        Replay a HTTP request to receive a new response from the server.

        Args:
            f: The flow to replay.
            block: If True, this function will wait for the replay to finish.
                This causes a deadlock if activated in the main thread.

        Returns:
            The thread object doing the replay.

        Raises:
            exceptions.ReplayException, if the flow is in a state
            where it is ineligible for replay.
        """

        if f.live:
            raise exceptions.ReplayException(
                "Can't replay live flow."
            )
        if f.intercepted:
            raise exceptions.ReplayException(
                "Can't replay intercepted flow."
            )
        if not f.request:
            raise exceptions.ReplayException(
                "Can't replay flow with missing request."
            )
        if f.request.raw_content is None:
            raise exceptions.ReplayException(
                "Can't replay flow with missing content."
            )

        f.backup()
        f.request.is_replay = True

        f.response = None
        f.error = None

        if f.request.http_version == "HTTP/2.0":  # https://github.com/mitmproxy/mitmproxy/issues/2197
            f.request.http_version = "HTTP/1.1"
            host = f.request.headers.pop(":authority")
            f.request.headers.insert(0, "host", host)

        rt = http_replay.RequestReplayThread(
            self.options,
            f,
            self.event_queue,
            self.should_exit
        )
        rt.start()  # pragma: no cover
        if block:
            rt.join()
        return rt
Exemplo n.º 3
0
    def replay_request(
            self,
            f: http.HTTPFlow,
            block: bool=False
    ) -> http_replay.RequestReplayThread:
        """
        Replay a HTTP request to receive a new response from the server.

        Args:
            f: The flow to replay.
            block: If True, this function will wait for the replay to finish.
                This causes a deadlock if activated in the main thread.

        Returns:
            The thread object doing the replay.

        Raises:
            exceptions.ReplayException, if the flow is in a state
            where it is ineligible for replay.
        """

        if f.live:
            raise exceptions.ReplayException(
                "Can't replay live flow."
            )
        if f.intercepted:
            raise exceptions.ReplayException(
                "Can't replay intercepted flow."
            )
        if not f.request:
            raise exceptions.ReplayException(
                "Can't replay flow with missing request."
            )
        if f.request.raw_content is None:
            raise exceptions.ReplayException(
                "Can't replay flow with missing content."
            )

        f.backup()
        f.request.is_replay = True

        f.response = None
        f.error = None

        if f.request.http_version == "HTTP/2.0":  # https://github.com/mitmproxy/mitmproxy/issues/2197
            f.request.http_version = "HTTP/1.1"
            host = f.request.headers.pop(":authority")
            f.request.headers.insert(0, "host", host)

        rt = http_replay.RequestReplayThread(
            self.options,
            f,
            self.event_queue,
            self.should_exit
        )
        rt.start()  # pragma: no cover
        if block:
            rt.join()
        return rt
Exemplo n.º 4
0
 def request(self, flow: HTTPFlow):
     # Remove "vgs-client" header, that is sent by VGS-Collect.
     # This copies logic from proxy
     flow.request.headers.pop('vgs-client', None)
     if flow.request.host == 'dummy-upstream':
         flow.error = Error('No upstream is configured.')
         flow.response = make_error_response(
             400,
             'No upstream is configured.',
         )
Exemplo n.º 5
0
    def request(self, flow: http.HTTPFlow):
        if "mitm.it" in flow.request.url:
            return

        data = flow.request.data.content.decode("UTF-8")
        if not len(data):
            data = None
        req = Request(flow.request.method, flow.request.url,
                      dict(flow.request.headers), data)
        resp = submit_request(req)

        if resp:
            flow.response = http.HTTPResponse.make(
                resp["status"], resp["body"].encode("UTF-8"), resp["headers"])

        else:
            flow.error = Error("Gameserver did not send response")
            flow.response = http.HTTPResponse.make(
                400, b"The gameserver returned no response for this request.",
                {})
Exemplo n.º 6
0
 def kill(flow: HTTPFlow):
     # Can't use flow.kill() here because that currently still depends on a reply object.
     flow.error = Error(Error.KILLED_MESSAGE)