mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
fix: Determine body presence according to RFC7230
Fixes https://github.com/solid/community-server/issues/121
This commit is contained in:
committed by
Joachim Van Herwegen
parent
ee3b847033
commit
a06a7ff685
@@ -17,10 +17,18 @@ export class RawBodyParser extends BodyParser {
|
||||
// Note that the only reason this is a union is in case the body is empty.
|
||||
// If this check gets moved away from the BodyParsers this union could be removed
|
||||
public async handle(input: HttpRequest): Promise<Representation | undefined> {
|
||||
if (!input.headers['content-type']) {
|
||||
// RFC7230, §3.3: The presence of a message body in a request
|
||||
// is signaled by a Content-Length or Transfer-Encoding header field.
|
||||
if (!input.headers['content-length'] && !input.headers['transfer-encoding']) {
|
||||
return;
|
||||
}
|
||||
|
||||
// While RFC7231 allows treating a body without content type as an octet stream,
|
||||
// such an omission likely signals a mistake, so force clients to make this explicit.
|
||||
if (!input.headers['content-type']) {
|
||||
throw new Error('An HTTP request body was passed without Content-Type header');
|
||||
}
|
||||
|
||||
return {
|
||||
binary: true,
|
||||
data: input,
|
||||
@@ -29,11 +37,11 @@ export class RawBodyParser extends BodyParser {
|
||||
}
|
||||
|
||||
private parseMetadata(input: HttpRequest): RepresentationMetadata {
|
||||
const mediaType = input.headers['content-type']!.split(';')[0];
|
||||
const contentType = /^[^;]*/u.exec(input.headers['content-type']!)![0];
|
||||
|
||||
const metadata: RepresentationMetadata = {
|
||||
raw: [],
|
||||
contentType: mediaType,
|
||||
contentType,
|
||||
};
|
||||
|
||||
const { link, slug } = input.headers;
|
||||
|
||||
Reference in New Issue
Block a user