From 93b3e3b8e12c314717ed9b5f7339b158c067c718 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Thu, 19 Dec 2019 09:29:37 -0300 Subject: [PATCH] 15672: Switches to POST when using long query strings on list API calls. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- package.json | 1 + src/services/common-service/common-service.ts | 38 ++++++++++++------- yarn.lock | 19 ++++++++++ 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 0687e1ba45..93b6bb0fd6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index 262b5c5d55..d811782127 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -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 { 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) { diff --git a/yarn.lock b/yarn.lock index bb1cf454ab..fd0fa51976 100644 --- 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" -- 2.30.2