Skip to content

Commit 7d81d5d

Browse files
committed
better content type checking
1 parent cd3cff7 commit 7d81d5d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

apps/webapp/app/routes/otel.v1.logs.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { otlpExporter } from "~/v3/otlpExporter.server";
44

55
export async function action({ request }: ActionFunctionArgs) {
66
try {
7-
const contentType = request.headers.get("content-type");
7+
const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
88

9-
if (contentType === "application/json") {
9+
if (contentType.startsWith("application/json")) {
1010
const body = await request.json();
1111

1212
const exportResponse = await otlpExporter.exportLogs(body as ExportLogsServiceRequest);
1313

1414
return json(exportResponse, { status: 200 });
15-
} else if (contentType === "application/x-protobuf") {
15+
} else if (contentType.startsWith("application/x-protobuf")) {
1616
const buffer = await request.arrayBuffer();
1717

1818
const exportRequest = ExportLogsServiceRequest.decode(new Uint8Array(buffer));

apps/webapp/app/routes/otel.v1.traces.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { otlpExporter } from "~/v3/otlpExporter.server";
44

55
export async function action({ request }: ActionFunctionArgs) {
66
try {
7-
const contentType = request.headers.get("content-type");
7+
const contentType = request.headers.get("content-type")?.toLowerCase() ?? "";
88

9-
if (contentType === "application/json") {
9+
if (contentType.startsWith("application/json")) {
1010
const body = await request.json();
1111

1212
const exportResponse = await otlpExporter.exportTraces(body as ExportTraceServiceRequest);
1313

1414
return json(exportResponse, { status: 200 });
15-
} else if (contentType === "application/x-protobuf") {
15+
} else if (contentType.startsWith("application/x-protobuf")) {
1616
const buffer = await request.arrayBuffer();
1717

1818
const exportRequest = ExportTraceServiceRequest.decode(new Uint8Array(buffer));

0 commit comments

Comments
 (0)