Skip to content

Commit b259948

Browse files
🏘
1 parent df9b582 commit b259948

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

packages/fts-http/src/handler.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ export function createHttpHandler(
5050
// Note: it is inconvenient but important for this handler to not be async in
5151
// order to maximize compatibility with different Node.js server frameworks.
5252
const handler = (req: http.IncomingMessage, res: http.ServerResponse) => {
53+
if (opts.debug) {
54+
if (req.method !== 'OPTIONS') {
55+
console.log(req.method, req.url, req.headers)
56+
}
57+
}
58+
5359
const context = new HttpContext(req, res)
5460

5561
if (context.req.method === 'OPTIONS') {
@@ -157,7 +163,7 @@ async function getParams(
157163
)
158164
}
159165

160-
return getBody(context, debug)
166+
return getBody(context)
161167
}
162168
} else {
163169
let params: any = {}
@@ -225,7 +231,7 @@ async function getParams(
225231
limit: BODY_SIZE_LIMIT
226232
})
227233
} else {
228-
const body = await getBody(context, debug)
234+
const body = await getBody(context)
229235
return JSON.parse(body.toString('utf8'))
230236
}
231237
} else {
@@ -240,18 +246,15 @@ async function getParams(
240246
}
241247
}
242248

243-
async function getBody(context: HttpContext, debug: boolean): Promise<Buffer> {
244-
const opts: any = {}
249+
async function getBody(context: HttpContext): Promise<Buffer> {
250+
const opts: any = {
251+
limit: BODY_SIZE_LIMIT
252+
}
253+
245254
const len = context.req.headers['content-length']
246255
const encoding = context.req.headers['content-encoding'] || 'identity'
247256
if (len && encoding === 'identity') {
248257
opts.length = +len
249-
opts.limit = BODY_SIZE_LIMIT
250-
}
251-
252-
if (debug) {
253-
console.log(opts)
254-
console.log(context.req.headers)
255258
}
256259

257260
return (raw(inflate(context.req), opts) as unknown) as Promise<Buffer>

0 commit comments

Comments
 (0)