Skip to content

Commit eb73ae2

Browse files
committed
Consistently call getContentType helper when needed
1 parent 868a975 commit eb73ae2

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

lib/handlers/patch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const error = require('../http-error')
99
const $rdf = require('rdflib')
1010
const crypto = require('crypto')
1111
const overQuota = require('../utils').overQuota
12+
const getContentType = require('../utils').getContentType
1213

1314
// Patch parsers by request body content type
1415
const PATCH_PARSERS = {
@@ -42,7 +43,7 @@ async function patchHandler (req, res, next) {
4243
const patch = {}
4344
patch.text = req.body ? req.body.toString() : ''
4445
patch.uri = `${url}#patch-${hash(patch.text)}`
45-
patch.contentType = (req.get('content-type') || '').match(/^[^;\s]*/)[0]
46+
patch.contentType = getContentType(req.headers)
4647
debug('PATCH -- Received patch (%d bytes, %s)', patch.text.length, patch.contentType)
4748
const parsePatch = PATCH_PARSERS[patch.contentType]
4849
if (!parsePatch) {

lib/handlers/post.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ const header = require('../header')
77
const patch = require('./patch')
88
const error = require('../http-error')
99
const { extensions } = require('mime-types')
10+
const getContentType = require('../utils').getContentType
1011

1112
async function handler (req, res, next) {
1213
const ldp = req.app.locals.ldp
13-
const contentType = req.get('content-type')
14+
const contentType = getContentType(req.headers)
1415
debug('content-type is ', contentType)
1516
// Handle SPARQL(-update?) query
1617
if (contentType === 'application/sparql' ||

lib/ldp-copy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const error = require('./http-error')
77
const path = require('path')
88
const http = require('http')
99
const https = require('https')
10+
const getContentType = require('./utils').getContentType
1011

1112
/**
1213
* Cleans up a file write stream (ends stream, deletes the file).
@@ -45,7 +46,7 @@ function copy (resourceMapper, copyToUri, copyFromUri) {
4546
return reject(error)
4647
}
4748
// Grab the content type from the source
48-
const contentType = response.headers['content-type']
49+
const contentType = getContentType(response.headers)
4950
resourceMapper.mapUrlToFile({ url: copyToUri, createIfNotExists: true, contentType })
5051
.then(({ path: copyToPath }) => {
5152
mkdirp(path.dirname(copyToPath), function (err) {

0 commit comments

Comments
 (0)