Fix envelope header parsing
This commit is contained in:
@@ -1,13 +1,19 @@
|
||||
import { jsonError } from "../common.js";
|
||||
|
||||
export async function onRequestPost(context: RequestContext) {
|
||||
const dsn = context.request.headers.get("dsn");
|
||||
const clonedRequest = context.request.clone();
|
||||
const header = (await context.request.text()).split("\n").at(0);
|
||||
|
||||
if (!dsn || dsn !== context.env.DSN) return jsonError("Bad or no DSN", 400);
|
||||
if (!header) return jsonError("Failed to parse envelope header", 500);
|
||||
|
||||
const { dsn } = JSON.parse(header);
|
||||
|
||||
if (context.env.DSN !== dsn) return jsonError("Bad or no DSN", 400);
|
||||
|
||||
const sentryUrl = new URL(dsn);
|
||||
|
||||
await fetch(`https://${sentryUrl.host}/api${sentryUrl.pathname}/envelope`, {
|
||||
body: context.request.body,
|
||||
body: clonedRequest.body,
|
||||
headers: {
|
||||
"content-type": "application/x-sentry-envelope",
|
||||
"x-forwarded-for": context.request.headers.get(
|
||||
|
||||
Reference in New Issue
Block a user