(req, res, next)
| 12 | * @method handler |
| 13 | */ |
| 14 | export default async function handler (req, res, next) { |
| 15 | const copyFrom = req.header('Source') |
| 16 | if (!copyFrom) { |
| 17 | return next(HTTPError(400, 'Source header required')) |
| 18 | } |
| 19 | const fromExternal = !!parse(copyFrom).hostname |
| 20 | const ldp = req.app.locals.ldp |
| 21 | const serverRoot = ldp.resourceMapper.resolveUrl(req.hostname) |
| 22 | const copyFromUrl = fromExternal ? copyFrom : serverRoot + copyFrom |
| 23 | const copyToUrl = res.locals.path || req.path |
| 24 | try { |
| 25 | await ldpCopy(ldp.resourceMapper, copyToUrl, copyFromUrl) |
| 26 | } catch (err) { |
| 27 | const statusCode = err.statusCode || 500 |
| 28 | const errorMessage = err.statusMessage || err.message |
| 29 | debug.handlers('Error with COPY request:' + errorMessage) |
| 30 | return next(HTTPError(statusCode, errorMessage)) |
| 31 | } |
| 32 | res.set('Location', copyToUrl) |
| 33 | res.sendStatus(201) |
| 34 | next() |
| 35 | } |
nothing calls this directly
no test coverage detected