summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2008-07-16 16:50:24 +0000
committerpixel <pixel>2008-07-16 16:50:24 +0000
commitd1d512080aafbf9a271c13cd3eb04815baeebadc (patch)
tree999acff041d17618f02cd1b066477d87da6afa2b /lib
parent5627c9a50ada2bce7c43c7bdeefe822c2b53df61 (diff)
Adding basic cookies support.
Diffstat (limited to 'lib')
-rw-r--r--lib/HttpServ.cc11
-rw-r--r--lib/LuaHttp.cc20
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index 3b14c49..a16bc45 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: HttpServ.cc,v 1.63 2008-07-16 09:37:40 pixel Exp $ */
+/* $Id: HttpServ.cc,v 1.64 2008-07-16 16:50:24 pixel Exp $ */
#include <vector>
@@ -915,6 +915,15 @@ void HttpResponse::PrepareResponse(Handle * b) {
strftime(buf, 1024, "%a, %d %b %Y %H:%M:%S GMT", ft);
(*b) << "Last-Modified: " << buf << "\r\n";
}
+ if (cookies.size()) {
+ (*b) << "Set-Cookie: ";
+ for (std::vector<std::pair<String, String> >::iterator i = cookies.begin(); i != cookies.end(); i++) {
+ (*b) << i->first << "=" << i->second << ";";
+ }
+ if (cookies_path != "")
+ (*b) << "path=" << cookies_path;
+ (*b) << "\r\n";
+ }
(*b) << "\r\n";
}
diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc
index 0f2bd70..8284537 100644
--- a/lib/LuaHttp.cc
+++ b/lib/LuaHttp.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: LuaHttp.cc,v 1.27 2008-02-26 18:23:58 pixel Exp $ */
+/* $Id: LuaHttp.cc,v 1.28 2008-07-16 16:50:24 pixel Exp $ */
#include "Domain.h"
#include "LuaHttp.h"
@@ -220,6 +220,10 @@ int sLua_HttpResponse::HttpResponse_proceed(Lua * L, int n, HttpResponse * res,
}
} else if (i == "cache") {
L->push(res->cache);
+ } else if (i == "cookies_path") {
+ L->push(res->cookies_path);
+ } else if (i == "cookies") {
+ L->error("Can't read cookies (for now)");
} else {
L->error("Unknow field in HttpResponse object: " + i);
}
@@ -245,6 +249,18 @@ int sLua_HttpResponse::HttpResponse_proceed(Lua * L, int n, HttpResponse * res,
L->error("Can't alter field buffer in HttpResponse.");
} else if (i == "cache") {
res->cache = L->toboolean(3);
+ } else if (i == "cookies_path") {
+ res->cookies_path = L->tostring(3);
+ } else if (i == "cookies") {
+ String cookie = L->tostring(3), key, value;
+ int pos = cookie.strchr('=');
+ if (pos < 0) {
+ L->error("Malformed cookie.");
+ }
+ key = cookie.extract(0, pos - 1).trim();
+ value = cookie.extract(pos + 1).trim();
+ std::pair<String, String> e(key, value);
+ res->cookies.push_back(e);
} else {
L->error("Unknow field in HttpResponse object: " + i);
}
@@ -325,7 +341,7 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller)
}
LuaDomain::LuaDomain(Lua * _L, String r) : Domain(r), L(_L->Father()) {
- id = max_id++;
+ id = max_id++; /***FIXME***/
L->push(DOMAIN_REGISTRY);
L->gettable(LUA_REGISTRYINDEX);