better error code for uploads without content-length
Massimo Melina committed
Mar 22, 2026 at 11:31 UTC
a6ad6c0ab771ab646abdea5ee00ca5b6b8cc612f
2 files changed
+4
-3
src/cross-const.ts
+1
@@ -30,6 +30,7 @@ export const HTTP_NOT_FOUND = 404
30
export const HTTP_METHOD_NOT_ALLOWED = 405
31
export const HTTP_NOT_ACCEPTABLE = 406
32
export const HTTP_CONFLICT = 409
33
+export const HTTP_LENGTH_REQUIRED = 411
34
export const HTTP_PRECONDITION_FAILED = 412
35
export const HTTP_PAYLOAD_TOO_LARGE = 413
36
export const HTTP_RANGE_NOT_SATISFIABLE = 416
src/upload.ts
+3
-3
@@ -1,8 +1,8 @@
1
import { getNodeByName, statusCodeForMissingPerm, VfsNode } from './vfs'
2
import Koa from 'koa'
3
import {
4
- HTTP_CONFLICT, HTTP_FOOL, HTTP_INSUFFICIENT_STORAGE, HTTP_RANGE_NOT_SATISFIABLE, HTTP_BAD_REQUEST, HTTP_NO_CONTENT,
5
- HTTP_PRECONDITION_FAILED, MTIME_CHECK, HTTP_SERVER_ERROR,
4
+ HTTP_CONFLICT, HTTP_FOOL, HTTP_INSUFFICIENT_STORAGE, HTTP_RANGE_NOT_SATISFIABLE, HTTP_NO_CONTENT, HTTP_SERVER_ERROR,
5
+ HTTP_PRECONDITION_FAILED, HTTP_LENGTH_REQUIRED, MTIME_CHECK,
6
} from './const'
7
import { basename, dirname, extname, join } from 'path'
8
import fs from 'fs'
@@ -77,7 +77,7 @@ export function uploadWriter(base: VfsNode, baseUri: string, filename: string, c
77
const stillToWrite = Math.max(contentLength, Number(ctx.query.partial) || 0) // ...the number is used to tell how much space we need (fullSize - offset)
78
if (isNaN(stillToWrite)) {
79
if (min)
80
- return fail(HTTP_BAD_REQUEST, 'content-length mandatory')
80
+ return fail(HTTP_LENGTH_REQUIRED)
81
}
82
else
83
try {