module.exports = handler

const debug = require('../debug')
const error = require('../http-error')
const ldpCopy = require('../ldp-copy')
const utils = require('../utils')

/**
 * Handles HTTP COPY requests to import a given resource (specified in the
 * `Source:` header) to a destination (specified in request path).
 * For the moment, you can copy from public resources only (no auth delegation
 * is implemented), and is mainly intended for use with
 * "Save an external resource to Solid" type apps.
 * @method handler
 */
function handler (req, res, next) {
  const copyFrom = req.header('Source')
  if (!copyFrom) {
    return next(error(400, 'Source header required'))
  }
  const serverRoot = utils.uriBase(req)
  const copyFromUrl = serverRoot + copyFrom
  const copyTo = res.locals.path || req.path
  const copyToPath = utils.reqToPath(req)
  ldpCopy(copyToPath, copyFromUrl, function (err) {
    if (err) {
      let statusCode = err.statusCode || 500
      let errorMessage = err.statusMessage || err.message
      debug.handlers('Error with COPY request:' + errorMessage)
      return next(error(statusCode, errorMessage))
    }
    res.set('Location', copyTo)
    res.sendStatus(201)
    return next()
  })
}

@@ -164,16 +164,43 @@
 /utils')
+%0Aconst url = require('url')
 %0A%0A/**%0A *
@@ -701,16 +701,70 @@
 '))%0A  %7D%0A
+  const fromExternal = !!url.parse(copyFrom).hostname%0A
   const 
@@ -816,16 +816,42 @@
 romUrl =
+ fromExternal ? copyFrom :
  serverR

Add support for copying external resources (#477)