formacao
This commit is contained in:
+24
-23
@@ -62,8 +62,15 @@ var streamHandle = (app) => {
|
||||
var handle = (app, { isContentTypeBinary } = { isContentTypeBinary: void 0 }) => {
|
||||
return async (event, lambdaContext) => {
|
||||
const processor = getProcessor(event);
|
||||
const req = processor.createRequest(event);
|
||||
const requestContext = getRequestContext(event);
|
||||
let req, requestContext;
|
||||
try {
|
||||
req = processor.createRequest(event);
|
||||
requestContext = getRequestContext(event);
|
||||
} catch (error) {
|
||||
console.error("Error processing request:", error);
|
||||
const errorResponse = error instanceof TypeError ? new Response("Invalid request", { status: 400 }) : new Response("Internal Server Error", { status: 500 });
|
||||
return processor.createResult(event, errorResponse, { isContentTypeBinary });
|
||||
}
|
||||
const res = await app.fetch(req, {
|
||||
event,
|
||||
requestContext,
|
||||
@@ -102,7 +109,9 @@ var EventProcessor = class {
|
||||
method
|
||||
};
|
||||
if (event.body) {
|
||||
requestInit.body = event.isBase64Encoded ? decodeBase64(event.body) : event.body;
|
||||
const body = event.isBase64Encoded ? decodeBase64(event.body) : new TextEncoder().encode(event.body);
|
||||
requestInit.body = body;
|
||||
headers.set("content-length", body.length.toString());
|
||||
}
|
||||
return new Request(url, requestInit);
|
||||
}
|
||||
@@ -195,26 +204,22 @@ var EventV1Processor = class extends EventProcessor {
|
||||
return Object.entries(event.queryStringParameters || {}).filter(([, value]) => value).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value || "")}`).join("&");
|
||||
}
|
||||
}
|
||||
getCookies(event, headers) {
|
||||
getCookies(_event, _headers) {
|
||||
}
|
||||
getHeaders(event) {
|
||||
const headers = new Headers();
|
||||
this.getCookies(event, headers);
|
||||
if (event.headers) {
|
||||
for (const [k, v] of Object.entries(event.headers)) {
|
||||
if (v) {
|
||||
headers.set(k, sanitizeHeaderValue(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.multiValueHeaders) {
|
||||
for (const [k, values] of Object.entries(event.multiValueHeaders)) {
|
||||
if (values) {
|
||||
const foundK = headers.get(k);
|
||||
values.forEach((v) => {
|
||||
const sanitizedValue = sanitizeHeaderValue(v);
|
||||
return (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue);
|
||||
});
|
||||
values.forEach((v) => headers.append(k, sanitizeHeaderValue(v)));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (event.headers) {
|
||||
for (const [k, v] of Object.entries(event.headers)) {
|
||||
if (v && !headers.has(k)) {
|
||||
headers.set(k, sanitizeHeaderValue(v));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -274,7 +279,7 @@ var ALBProcessor = class extends EventProcessor {
|
||||
if (result.multiValueHeaders) {
|
||||
result.multiValueHeaders["set-cookie"] = cookies;
|
||||
} else {
|
||||
result.headers["set-cookie"] = cookies.join(", ");
|
||||
result.headers["set-cookie"] = cookies[0];
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -294,11 +299,7 @@ var LatticeV2Processor = class extends EventProcessor {
|
||||
if (event.headers) {
|
||||
for (const [k, values] of Object.entries(event.headers)) {
|
||||
if (values) {
|
||||
const foundK = headers.get(k);
|
||||
values.forEach((v) => {
|
||||
const sanitizedValue = sanitizeHeaderValue(v);
|
||||
return (!foundK || !foundK.includes(sanitizedValue)) && headers.append(k, sanitizedValue);
|
||||
});
|
||||
values.forEach((v) => headers.append(k, sanitizeHeaderValue(v)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,7 +310,7 @@ var LatticeV2Processor = class extends EventProcessor {
|
||||
setCookiesToResult(result, cookies) {
|
||||
result.headers = {
|
||||
...result.headers,
|
||||
"set-cookie": cookies.join(", ")
|
||||
"set-cookie": cookies
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user