15672: Switches to POST when using long query strings on list API calls.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 19 Dec 2019 12:29:37 +0000 (09:29 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 19 Dec 2019 12:29:37 +0000 (09:29 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

package.json
src/services/common-service/common-service.ts
yarn.lock

index 0687e1ba45125e90c6af9a57b045bb53e345bdb6..93b6bb0fd61db49fff011743c9db38064dc67b4a 100644 (file)
@@ -35,6 +35,7 @@
     "lodash.template": "4.5.0",
     "mem": "4.0.0",
     "prop-types": "15.7.2",
+    "query-string": "6.9.0",
     "react": "16.5.2",
     "react-copy-to-clipboard": "5.0.1",
     "react-dnd": "5.0.0",
index 262b5c5d55767beb6b851a102906e36c31c38d9d..d81178212711a7e7634e5493b7e516793d158aa2 100644 (file)
@@ -6,6 +6,7 @@ import * as _ from "lodash";
 import { AxiosInstance, AxiosPromise } from "axios";
 import * as uuid from "uuid/v4";
 import { ApiActions } from "~/services/api/api-actions";
+import * as QueryString from "query-string";
 
 interface Errors {
     errors: string[];
@@ -114,20 +115,29 @@ export class CommonService<T> {
             order: order ? order : undefined
         };
 
-        // Using the POST special case to avoid URI length 414 errors.
-        // See https://doc.arvados.org/v1.4/api/requests.html
-        const formData = new FormData();
-        formData.append("_method", "GET");
-        Object.keys(params).map(key => {
-            if (params[key] !== undefined) {
-                formData.append(key, params[key]);
-            }
-        });
-
-        return CommonService.defaultResponse(
-            this.serverApi.post(this.resourceType, formData),
-            this.actions
-        );
+        if (QueryString.stringify(params).length <= 1500) {
+            return CommonService.defaultResponse(
+                this.serverApi.get(this.resourceType, { params }),
+                this.actions
+            );
+        } else {
+            // Using the POST special case to avoid URI length 414 errors.
+            const formData = new FormData();
+            formData.append("_method", "GET");
+            Object.keys(params).map(key => {
+                if (params[key] !== undefined) {
+                    formData.append(key, params[key]);
+                }
+            });
+            return CommonService.defaultResponse(
+                this.serverApi.post(this.resourceType, formData, {
+                    params: {
+                        _method: 'GET'
+                    }
+                }),
+                this.actions
+            );
+        }
     }
 
     update(uuid: string, data: Partial<T>) {
index bb1cf454ab14b3d98681c0e996a885245172bd30..fd0fa51976795d7b52bb6c46853e61fb5311a03c 100644 (file)
--- a/yarn.lock
+++ b/yarn.lock
@@ -8291,6 +8291,15 @@ qs@~6.5.2:
   resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36"
   integrity sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==
 
+query-string@6.9.0:
+  version "6.9.0"
+  resolved "https://registry.yarnpkg.com/query-string/-/query-string-6.9.0.tgz#1c3b727c370cf00f177c99f328fda2108f8fa3dd"
+  integrity sha512-KG4bhCFYapExLsUHrFt+kQVEegF2agm4cpF/VNc6pZVthIfCc/GK8t8VyNIE3nyXG9DK3Tf2EGkxjR6/uRdYsA==
+  dependencies:
+    decode-uri-component "^0.2.0"
+    split-on-first "^1.0.0"
+    strict-uri-encode "^2.0.0"
+
 query-string@^4.1.0:
   version "4.3.4"
   resolved "https://registry.yarnpkg.com/query-string/-/query-string-4.3.4.tgz#bbb693b9ca915c232515b228b1a02b609043dbeb"
@@ -9667,6 +9676,11 @@ spdy@^4.0.1:
     select-hose "^2.0.0"
     spdy-transport "^3.0.0"
 
+split-on-first@^1.0.0:
+  version "1.1.0"
+  resolved "https://registry.yarnpkg.com/split-on-first/-/split-on-first-1.1.0.tgz#f610afeee3b12bce1d0c30425e76398b78249a5f"
+  integrity sha512-43ZssAJaMusuKWL8sKUBQXHWOpq8d6CfN/u1p4gUzfJkM05C8rxTmYrkIPTXapZpORA6LkkzcUulJ8FqA7Uudw==
+
 split-string@^3.0.1, split-string@^3.0.2:
   version "3.1.0"
   resolved "https://registry.yarnpkg.com/split-string/-/split-string-3.1.0.tgz#7cb09dda3a86585705c64b39a6466038682e8fe2"
@@ -9775,6 +9789,11 @@ strict-uri-encode@^1.0.0:
   resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
   integrity sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM=
 
+strict-uri-encode@^2.0.0:
+  version "2.0.0"
+  resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz#b9c7330c7042862f6b142dc274bbcc5866ce3546"
+  integrity sha1-ucczDHBChi9rFC3CdLvMWGbONUY=
+
 string-length@^1.0.1:
   version "1.0.1"
   resolved "https://registry.yarnpkg.com/string-length/-/string-length-1.0.1.tgz#56970fb1c38558e9e70b728bf3de269ac45adfac"