uppy/e2e/mock-server.mjs
Artur Paikin d979f5cf91
@uppy/companion: Use filename from content-disposition instead of relying on url, with fallback (#4489)
* Use filename from content-disposition instead of relying on url, with fallback

* Update packages/@uppy/companion/src/server/helpers/request.js

* Update packages/@uppy/companion/src/server/helpers/request.js

* Add random string to file name coming from basename in case ?param is a differentiator

* Add e2e test for Companion /url/meta file name + mock server with Content-Disposition

Co-authored-by: Antoine du Hamel <antoine@transloadit.com>

* Update e2e/cypress/integration/dashboard-xhr.spec.ts

Co-authored-by: Mikael Finstad <finstaden@gmail.com>

* Update e2e/mock-server.mjs

Co-authored-by: Antoine du Hamel <antoine@transloadit.com>

* Update package.json

Co-authored-by: Antoine du Hamel <antoine@transloadit.com>

* Update e2e/mock-server.mjs

Co-authored-by: Antoine du Hamel <antoine@transloadit.com>

* Update e2e/cypress/integration/dashboard-xhr.spec.ts

Co-authored-by: Mikael Finstad <finstaden@gmail.com>

* Add comment about why randomUUID is added to file name

* yarn

* res vs response

---------

Co-authored-by: Antoine du Hamel <antoine@transloadit.com>
Co-authored-by: Mikael Finstad <finstaden@gmail.com>
2023-06-09 19:22:20 +01:00

30 lines
849 B
JavaScript

import http from 'node:http'
const requestListener = (req, res) => {
const endpoint = req.url
switch (endpoint) {
case '/file-with-content-disposition': {
const fileName = `DALL·E IMG_9078 - 学中文 🤑`
res.setHeader('Content-Disposition', `attachment; filename="ASCII-name.zip"; filename*=UTF-8''${encodeURIComponent(fileName)}`)
res.setHeader('Content-Type', 'image/jpeg')
res.setHeader('Content-Length', '86500')
break
}
case '/file-no-headers':
break
default:
res.writeHead(404).end('Unhandled request')
}
res.end()
}
export default function startMockServer (host, port) {
const server = http.createServer(requestListener)
server.listen(port, host, () => {
console.log(`Server is running on http://${host}:${port}`)
})
}
// startMockServer('localhost', 4678)