OSDN Git Service

no-encode option of http-get function.
authorvisor <visor@users.sourceforge.jp>
Sat, 13 Oct 2012 15:49:29 +0000 (00:49 +0900)
committervisor <visor@users.sourceforge.jp>
Sat, 13 Oct 2012 15:49:29 +0000 (00:49 +0900)
modules/ml-http.cc

index ebcd5fc..02493cf 100644 (file)
@@ -72,7 +72,7 @@ static void  location_sub (ustring& url, MNode* query, MNode* arg, MlEnv* mlenv)
     }
 }
 
-static void  url_sub (const ustring& url, HTTPSend* http) {
+static void  url_sub (const ustring& url, HTTPSend* http, bool noencode) {
     ustring  str;
     uiterator  b, e;
     umatch  m;
@@ -88,7 +88,12 @@ static void  url_sub (const ustring& url, HTTPSend* http) {
            } else {
                http->proto = uHttp;
                http->reqhost = ustring (m[2].first, m[2].second);
-               http->path = str;
+               if (noencode) {
+                   http->path = str;
+               } else {
+                   http->path = ustring (b, m[0].second - 1);
+                   http->path.append (percentEncode_path (m[0].second - 1, e));
+               }
                if (http->host.port == 0)
                    http->host.port = 80;
            }
@@ -100,14 +105,20 @@ static void  url_sub (const ustring& url, HTTPSend* http) {
                http->host.port = to_uint32 (ustring (m[5].first, m[5].second));
            else
                http->host.port = 0;
-           http->path = percentEncode_path (m[0].second - 1, e);
+           if (noencode)
+               http->path = ustring (m[0].second - 1, e);
+           else
+               http->path = percentEncode_path (m[0].second - 1, e);
        }
     } else {
 //     throw (str + ": bad URL.");
        http->proto.resize (0);
        http->host.host.resize (0);
        http->host.port = 0;
-       http->path = percentEncode_path (str);
+       if (noencode)
+           http->path = str;
+       else
+           http->path = percentEncode_path (str);
     }
 }
 
@@ -340,7 +351,7 @@ MNode*  ml_response_no_cache (MNode* cell, MlEnv* mlenv) {
        [:proxy-id STRING] [:proxy-password STRING | :proxy-pw STRING]
        [#sjis] [#euc-jp] [:iconv NAME]
        [:on-error FUNCTION]
-       [#no-verify]
+       [#no-verify] [#no-encode]
        [SUBFUNCTION...]) -> LAST VALUE
 
 */
@@ -353,6 +364,7 @@ MNode*  ml_http_get (MNode* cell, MlEnv* mlenv) {
     MNodePtr  headerquery;
     MNodePtr  errfn;
     bool  fnoverify = false;
+    bool  fnoencode = false;
     std::vector<MNode*>  params;
     std::vector<MNode*>  keywords;
     MNode*  rest;
@@ -388,6 +400,7 @@ MNode*  ml_http_get (MNode* cell, MlEnv* mlenv) {
        {CharConst ("raw-file-serial"), false}, // 27
        {CharConst ("raw-file-named"), false},  // 28
        {CharConst ("raw-file-static"), false}, // 29
+       {CharConst ("no-encode"), true},        // 30
        {NULL, 0, 0}
     };
 
@@ -473,8 +486,10 @@ MNode*  ml_http_get (MNode* cell, MlEnv* mlenv) {
        obj.http->rawqueryfile = mlenv->env->path_storage_file (eval_str (keywords[28], mlenv));
     if (keywords[29])          // raw-file-static
        obj.http->rawqueryfile = mlenv->env->path_static_file (eval_str (keywords[29], mlenv));
+    if (keywords[30])          // no-encode
+       fnoencode = eval_bool (keywords[30], mlenv);
     
-    url_sub (url, obj.http);
+    url_sub (url, obj.http, fnoencode);
     if (obj.http->proto.empty ()) {
        throw (obj.http->path + ": bad URL.");
     }