diff --git a/x-pack/plugins/fleet/server/routes/epm/handlers.ts b/x-pack/plugins/fleet/server/routes/epm/handlers.ts index 1d221b8b1eead..ce03d0eeb3826 100644 --- a/x-pack/plugins/fleet/server/routes/epm/handlers.ts +++ b/x-pack/plugins/fleet/server/routes/epm/handlers.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ import { TypeOf } from '@kbn/config-schema'; -import { RequestHandler, CustomHttpResponseOptions } from 'src/core/server'; +import { RequestHandler, ResponseHeaders, KnownHeaders } from 'src/core/server'; import { GetInfoResponse, InstallPackageResponse, @@ -103,15 +103,21 @@ export const getFileHandler: RequestHandler = { + + const headersToProxy: KnownHeaders[] = ['content-type', 'cache-control']; + const proxiedHeaders = headersToProxy.reduce((headers, knownHeader) => { + const value = registryResponse.headers.get(knownHeader); + if (value !== null) { + headers[knownHeader] = value; + } + return headers; + }, {} as ResponseHeaders); + + return response.custom({ body: registryResponse.body, statusCode: registryResponse.status, - }; - if (contentType !== null) { - customResponseObj.headers = { 'Content-Type': contentType }; - } - return response.custom(customResponseObj); + headers: proxiedHeaders, + }); } catch (error) { return defaultIngestErrorHandler({ error, response }); }