mirror of
https://github.com/jdalrymple/gitbeaker.git
synced 2026-01-18 15:55:30 +00:00
Fixing support for FormData requests (#1056)
This commit is contained in:
parent
949171bd23
commit
21faf97301
@ -11,7 +11,7 @@ function responseHeadersAsObject(response): Record<string, string> {
|
||||
if (!response.headers.entries().length) {
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
const headers = {};
|
||||
const keyVals = [...response.headers.entries()];
|
||||
|
||||
|
||||
@ -11,11 +11,11 @@
|
||||
"dependencies": {
|
||||
"@gitbeaker/core": "^23.4.2",
|
||||
"@gitbeaker/requester-utils": "^23.4.2",
|
||||
"form-data": "^3.0.0",
|
||||
"got": "^11.1.4",
|
||||
"xcase": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"form-data": "^3.0.0",
|
||||
"@types/node": "^14.0.6",
|
||||
"openpgp": "^4.10.4",
|
||||
"rollup": "^2.12.0",
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import Got from 'got';
|
||||
import * as FormData from 'form-data';
|
||||
import { decamelizeKeys } from 'xcase';
|
||||
import { Agent } from 'https';
|
||||
import {
|
||||
@ -15,7 +14,8 @@ export function defaultRequest(
|
||||
) {
|
||||
const options = baseDefaultRequest(service, { body, query, sudo, method });
|
||||
|
||||
if (typeof body === 'object' && !(body instanceof FormData)) {
|
||||
// FIXME: Not the best comparison, but...it will have to do for now.
|
||||
if (typeof body === 'object' && body.constructor.name !== 'FormData') {
|
||||
options.json = decamelizeKeys(body);
|
||||
|
||||
delete options.body;
|
||||
|
||||
@ -9,12 +9,12 @@
|
||||
"url": "https://github.com/jdalrymple/gitbeaker/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"form-data": "^3.0.0",
|
||||
"query-string": "^6.12.1",
|
||||
"xcase": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^14.0.6",
|
||||
"form-data": "^3.0.0",
|
||||
"rollup": "^2.12.0",
|
||||
"rollup-plugin-terser": "^6.1.0",
|
||||
"rollup-plugin-typescript2": "^0.27.1",
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import { Agent } from 'https';
|
||||
import { decamelizeKeys } from 'xcase';
|
||||
import { stringify } from 'query-string';
|
||||
import * as FormData from 'form-data';
|
||||
|
||||
// Types
|
||||
export interface RequesterType {
|
||||
@ -41,7 +40,8 @@ export function defaultRequest(
|
||||
|
||||
if (sudo) headers.sudo = sudo;
|
||||
|
||||
if (typeof body === 'object' && !(body instanceof FormData)) {
|
||||
// FIXME: Not the best comparison, but...it will have to do for now.
|
||||
if (typeof body === 'object' && body.constructor.name !== 'FormData') {
|
||||
bod = JSON.stringify(decamelizeKeys(body));
|
||||
headers['content-type'] = 'application/json';
|
||||
} else {
|
||||
@ -67,6 +67,7 @@ export function createInstance(optionsHandler, requestHandler): RequesterType {
|
||||
/* eslint func-names:0 */
|
||||
requester[m] = function (service, endpoint, options) {
|
||||
const requestOptions = optionsHandler(service, { ...options, method: m });
|
||||
|
||||
return requestHandler(endpoint, requestOptions);
|
||||
};
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user