diff --git a/exec/load/http.js b/exec/load/http.js index af494f0e46fd793ed81209e5b66a69a96283a656..c819275851729e34a8daf94402cb42541b1ab7be 100644 --- a/exec/load/http.js +++ b/exec/load/http.js @@ -44,6 +44,23 @@ function HTTPRequest() this.AddDefaultHeaders(); }; + this.SetupPost=function(url, referer, base, data) { + this.referer=referer; + this.base=base; + this.url=new URL(url, this.base); + if(this.url.scheme!='http') + throw("Unknown scheme! '"+this.url.scheme+"'"); + if(this.url.path=='') + this.url.path='/'; + if(this.url.query != ''); + this.request="POST "+this.url.request_path+" HTTP/1.0"; + this.request_headers=[]; + this.AddDefaultHeaders(); + this.body=data; + this.request_headers.push("Content-Type: application/x-www-form-urlencoded"); + this.request_headers.push("Content-Length: "+data.length); + }; + this.SendRequest=function() { var i; @@ -82,6 +99,7 @@ function HTTPRequest() throw("Unable to receive headers"); if(header=='') return; + this.response_headers.push(header); m=header.match(/^Content-length:\s+([0-9]+)$/); if(m!=null) this.contentlength=parseInt(m[0]); @@ -109,4 +127,11 @@ function HTTPRequest() this.ReadResponse(); return(this.body); }; + + this.Post=function(url, data, referer, base) { + this.SetupPost(url,referer,base,data); + this.SendRequest(); + this.ReadResponse(); + return(this.body); + }; }