Skip to content

Commit 9ec1320

Browse files
authored
Merge pull request #1346 from bourgeoa/master
PUT copy body for contentType application/json
2 parents 18aea70 + 4610103 commit 9ec1320

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

lib/ldp.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,6 @@ class LDP {
156156
}
157157
// const { url: putUrl } = await this.resourceMapper.mapFileToUrl({ path: resourceUrl, hostname })
158158

159-
// HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
160-
// for JSON bodies. So, the stream needs to be reset
161-
if (contentType && contentType.includes('application/json')) {
162-
stream = intoStream(JSON.stringify(stream.body))
163-
}
164-
165159
await ldp.put(resourceUrl, stream, contentType)
166160
return URL.parse(originalUrl).path
167161
}
@@ -240,6 +234,11 @@ class LDP {
240234

241235
// Directory created, now write the file
242236
return withLock(path, { mustExist: false }, () => new Promise((resolve, reject) => {
237+
// HACK: the middleware in webid-oidc.js uses body-parser, thus ending the stream of data
238+
// for JSON bodies. So, the stream needs to be reset
239+
if (contentType.includes('application/json')) {
240+
stream = intoStream(JSON.stringify(stream.body))
241+
}
243242
const file = stream.pipe(fs.createWriteStream(path))
244243
file.on('error', function () {
245244
reject(error(500, 'Error writing data'))

0 commit comments

Comments
 (0)