Skip to content

Commit

Permalink
fix(xo-server/vm.export): body does not have a headers prop
Browse files Browse the repository at this point in the history
  • Loading branch information
julien-f committed Apr 2, 2024
1 parent f9ca9e7 commit 0794a63
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Expand Up @@ -12,6 +12,7 @@
> Users must be able to say: “I had this issue, happy to know it's fixed”
- [REST API] Fix download of host's audit and logs broken in XO 5.93.0
- [VM] Fix `unknown error` on export (broken in XO 5.93.0)

### Packages to release

Expand Down
8 changes: 3 additions & 5 deletions packages/xo-server/src/api/vm.mjs
Expand Up @@ -16,7 +16,7 @@ import { Disposable, ignoreErrors, timeout } from 'promise-toolbox'
import { invalidParameters, noSuchObject, unauthorized } from 'xo-common/api-errors.js'
import { Ref } from 'xen-api'

import { forEach, map, mapFilter, parseSize, safeDateFormat } from '../utils.mjs'
import { forEach, map, mapFilter, noop, parseSize, safeDateFormat } from '../utils.mjs'
import { getSyncedHandler } from '@xen-orchestra/fs'

const log = createLogger('xo:vm')
Expand Down Expand Up @@ -1226,11 +1226,9 @@ async function handleExport(req, res, { xapi, vmRef, compress, format = 'xva' })
const stream =
format === 'ova' ? await xapi.exportVmOva(vmRef) : (await xapi.VM_export(FAIL_ON_QUEUE, vmRef, { compress })).body

res.on('close', () => stream.destroy())
// Remove the filename as it is already part of the URL.
stream.headers['content-disposition'] = 'attachment'
res.on('close', () => stream.on('error', noop).destroy())

res.writeHead(stream.statusCode, stream.statusMessage != null ? stream.statusMessage : '', stream.headers)
res.setHeader('content-disposition', 'attachment')
stream.pipe(res)
}

Expand Down

0 comments on commit 0794a63

Please sign in to comment.