Note!: This is NOT a PROPER example of a HTTP client with sockets in C. Its main purpose is to teach how to build Python modules using the Python C API!
I used Python 3.8.10 and gcc 9.4.0
See the code of the 'HTTP client' in src/ directory and
myhttp.c for Python C extention code.
Install <Python.h> to enable the inclusion of the header in your code:
sudo apt-get install python3-devConfigure localhost:
- Open
/etc/hostswith any editor and paste this code:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
Install MyHttp package
- Install the package globally:
sudo python3 setup.py installCheck installation with:
pip3 freezeYou should see this in result your installed modules:
...
MyHttp==1.0.0
...- Or install it locally:
sudo python3 setup.py buildCodes below will create a .so file in build/ folder.
Test your code:
Note: Before testing with localhost, run server.py (default port is: 8080):
python3 server.pyRun test.py as:
python3 test.py --full-printWhen the --full-print flag is provided, the test.py will print full responses.
Use --no-external or --no-internal to exclude external or local requests, respectively.