Note!: This is NOT a PROPER example of HTTP client with sockets in C. Main purpose of this repository is to learn to build python modules with Python C API!
I use Python 3.8.10
and gcc 9.4.0
See code of 'HTTP client' in src/*
directory and
myhttp.c for Python C extention code.
Install <Python.h>
to be able to include the header in your code:
sudo apt-get install python3-dev
Configure localhost:
- Open
/etc/hosts
with 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 install
Check installation with:
pip3 freeze
You should see this in result your installed modules:
...
MyHttp==1.0.0
...
- Or install it locally:
sudo python3 setup.py build
Codes below will create .so
file in /build/*/
folder.
Test your code:
Note: Before testing with localhost, run server.py
(default port is: 8080):
python3 server.py
Run test.py
as:
python3 test.py --full-print
As --full-print
flag provided test.py
will print full responses.
Use --no-external
or --no-internal
to exclude external or local requests, respectively.