Skip to content

Commit 0a958f2

Browse files
authored
Merge pull request #1323 from solid/fix/1316
Fix empty content type and body problem
2 parents ad8de1c + fbcb949 commit 0a958f2

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/ldp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class LDP {
158158

159159
// HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
160160
// for JSON bodies. So, the stream needs to be reset
161-
if (contentType.includes('application/json')) {
161+
if (contentType && contentType.includes('application/json')) {
162162
stream = intoStream(JSON.stringify(stream.body))
163163
}
164164

test/integration/http-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,27 @@ describe('HTTP APIs', function () {
559559
.expect(hasHeader('acl', suffixAcl))
560560
.expect(201, done)
561561
})
562+
it('should create new resource even if body is empty', function (done) {
563+
server.post('/post-tests/')
564+
.set('slug', 'post-resource-empty')
565+
.set('content-type', 'text/turtle')
566+
.expect(hasHeader('describedBy', suffixMeta))
567+
.expect(hasHeader('acl', suffixAcl))
568+
.expect('location', /.*\.ttl/)
569+
.expect(201, done)
570+
})
571+
it('should error with 415 if the body is empty and no content type is provided', function (done) {
572+
server.post('/post-tests/')
573+
.set('slug', 'post-resource-empty-fail')
574+
.expect(415, done)
575+
})
576+
it('should error with 415 if the body is provided but there is no content-type header', function (done) {
577+
server.post('/post-tests/')
578+
.set('slug', 'post-resource-rdf-no-content-type')
579+
.send(postRequest1Body)
580+
.set('content-type', '')
581+
.expect(415, done)
582+
})
562583
it('should create new resource even if no trailing / is in the target',
563584
function (done) {
564585
server.post('')

0 commit comments

Comments
 (0)