Skip to content

Commit 304a0ce

Browse files
feat(fts-http): add support for brotli compressed request bodies
1 parent d770d2f commit 304a0ce

File tree

3 files changed

+11
-54
lines changed

3 files changed

+11
-54
lines changed

packages/fts-http/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"accepts": "^1.3.5",
2929
"content-type": "^1.0.4",
3030
"cors": "^2.8.5",
31+
"decompress-request": "^1.0.0",
3132
"file-type": "^12.4.0",
3233
"fts": "^1.3.0",
3334
"fts-core": "^1.1.0",
3435
"fts-validator": "^1.3.3",
35-
"inflation": "^2.0.0",
3636
"is-stream": "^1.1.0",
3737
"micro": "^9.3.3",
3838
"micro-cors": "^0.1.1",

packages/fts-http/src/handler.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import contentType from 'content-type'
2+
import decompressRequest from 'decompress-request'
23
import fileType from 'file-type'
34
import fs from 'fs'
45
import { Definition } from 'fts'
56
import { createValidator } from 'fts-validator'
67
import http from 'http'
7-
import inflate from 'inflation'
88
import { readable } from 'is-stream'
99
import * as micro from 'micro'
1010
import microCORS = require('micro-cors')
@@ -232,7 +232,7 @@ async function getParams(
232232
})
233233
} else {
234234
const body = await getBody(context)
235-
return JSON.parse(body.toString('utf8'))
235+
params = JSON.parse(body.toString('utf8'))
236236
}
237237
} else {
238238
throw micro.createError(501, 'Not implemented\n')
@@ -257,7 +257,9 @@ async function getBody(context: HttpContext): Promise<Buffer> {
257257
opts.length = +len
258258
}
259259

260-
return (raw(inflate(context.req), opts) as unknown) as Promise<Buffer>
260+
return (raw(decompressRequest(context.req), opts) as unknown) as Promise<
261+
Buffer
262+
>
261263
}
262264

263265
function send(context: HttpContext, code: number, obj: any = null) {

yarn.lock

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,6 +2752,11 @@ decode-uri-component@^0.2.0:
27522752
resolved "https://registry.yarnpkg.com/decode-uri-component/-/decode-uri-component-0.2.0.tgz#eb3913333458775cb84cd1a1fae062106bb87545"
27532753
integrity sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU=
27542754

2755+
decompress-request@^1.0.0:
2756+
version "1.0.0"
2757+
resolved "https://registry.yarnpkg.com/decompress-request/-/decompress-request-1.0.0.tgz#770c29856875d416baede259ca1a26981ef8e0ea"
2758+
integrity sha512-QQivyhJ/gOt9Qj9xDV4KOxq3fz5Sekxyg9dD9hi1Yw+WgjdWk2Cga30ulYvc8NLHp+MvzyBXwI4tZbfFgaBk4g==
2759+
27552760
decompress-response@^3.3.0:
27562761
version "3.3.0"
27572762
resolved "https://registry.yarnpkg.com/decompress-response/-/decompress-response-3.3.0.tgz#80a4dd323748384bfa248083622aedec982adff3"
@@ -3534,51 +3539,6 @@ fstream@^1.0.0, fstream@^1.0.2:
35343539
mkdirp ">=0.5 0"
35353540
rimraf "2"
35363541

3537-
"fts-core@link:packages/fts-core":
3538-
version "0.0.0"
3539-
uid ""
3540-
3541-
"fts-dev@link:packages/fts-dev":
3542-
version "0.0.0"
3543-
uid ""
3544-
3545-
"fts-http-client@link:packages/fts-http-client":
3546-
version "0.0.0"
3547-
uid ""
3548-
3549-
"fts-http@link:packages/fts-http":
3550-
version "1.3.5"
3551-
dependencies:
3552-
accepts "^1.3.5"
3553-
content-type "^1.0.4"
3554-
cors "^2.8.5"
3555-
file-type "^12.4.0"
3556-
fts "^1.3.0"
3557-
fts-core "^1.1.0"
3558-
fts-validator "^1.3.3"
3559-
inflation "^2.0.0"
3560-
is-stream "^1.1.0"
3561-
micro "^9.3.3"
3562-
micro-cors "^0.1.1"
3563-
mime-types "^2.1.24"
3564-
multiparty "^4.2.1"
3565-
parseurl "^1.3.2"
3566-
qs "^6.6.0"
3567-
raw-body "^2.4.1"
3568-
resolve "^1.10.0"
3569-
type-is "^1.6.16"
3570-
urlencoded-body-parser "^3.0.0"
3571-
3572-
"fts-validator@link:packages/fts-validator":
3573-
version "1.3.3"
3574-
dependencies:
3575-
ajv "^6.7.0"
3576-
clone-deep "^4.0.1"
3577-
3578-
"fts@link:packages/fts":
3579-
version "0.0.0"
3580-
uid ""
3581-
35823542
function-bind@^1.0.2, function-bind@^1.1.1:
35833543
version "1.1.1"
35843544
resolved "https://registry.yarnpkg.com/function-bind/-/function-bind-1.1.1.tgz#a56899d3ea3c9bab874bb9773b7c5ede92f4895d"
@@ -4154,11 +4114,6 @@ indent-string@^3.0.0, indent-string@^3.2.0:
41544114
resolved "https://registry.yarnpkg.com/indent-string/-/indent-string-3.2.0.tgz#4a5fd6d27cc332f37e5419a504dbb837105c9289"
41554115
integrity sha1-Sl/W0nzDMvN+VBmlBNu4NxBckok=
41564116

4157-
inflation@^2.0.0:
4158-
version "2.0.0"
4159-
resolved "https://registry.yarnpkg.com/inflation/-/inflation-2.0.0.tgz#8b417e47c28f925a45133d914ca1fd389107f30f"
4160-
integrity sha1-i0F+R8KPklpFEz2RTKH9OJEH8w8=
4161-
41624117
inflight@^1.0.4:
41634118
version "1.0.6"
41644119
resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9"

0 commit comments

Comments
 (0)