From e33e19d0587146859d48a134ec9fd94e7b7ba5cd Mon Sep 17 00:00:00 2001 From: "FWoltermann@gmail.com" Date: Thu, 8 Dec 2011 14:53:40 +0000 Subject: Initial upload --- NetEx/HttpClient.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 NetEx/HttpClient.cpp (limited to 'NetEx/HttpClient.cpp') 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 + +// +-------------------------------------------------------------------+ + +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& dst, List& 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 -- cgit v1.1