diff --git a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike index 7807b872bcb102f664a67beb518ac270c66235e3..f2ff1b0d37a8516727b3d0f0d9120b2c5434d979 100644 --- a/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike +++ b/lib/modules/Protocols.pmod/HTTP.pmod/Query.pike @@ -42,7 +42,8 @@ **! Errno copied from the connection. **! **! variable mapping headers -**! Headers as a mapping. +**! Headers as a mapping. All header names are in lower case, +**! for convinience. **! **! variable string protocol **! Protocol string, ie "HTTP/1.0". @@ -373,8 +374,41 @@ object thread_request(string server,int port,string query, if (server1) server=server1; // cheaty, if host doesn't exist + // prepare the request + + if (!data) data=""; + + if (!headers) headers=""; + else if (mappingp(headers)) + { + headers=mkmapping(Array.map(indices(headers),lower_case), + values(headers)); + + if (data!="") headers->content_length=strlen(data); + + headers=headers_encode(headers); + } + + request=query+"\r\n"+headers+"\r\n"+data; + conthread=thread_create(connect,server,port); + return this_object(); +} + +object sync_request(string server,int port,string query, + void|mapping|string headers,void|string data) +{ + // start open the connection + + con=Stdio.File(); + if (!con->open_socket()) + error("HTTP.Query(): can't open socket; "+strerror(con->errno)+"\n"); + + string server1=dns_lookup(server); + + if (server1) server=server1; // cheaty, if host doesn't exist + // prepare the request if (!data) data=""; @@ -392,6 +426,8 @@ object thread_request(string server,int port,string query, request=query+"\r\n"+headers+"\r\n"+data; + connect(server,port); + return this_object(); }