HTTP Client Request
HTTP Client Request
HTTP Client Request
SENDED :
for http request : get
b'GET /?address=10+rue+des+chardonnerets+31270+villeneuve+tolosane HTTP/1.1\r\
nHost: 127.0.0.1:65432\r\nUser-Agent: python-requests/2.24.0\r\nAccept-Encoding:
gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'
sended : http get request with test as param
b'GET /?test HTTP/1.1\r\nHost: 127.0.0.1:65432\r\nUser-Agent:
python-requests/2.24.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\
nConnection: keep-alive\r\n\r\n'
sended : http get request with 2 entries as param, dict :
b'GET /?address=10+rue+des+chardonnerets+31270+villeneuve+tolosane&anothet=123
HTTP/1.1\r\nHost: 127.0.0.1:46527\r\nUser-Agent: python-requests/2.24.0\r\nAccept-
Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'
sended : http get request no param
b'GET / HTTP/1.1\r\nHost: 127.0.0.1:46527\r\nUser-Agent: python-requests/2.24.0\r\
nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'
sended : http request post
b'POST /?Hello%20world! HTTP/1.1\r\nHost: 127.0.0.1:46527\r\nUser-Agent: python-
requests/2.24.0\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection:
keep-alive\r\nContent-Length: 0\r\n\r\n'
sended http request post with header test: gg
b'POST / HTTP/1.1\r\nHost: 127.0.0.1:46527\r\nUser-Agent: python-requests/2.24.0\r\
nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\ntest:
gg\r\nContent-Length: 0\r\n\r\n'
b'GET / HTTP/1.1\r\nHost: localhost:25000\r\nUpgrade-Insecure-Requests: 1\r\
nAccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\nUser-
Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML,
like Gecko) Version/13.1.1 Safari/605.1.15\r\nAccept-Language: en-gb\r\nAccept-
Encoding: gzip, deflate\r\nConnection: keep-alive\r\n\r\n'
possible answer
#{"Host" : None, "User-Agent" : "Googlebot", "Connection" : "close"} -> header
#Some chars may not be sended correctly. -> for ' ' or so, use % + 0*(2-len(c)) +
hex(ord(char))[2:]
#TODO -> create two folders one server and one client with an http request parser
and an http request maker.
#setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
#Test purposes only.
"""
def stop_http_server():
global LOOP
LOOP = False
#----- HTTP Client Request Function -----
def raw_http_client_request(sock, method: str, uri: str ="", parameters: list =[],
header: dict ={}, data=b"", version: float =1.0, rwsize: int =256):
sock.send(str(method).encode("ascii") + b" /" + str(uri).encode("ascii"))
if parameters:
sock.send(b"?")
if not isinstance(parameters, str):
i = 0
for item in parameters:
sock.send(str(item).encode('ascii'))
if isinstance(parameters, dict):
sock.send(b"=" + parameters[item].encode("ascii"))
if i < len(parameters)-1:
sock.send(b"&")
i += 1
else:
sock.send(str(parameters).encode('ascii'))
sock.send(b" HTTP/" + str(version).encode("ascii") + b"\r\n")
for key in header:
sock.send(str(key).encode("ascii") + b": " +
str(header[key]).encode("ascii") + b"\r\n")
sock.send(b"\r\n")
if isinstance(data, bytes):
sock.send(data)
else:
fd = open(str(data), 'rb')
while True:
temp = fd.read(rwsize)
sock.send(temp)
if len(temp) < rwsize: break
fd.close()
return
def unregister_cmd(cmd):
global cmds, funcs
i = cmds.index(cmd)
if i >= 0:
del funcs[i], cmds[i]
#%C3%A7%D0%BF ->for: çп
#%C3%A7 ->for: ç
#%D0%BF ->for: п
"""
["GET", "POST", "HEAD", "TRACE", "PUT", "DELETE", "CONNECT", "OPTIONS", "PATCH"]
1.1
{"Host:" : None, "User-Agent:" : "Googlebot", "Connection:" : "close"}
80
for server -> each conn has a security number that can be changed through post with
the given good passwords and all. -> each request processing depends on whether the
security number of the connection is correct or not.
"""