예제 #1
0
    def _create_request(self, flow, response=None):
        request = Request(method=flow.request.method,
                          url=flow.request.url,
                          headers=[(k, v)
                                   for k, v in flow.request.headers.items()],
                          body=flow.request.raw_content)
        request.response = response

        return request
예제 #2
0
파일: Methods.py 프로젝트: RazKissos/pweb
    def default_interceptor(request: selenium_request.Request):
        """
        Inner function that acts like a proxy, it removes any requests we don't want.

        @param request: The current request
        @type request: selenium_request.Request
        @return: None
        """
        # Block PNG, JPEG and GIF images.
        if request.path.endswith(('.png', '.jpg', '.gif')):
            request.abort()  # Abort the unwanted request.
예제 #3
0
파일: edmunds.py 프로젝트: qdbp/cars
def interceptor(request: Request) -> None:
    if request.path.endswith((".png", ".jpg", ".gif")):
        request.abort()
        return

    if (
        "edmunds.com" not in request.host
        and "edmunds-media.com" not in request.host
    ):
        request.abort()
        return

    if "activate" in request.path or "certified-program" in request.path:
        request.abort()
        return

    request.headers["User-Agent"] = (
        "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
        "AppleWebKit/537.36 (KHTML, like Gecko) "
        "Chrome/99.0.4844.82 Safari/537.36 Vivaldi/4.3"
    )

    if (ffkey := "fetchSuggestedFacets") in request.params.keys():
        new_params = request.params
        new_params[ffkey] = "false"
        request.params = new_params
예제 #4
0
    def _create_request(self, flow, response=None):
        request = Request(
            method=flow.request.method,
            url=flow.request.url,
            headers=[(k, v) for k, v in flow.request.headers.items()],
            body=flow.request.raw_content
        )

        # For websocket requests, the scheme of the request is overwritten with https
        # in the initial CONNECT request so this hack explicitly sets the scheme back to wss.
        if websockets.check_handshake(request.headers) and websockets.check_client_version(request.headers):
            request.url = request.url.replace('https', 'wss', 1)

        request.response = response

        return request
예제 #5
0
    def _create_request(self, body=None):
        request = Request(
            method='GET',
            url=
            'http://www.example.com/some/path/?foo=bar&hello=world&foo=baz&other=',
            headers=
            [('Accept', '*/*'), ('Host', 'www.example.com'),
             ('User-Agent',
              'Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0'
              )],
            body=body)

        return request
예제 #6
0
    def save_request(self, request: Request) -> None:
        """Save a request to storage.

        Args:
            request: The request to save.
        """
        request.id = str(uuid.uuid4())

        with self._lock:
            if self._maxsize > 0:
                while len(self._requests) >= self._maxsize:
                    self._requests.popitem(last=False)

                self._requests[request.id] = {
                    'request': request,
                }
예제 #7
0
    def save_request(self, request: Request) -> None:
        """Save a request to storage.

        Args:
            request: The request to save.
        """
        request_id = str(uuid.uuid4())
        request_dir = self._get_request_dir(request_id)
        os.mkdir(request_dir)
        request.id = request_id

        self._save(request, request_dir, 'request')

        with self._lock:
            self._index.append(
                _IndexedRequest(id=request_id,
                                url=request.url,
                                has_response=False))
예제 #8
0
 def _create_request(self,
                     url='http://www.example.com/test/path/',
                     body=b''):
     headers = [('Host', 'www.example.com'), ('Accept', '*/*')]
     return Request(method='GET', url=url, headers=headers, body=body)
예제 #9
0
 def _intercept_requests(self, request: Request):
     # Intercept Network Requests - E.g. Block Ads/Malware
     if self.should_block_request(url=request.url):
         request.abort()