//#define BOOTSTRAPHACK 1
//#define COMPAT_STORAGE_CREATE 1
//#define HTTPS_NOCACHE 1
+//#define QUERYENCODEALT 1
#define STANDALONE 1
#endif /* CONFIG_H */
return percentEncode (b, e, re);
}
+ustring percentEncode_path (uiterator b, uiterator e) {
+ static uregex re ("(\\x00)|([^A-Za-z0-9_/.~-])");
+
+ return percentEncode (b, e, re);
+}
+
ustring percentEncode (const ustring& str) {
return percentEncode (str.begin (), str.end ());
}
+ustring percentEncode_path (const ustring& str) {
+ return percentEncode_path (str.begin (), str.end ());
+}
+
+#if 0
ustring percentEncode_path (uiterator b, uiterator e) {
uiterator i;
ustring ans;
ustring percentEncode_path (const ustring& str) {
return percentEncode_path (str.begin (), str.end ());
}
+#endif
ustring percentDecode (const ustring& str) {
ustring ans;
+#include "config.h"
#include "util_url.h"
#include "util_const.h"
#include "util_string.h"
return usearch (proto, m, re);
}
+#ifdef QUERYENCODEALT
static ustring urlencode (uiterator b, uiterator e, const uregex& re) {
umatch m;
ustring ans;
+ int c;
while (b < e && usearch (b, e, m, re)) {
while (b < m[0].first) {
b = m[0].second;
}
while (b < e) {
- if (*b == 0)
+ c = *b ++;
+ if (c == 0)
ans.append (uUScore);
else
- ans.append (percentHEX (*b++));
+ ans.append (percentHEX (c));
}
return ans;
static uregex re ("[" CUNRESERVED "/" MSB1CHAR "]+");
return urlencode (b, e, re);
}
+#endif
ustring buildQuery (MNode* query) {
int c = 0;
ans.append (CharConst ("&"));
c ++;
u = to_string (a->car ());
+#ifdef QUERYENCODEALT
ans.append (urlencode (u.begin (), u.end ()));
+#else
+ ans.append (percentEncode (u.begin (), u.end ()));
+#endif
ans.append (uEq);
u = to_string (a->cdr ());
+#ifdef QUERYENCODEALT
ans.append (urlencode (u.begin (), u.end ()));
+#else
+ ans.append (percentEncode (u.begin (), u.end ()));
+#endif
} else {
throw (to_string (a) + uErrorBadValue);
}
#ifndef UTIL_URL_H
#define UTIL_URL_H
+#include "config.h"
#include "ustring.h"
class MNode;
bool checkURL (ustring& url, upair* scheme, upair* delim, upair* user, upair* pass, upair* host, upair* port, upair* rest);
bool checkURLSafe (ustring& url);
bool checkScheme (ustring& proto);
+#ifdef QUERYENCODEALT
ustring urlencode (uiterator b, uiterator e);
ustring urlencode_path (uiterator b, uiterator e);
+#endif
ustring buildQuery (MNode* query);
#endif /* UTIL_URL_H */
+#include "config.h"
#include "ml-http.h"
#include "ml.h"
#include "mlenv.h"
if (port.first != port.second) {
ans.append (uColon).append (port.first, port.second);
}
+#ifdef QUERYENCODEALT
ans.append (urlencode_path (rest.first, rest.second));
+#else
+ ans.append (percentEncode_path (rest.first, rest.second));
+#endif
} else {
+#ifdef QUERYENCODEALT
ans.assign (urlencode_path (url.begin (), url.end ()));
+#else
+ ans.assign (percentEncode_path (url.begin (), url.end ()));
+#endif
}
if (query)
ans.append (buildQuery (query));
if (user ()) {
u = to_string (user ());
omitCtrl (u);
+#ifdef QUERYENCODEALT
ans ()->append (urlencode (u.begin (), u.end ()));
+#else
+ ans ()->append (percentEncode (u.begin (), u.end ()));
+#endif
if (pwd ()) {
ans ()->append (uColon);
u = to_string (pwd ());
omitCtrl (u);
+#ifdef QUERYENCODEALT
ans ()->append (urlencode (u.begin (), u.end ()));
+#else
+ ans ()->append (percentEncode (u.begin (), u.end ()));
+#endif
}
ans ()->append (CharConst ("@"));
}
if (path[0] != '/') {
ans ()->append (uSlash);
}
+#ifdef QUERYENCODEALT
ans ()->append (urlencode_path (path.begin (), path.end ()));
+#else
+ ans ()->append (percentEncode_path (path.begin (), path.end ()));
+#endif
if (query ()) {
ans ()->append (buildQuery (query ()));
}
if (! isNil (t ())) {
u = to_string (t ());
if (c == 0) {
+#ifdef QUERYENCODEALT
ans ()->append (urlencode (u.begin (), u.end ()));
+#else
+ ans ()->append (percentEncode (u.begin (), u.end ()));
+#endif
c ++;
} else {
+#ifdef QUERYENCODEALT
ans ()->append (uSlash).append (urlencode (u.begin (), u.end ()));
+#else
+ ans ()->append (uSlash).append (percentEncode (u.begin (), u.end ()));
+#endif
}
}
nextNode (arg);