fix(xo-server/rest-api): VDI export via NBD

This commit is contained in:
Julien Fontanet
2023-07-12 10:18:45 +02:00
parent 696ee7dbe5
commit 0840b4c359
2 changed files with 14 additions and 2 deletions

View File

@@ -13,6 +13,8 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [REST API] Fix VDI export when NBD is enabled
### Packages to release
> When modifying a package, add it here with its release type.
@@ -32,6 +34,7 @@
- @xen-orchestra/backups minor
- @xen-orchestra/xapi major
- complex-matcher patch
- xo-server patch
- xo-web minor
<!--packages-end-->

View File

@@ -371,9 +371,18 @@ export default class RestApi {
wrap(async (req, res) => {
const stream = await req.xapiObject.$exportContent({ format: req.params.format })
stream.headers['content-disposition'] = 'attachment'
res.writeHead(stream.statusCode, stream.statusMessage != null ? stream.statusMessage : '', stream.headers)
// stream can be an HTTP response, in this case, extract interesting data
const { headers = {}, length, statusCode = 200, statusMessage = 'OK' } = stream
// Set the correct disposition
headers['content-disposition'] = 'attachment'
// expose the stream length if known
if (headers['content-length'] === undefined && length !== undefined) {
headers['content-length'] = length
}
res.writeHead(statusCode, statusMessage, headers)
await pipeline(stream, res)
})
)