summaryrefslogtreecommitdiffhomepage
path: root/NetEx/HttpClient.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NetEx/HttpClient.cpp')
-rw-r--r--NetEx/HttpClient.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/NetEx/HttpClient.cpp b/NetEx/HttpClient.cpp
new file mode 100644
index 0000000..3f7e204
--- /dev/null
+++ b/NetEx/HttpClient.cpp
@@ -0,0 +1,68 @@
+/* Project nGenEx
+ Destroyer Studios LLC
+ Copyright © 1997-2004. All Rights Reserved.
+
+ SUBSYSTEM: NetEx.lib
+ FILE: HttpClient.cpp
+ AUTHOR: John DiCamillo
+
+
+ OVERVIEW
+ ========
+ Network Server Pump for HTTP Server
+*/
+
+
+#include "MemDebug.h"
+#include "HttpClient.h"
+#include "NetHost.h"
+#include "NetLayer.h"
+#include <mmsystem.h>
+
+// +-------------------------------------------------------------------+
+
+HttpClient::HttpClient(const NetAddr& server_addr)
+ : NetClient(server_addr)
+{
+}
+
+HttpClient::~HttpClient()
+{
+ cookies.destroy();
+}
+
+HttpResponse*
+HttpClient::DoRequest(HttpRequest& request)
+{
+ // add existing cookies to request before sending:
+ CombineCookies(request.GetCookies(), cookies);
+
+ Text req = request.operator Text();
+ Text msg = SendRecv(req);
+ HttpResponse* response = new(__FILE__,__LINE__) HttpResponse(msg);
+
+ if (response) {
+ // save cookies returned in response:
+ CombineCookies(cookies, response->GetCookies());
+ }
+
+ return response;
+}
+
+void
+HttpClient::CombineCookies(List<HttpParam>& dst, List<HttpParam>& src)
+{
+ for (int i = 0; i < src.size(); i++) {
+ HttpParam* s = src[i];
+ HttpParam* d = dst.find(s);
+
+ if (d) {
+ d->value = s->value;
+ }
+ else {
+ HttpParam* cookie = new(__FILE__,__LINE__) HttpParam(s->name, s->value);
+ if (cookie)
+ dst.append(cookie);
+ }
+ }
+} \ No newline at end of file