Skip to content

Commit be003b0

Browse files
committed
Throw error when Content-Type is omitted
1 parent 865cbf6 commit be003b0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "labelzoom-cf-api-proxy",
33
"description": "A Cloudflare Worker that serves as a reverse proxy for LabelZoom's public REST API",
4-
"version": "1.2.6",
4+
"version": "1.2.7",
55
"private": true,
66
"dependencies": {
77
"hono": "4.9.12",

src/worker/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ app.get("/api/v2/convert/url/to/zpl/:url{.+}", (c) => proxy(c.req.param('url')))
7777
//#region All other conversions
7878
app.use("/api/v2/convert/:sourceFormat/to/:targetFormat", (c, next) => {
7979
return every(
80+
(c, next) => {
81+
if ((c.req.header('Content-Type') ?? '') === '') {
82+
throw new HTTPException(400, { message: 'Content-Type header is required' });
83+
}
84+
return next();
85+
},
8086
requestId({
8187
headerName: 'X-LZ-Request-Id',
8288
generator: () => new Date().toISOString().substring(0, 19).replaceAll('-', '/').replaceAll('T', '/').replaceAll(':', '') + '--' + crypto.randomUUID(),
@@ -85,7 +91,7 @@ app.use("/api/v2/convert/:sourceFormat/to/:targetFormat", (c, next) => {
8591
...c.req.param(),
8692
r2Bucket: c.env.LZ_R2_BUCKET,
8793
sampleRate: c.env.LZ_LOG_SAMPLE_RATE,
88-
})
94+
}),
8995
)(c, next);
9096
});
9197
//#endregion

src/worker/middleware/force-relative-redirects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const forceRelativeRedirects = (): MiddlewareHandler => {
1515
const url = new URL(locationHeader); // throws TypeError if not a full URL
1616

1717
// URL parsed successfully, it's an absolute redirect rather than relative
18-
if (/\.?labelzoom.net$/.test(url.host)) {
18+
if (/\.?labelzoom\.net$/i.test(url.host)) {
1919
c.res.headers.set('Location', url.pathname + url.search);
2020
}
2121
} catch {

0 commit comments

Comments
 (0)