summaryrefslogtreecommitdiff
path: root/lib/HttpClient.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/HttpClient.cc')
-rw-r--r--lib/HttpClient.cc24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/HttpClient.cc b/lib/HttpClient.cc
index 6182da4..8b18f07 100644
--- a/lib/HttpClient.cc
+++ b/lib/HttpClient.cc
@@ -17,19 +17,20 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: HttpClient.cc,v 1.10 2007-05-30 11:57:09 pixel Exp $ */
+/* $Id: HttpClient.cc,v 1.11 2007-06-17 15:24:44 pixel Exp $ */
#include <TaskMan.h>
#include <HttpClient.h>
#include <BRegex.h>
#include <CopyJob.h>
#include <ReadJob.h>
+#include <Variables.h>
t_headers no_headers;
const timeval timeout = { 8, 0 };
-HttpClient::HttpClient(const String & _url, Handle * _out, const String & _fake_host, t_headers _headers) : url(_url), out(_out), fake_host(_fake_host), headers(_headers), host(""), uri("") {
+HttpClient::HttpClient(const String & _url, Handle * _out, const String & _fake_host, t_headers _headers, const Variables & _vars) : url(_url), out(_out), fake_host(_fake_host), headers(_headers), vars(_vars), host(""), uri("") {
DecodeURL();
Client.SetNonBlock();
@@ -49,9 +50,11 @@ HttpClient::~HttpClient() {
int HttpClient::Do() throw (GeneralException) {
t_headers::iterator i;
String t;
- int l;
+ int l, j;
Regex h_reply("^HTTP/1.1 ");
Regex chunked_header("^Transfer-Encoding: chunked$");
+ bool do_post = vars.GetNb();
+ String rendered_variables;
switch (current) {
case 0:
@@ -67,15 +70,28 @@ int HttpClient::Do() throw (GeneralException) {
}
RemoveTimeout();
- b << "GET " + uri + " HTTP/1.1\r\n"
+ b << (do_post ? "GET " : "POST ") + uri + " HTTP/1.1\r\n"
"Host: " + host + "\r\n"
"Connection: close\r\n";
for (i = headers.begin(); i != headers.end(); i++) {
b << *i + "\r\n";
}
+
+ if (do_post) {
+ for (j = 0; j < vars.GetNb(); j++) {
+ if (j != 0) {
+ rendered_variables += "&";
+ }
+ rendered_variables += vars[j];
+ }
+ b << "Content-Type: application/x-www-form-urlencoded\r\n";
+ b << "Content-Length: " + String(rendered_variables.strlen()) + "\r\n\r\n";
+ }
b << "\r\n";
+
+ b << rendered_variables;
c = new CopyJob(&b, &Client);
WaitFor(timeout);