Skip to content

Commit 2dfa0f2

Browse files
author
John Schulz
committed
Forward any registry cache-control header for files
1 parent cc0d6c1 commit 2dfa0f2

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

x-pack/plugins/fleet/server/routes/epm/handlers.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66
import { TypeOf } from '@kbn/config-schema';
7-
import { RequestHandler, CustomHttpResponseOptions } from 'src/core/server';
7+
import { RequestHandler, ResponseHeaders, KnownHeaders } from 'src/core/server';
88
import {
99
GetInfoResponse,
1010
InstallPackageResponse,
@@ -103,15 +103,21 @@ export const getFileHandler: RequestHandler<TypeOf<typeof GetFileRequestSchema.p
103103
try {
104104
const { pkgName, pkgVersion, filePath } = request.params;
105105
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({
108117
body: registryResponse.body,
109118
statusCode: registryResponse.status,
110-
};
111-
if (contentType !== null) {
112-
customResponseObj.headers = { 'Content-Type': contentType };
113-
}
114-
return response.custom(customResponseObj);
119+
headers: proxiedHeaders,
120+
});
115121
} catch (error) {
116122
return defaultIngestErrorHandler({ error, response });
117123
}

0 commit comments

Comments
 (0)