0

I am trying to make little automated-testing script. It shoud be able to make HTTP request based on string provided, something like follows:

import coollib  # non-existent library

r = coollib.make_raw_request(
    # Lets assume, python's tripple quoted string spacing is not a problem.
    """
        GET / HTTP/1.1\n\r
        Host: example.com\n\r
        My-Faulty-Header: status\n\r
    """
)

print(r.response_body)

Intention behind this is to insert a little mistakes into request, to test, how web server copes with faulty requests.

Any idea how to do this? Any insights are welcome.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Fusion
  • 5,046
  • 5
  • 42
  • 51
  • I know nothing about `coollib`. But you might look into the `socket` module. That's a start, anyway. – Booboo Nov 04 '19 at 21:29

1 Answers1

2

As Ronald Aaronson mentioned in the comment, your weapon of choice here should probably be the socket library. There's an example in this related question: Creating a raw HTTP request with sockets

yoniLavi
  • 2,624
  • 1
  • 24
  • 30