}
void HTTPSend::makeHeader (ustring& q, const ustring& key, const ustring& val) {
- static uregex re1 ("[^a-zA-Z_0-9]");
- static uregex re2 ("[\\x00-\\x1f;]");
+ static uregex re1 ("[\\x00-\\x1f: ]");
+ static uregex re2 ("[\\x00-\\x1f]");
if (! checkRe (key, re1) && ! checkRe (val, re2) && key.length () + val.length () < 2048) {
q.append (key).append (CharConst (": ")).append (val).append (uCRLF);
if (fpost) {
q.assign (CharConst ("POST ")).append (path);
+ if (getparams.length () > 0) {
+ q.append (CharConst ("?")).append (getparams);
+ }
q.append (CharConst (" HTTP/1.0\r\n"));
} else {
q.assign (CharConst ("GET ")).append (path);
- if (params.length () > 0) {
+ if (getparams.length () > 0) {
+ q.append (CharConst ("?")).append (getparams);
+ } else if (params.length () > 0) {
q.append (CharConst ("?")).append (params);
}
q.append (CharConst (" HTTP/1.0\r\n"));
while (rc = buf.getln (client, line)) {
if (line.empty ())
break;
+ line = omitCtrl (fixUTF8 (line));
b = line.begin ();
e = line.end ();
if (splitChar (b, e, ':', m1)) {
std::stringstream ostr;
MotorOutputOStream out (&ostr);
readReplyBody (client, buf, &out);
- ans = ostr.str ();
+ ans = fixUTF8 (ostr.str ());
}
const ustring* HTTPSend::findHeader (const ustring& name) {
}
}
-static void request_query (MNode* query, HTTPSend& http) {
+static void request_query (MNode* query, HTTPSend& http, bool getmethod = false) {
MNode* a;
+ ustring* pp;
+ if (getmethod) {
+ pp = &http.getparams;
+ } else {
+ pp = &http.params;
+ }
if (query && query->isCons ()) {
while (query) {
if (a = query->car ()) {
- if (http.params.size () > 0)
- http.params.append (uAmp);
+ if (pp->size () > 0)
+ pp->append (uAmp);
if (a->isCons ()) {
- http.params.append (urlencode (to_string (a->car ()))).append (uEq).append (urlencode (to_string (a->cdr ())));
+ pp->append (urlencode (to_string (a->car ()))).append (uEq).append (urlencode (to_string (a->cdr ())));
} else {
- http.params.append (urlencode (to_string (a))).append (uEq);
+ pp->append (urlencode (to_string (a))).append (uEq);
nextNode (query);
if (query)
- http.params.append (urlencode (to_string (query->car ())));
+ pp->append (urlencode (to_string (query->car ())));
}
}
nextNode (query);
MLHttpGet obj (mlenv);
ustring url;
MNodePtr query;
+ MNodePtr getquery;
MNodePtr cookie;
MNodePtr headerquery;
{CharConst ("proxy-password"), false},
{CharConst ("proxy-pw"), false},
{CharConst ("header"), false},
+ {CharConst ("get-query"), false},
{NULL, 0, 0}
};
if (keywords[11]) { // header
headerquery = eval (keywords[11], mlenv);
}
+ if (keywords[12]) { // get-query
+ getquery = eval (keywords[12], mlenv);
+ }
url_sub (url, obj.http);
if (obj.http.proto.empty ()) {
throw (obj.http.path + ": bad URL.");
}
request_query (query (), obj.http);
+ request_query (getquery (), obj.http, true);
request_cookie (cookie (), obj.http);
request_headerquery (headerquery (), obj.http);