1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 00:59:24 -05:00

fix(ext/http): patch regression in variadic args to serve handler (#20796)

I'm not sure what was the purpose of trying to be so clever with the
args were (maybe an optimization?), but it breaks variadic args as
pointed out in #20054.

Signed-off-by: Matt Mastracci <matthew@mastracci.com>
Co-authored-by: Matt Mastracci <matthew@mastracci.com>
This commit is contained in:
Jared Flatow 2023-10-27 04:34:41 -07:00 committed by GitHub
parent 9ec18c35c7
commit 33565e16ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -435,8 +435,6 @@ function fastSyncResponseOrStream(req, respBody, status) {
*/
function mapToCallback(context, callback, onError) {
const signal = context.abortController.signal;
const hasCallback = callback.length > 0;
const hasOneCallback = callback.length === 1;
return async function (req) {
// Get the response from the user-provided callback. If that fails, use onError. If that fails, return a fallback
@ -444,20 +442,11 @@ function mapToCallback(context, callback, onError) {
let innerRequest;
let response;
try {
if (hasCallback) {
innerRequest = new InnerRequest(req, context);
const request = fromInnerRequest(innerRequest, signal, "immutable");
if (hasOneCallback) {
response = await callback(request);
} else {
response = await callback(
request,
new ServeHandlerInfo(innerRequest),
);
}
} else {
response = await callback();
}
innerRequest = new InnerRequest(req, context);
response = await callback(
fromInnerRequest(innerRequest, signal, "immutable"),
new ServeHandlerInfo(innerRequest),
);
} catch (error) {
try {
response = await onError(error);