|
4 | 4 | * you may not use this file except in compliance with the Elastic License. |
5 | 5 | */ |
6 | 6 | import { TypeOf } from '@kbn/config-schema'; |
7 | | -import { RequestHandler, CustomHttpResponseOptions } from 'src/core/server'; |
| 7 | +import { RequestHandler, ResponseHeaders, KnownHeaders } from 'src/core/server'; |
8 | 8 | import { |
9 | 9 | GetInfoResponse, |
10 | 10 | InstallPackageResponse, |
@@ -103,15 +103,21 @@ export const getFileHandler: RequestHandler<TypeOf<typeof GetFileRequestSchema.p |
103 | 103 | try { |
104 | 104 | const { pkgName, pkgVersion, filePath } = request.params; |
105 | 105 | const registryResponse = await getFile(`/package/${pkgName}/${pkgVersion}/${filePath}`); |
106 | | - const contentType = registryResponse.headers.get('Content-Type'); |
107 | | - const customResponseObj: CustomHttpResponseOptions<typeof registryResponse.body> = { |
| 106 | + |
| 107 | + const headersToProxy: KnownHeaders[] = ['content-type', 'cache-control']; |
| 108 | + const proxiedHeaders = headersToProxy.reduce((headers, knownHeader) => { |
| 109 | + const value = registryResponse.headers.get(knownHeader); |
| 110 | + if (value !== null) { |
| 111 | + headers[knownHeader] = value; |
| 112 | + } |
| 113 | + return headers; |
| 114 | + }, {} as ResponseHeaders); |
| 115 | + |
| 116 | + return response.custom({ |
108 | 117 | body: registryResponse.body, |
109 | 118 | statusCode: registryResponse.status, |
110 | | - }; |
111 | | - if (contentType !== null) { |
112 | | - customResponseObj.headers = { 'Content-Type': contentType }; |
113 | | - } |
114 | | - return response.custom(customResponseObj); |
| 119 | + headers: proxiedHeaders, |
| 120 | + }); |
115 | 121 | } catch (error) { |
116 | 122 | return defaultIngestErrorHandler({ error, response }); |
117 | 123 | } |
|
0 commit comments