def send_raw_request(self, head, postdata, fix_content_len=True):
        """
        In some cases the ExtendedUrllib user wants to send a request that was
        typed in a textbox or is stored in a file. When something like that
        happens, this library allows the user to send the request by specifying
        two parameters for the send_raw_request method:

        :param head: "<method> <URI> <HTTP version>\r\nHeader: Value\r\nHeader2: Value2..."
        :param postdata: The postdata, if any. If set to '' or None, no postdata is sent.
        :param fix_content_len: Indicates if the content length has to be fixed or not.

        :return: An HTTPResponse object.
        """
        # Parse the two strings
        fuzz_req = HTTPRequestParser(head, postdata)

        # Fix the content length
        if fix_content_len:
            headers = fuzz_req.get_headers()
            fixed = False
            for h in headers:
                if h.lower() == "content-length":
                    headers[h] = str(len(postdata))
                    fixed = True
            if not fixed and postdata:
                headers["content-length"] = str(len(postdata))
            fuzz_req.set_headers(headers)

        # Send it
        function_reference = getattr(self, fuzz_req.get_method())
        return function_reference(
            fuzz_req.get_uri(), data=fuzz_req.get_data(), headers=fuzz_req.get_headers(), cache=False, grep=False
        )
Example #2
0
    def send_raw_request(self, head, postdata, fix_content_len=True):
        """
        In some cases the ExtendedUrllib user wants to send a request that was
        typed in a textbox or is stored in a file. When something like that
        happens, this library allows the user to send the request by specifying
        two parameters for the send_raw_request method:

        :param head: "<method> <URI> <HTTP version>\r\nHeader: Value\r\nHeader2: Value2..."
        :param postdata: The postdata, if any. If set to '' or None, no postdata is sent.
        :param fix_content_len: Indicates if the content length has to be fixed or not.

        :return: An HTTPResponse object.
        """
        # Parse the two strings
        fuzz_req = HTTPRequestParser(head, postdata)

        # Fix the content length
        if fix_content_len:
            headers = fuzz_req.get_headers()
            fixed = False
            for h in headers:
                if h.lower() == 'content-length':
                    headers[h] = str(len(postdata))
                    fixed = True
            if not fixed and postdata:
                headers['content-length'] = str(len(postdata))
            fuzz_req.set_headers(headers)

        # Send it
        function_reference = getattr(self, fuzz_req.get_method())
        return function_reference(fuzz_req.get_uri(),
                                  data=fuzz_req.get_data(),
                                  headers=fuzz_req.get_headers(),
                                  cache=False,
                                  grep=False)
Example #3
0
    def _fix_content_length(self, head, postdata):
        """
        The user may have changed the postdata of the request, and not the
        content-length header; so we are going to fix that problem.
        """
        fuzzable_request = HTTPRequestParser(head, postdata)
        
        if fuzzable_request.get_data() is None:
            # Nothing to do here
            return head, postdata
        
        headers = fuzzable_request.get_headers()
        headers['content-length'] = [str(len(fuzzable_request.get_data())), ]

        fuzzable_request.set_headers(headers)
        head = fuzzable_request.dump_request_head()
        return head, postdata
Example #4
0
    def _fix_content_length(self, head, postdata):
        """
        The user may have changed the postdata of the request, and not the
        content-length header; so we are going to fix that problem.
        """
        fuzzable_request = HTTPRequestParser(head, postdata)

        if fuzzable_request.get_data() is None:
            # Nothing to do here
            return head, postdata

        headers = fuzzable_request.get_headers()
        headers['content-length'] = [
            str(len(fuzzable_request.get_data())),
        ]

        fuzzable_request.set_headers(headers)
        head = fuzzable_request.dump_request_head()
        return head, postdata