diff --git a/lib/ldp.js b/lib/ldp.js index 76663685b..fcc40dbf7 100644 --- a/lib/ldp.js +++ b/lib/ldp.js @@ -158,7 +158,7 @@ class LDP { // HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data // for JSON bodies. So, the stream needs to be reset - if (contentType.includes('application/json')) { + if (contentType && contentType.includes('application/json')) { stream = intoStream(JSON.stringify(stream.body)) } diff --git a/test/integration/http-test.js b/test/integration/http-test.js index f1e70a1e3..1df460360 100644 --- a/test/integration/http-test.js +++ b/test/integration/http-test.js @@ -559,6 +559,27 @@ describe('HTTP APIs', function () { .expect(hasHeader('acl', suffixAcl)) .expect(201, done) }) + it('should create new resource even if body is empty', function (done) { + server.post('/post-tests/') + .set('slug', 'post-resource-empty') + .set('content-type', 'text/turtle') + .expect(hasHeader('describedBy', suffixMeta)) + .expect(hasHeader('acl', suffixAcl)) + .expect('location', /.*\.ttl/) + .expect(201, done) + }) + it('should error with 415 if the body is empty and no content type is provided', function (done) { + server.post('/post-tests/') + .set('slug', 'post-resource-empty-fail') + .expect(415, done) + }) + it('should error with 415 if the body is provided but there is no content-type header', function (done) { + server.post('/post-tests/') + .set('slug', 'post-resource-rdf-no-content-type') + .send(postRequest1Body) + .set('content-type', '') + .expect(415, done) + }) it('should create new resource even if no trailing / is in the target', function (done) { server.post('')