python - Apparently fine http request results malformed when sent over socket -
i'm working socket operations , have coded basic interception proxy in python. works fine, hosts return 400 bad request responses.
these requests not malformed though. here's one:
get http://www.baltour.it/ http/1.1 host: www.baltour.it user-agent: mozilla/5.0 (x11; ubuntu; linux x86_64; rv:28.0) gecko/20100101 firefox/28.0 accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 accept-language: en-us,en;q=0.5 accept-encoding: gzip, deflate connection: keep-alive
same request, raw:
get http://www.baltour.it/ http/1.1\r\nhost: www.baltour.it\r\nuser-agent: mozilla/5.0 (x11; ubuntu; linux x86_64; rv:28.0) gecko/20100101 firefox/28.0\r\naccept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\naccept-language: en-us,en;q=0.5\r\naccept-encoding: gzip, deflate\r\nconnection: keep-alive\r\n\r\n
the code use send request basic socket operation (though don't think problem lies there, works fine hosts)
socket_client.send(request_raw)
while socket_client.recv used response (but no problems here, response well-formed, though status 400).
any ideas?
when not talking proxy, not supposed put http://hostname
part in http header; see section 5.1.2 of http 1.1 rfc 2616 spec:
the common form of request-uri used identify resource on origin server or gateway. in case the absolute path of uri must transmitted (see section 3.2.1, abs_path) request-uri, , network location of uri (authority) must transmitted in host header field.
(emphasis mine); abs_path
absolute path part of request uri, not full absolute uri itself.
e.g. server expects send:
get / http/1.1 host: www.baltour.it
a receiving server should tolerant of incorrect behaviour, however. server seems violate rfc here too. further on in same section reads:
to allow transition absoluteuris in requests in future versions of http, http/1.1 servers must accept absoluteuri form in requests, though http/1.1 clients generate them in requests proxies.
Comments
Post a Comment