From 1ca26faf9d5ed10ee4258820bd7e4529d4fd231a Mon Sep 17 00:00:00 2001
From: deuce <>
Date: Tue, 19 Jul 2011 08:05:01 +0000
Subject: [PATCH] Add POST support and returning response headers to the
 script.

---
 exec/load/http.js | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/exec/load/http.js b/exec/load/http.js
index af494f0e46..c819275851 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);
+	};
 }
-- 
GitLab