#include "motorenv.h"
#include "motoroutput.h"
#include "mlenv.h"
+#include "util_apache.h"
#include "util_file.h"
#include "util_string.h"
#include "util_time.h"
void HTTPResponse::setCookie (const ustring& key, const ustring& val, const ustring& path, time_t span, const ustring& domain, bool fsecure, MotorEnv* env) {
ustring ck;
+ ustring u;
+ size_t len;
umatch m;
static uregex re ("//|/\\.|\\.\\.|[\\x00-\\x20\\x7f-\\xff]");
ck.append (uEq);
ck.append (cookieencode (val));
ck.append (CharConst ("; path="));
- if (path.size () == 0) {
- if (env->scriptName.size () > 0) {
- ck.append (dirPart (env->scriptName));
- } else {
- ck.append (uSlash);
- }
- } else {
- if (usearch (path, m, re)) {
- if (path.begin () == m[0].first) {
- ck.append (uSlash);
- } else {
- ustring::const_iterator b = path.begin ();
- if (path[0] != '/')
- ck.append (uSlash);
- ck.append (ustring (b, m[0].first));
- }
- } else {
- if (path[0] != '/')
- ck.append (uSlash);
- ck.append (path);
- }
+ u = apacheAbsolutePath (path);
+ len = u.length ();
+ if (len > 0 && u[len - 1] == '/') {
+ u.resize (len - 1);
}
+ ck.append (u);
if (span > 0) {
time_t limit = now () + span;
ck.append (CharConst ("; expires="));
void HTTPSend::writeQueryForm (MNode* e, TcpClient& out) {
MNode* a;
- ustring u;
int c = 0;
if (e && e->isCons ()) {
while (e) {
if (a = e->car ()) {
+ ustring u;
if (c > 0)
u.append (uAmp);
u.append (percentEncode (cv (to_string (a->car ()))));
size_t HTTPSend::queryFormSize (MNode* e) {
MNode* a;
- ustring u;
int c = 0;
size_t ans = 0;
if (e && e->isCons ()) {
while (e) {
if (a = e->car ()) {
+ ustring u;
if (c > 0)
u.append (uAmp);
u.append (percentEncode (cv (to_string (a->car ()))));