fix: Expose Location header via CORS.

Fixes https://github.com/solid/community-server/issues/441
This commit is contained in:
Ruben Verborgh 2020-12-27 15:15:55 +01:00
parent af8524e0d6
commit a5c372c37c
2 changed files with 8 additions and 1 deletions

View File

@ -17,6 +17,7 @@
"DELETE" "DELETE"
], ],
"CorsHandler:_options_exposedHeaders": [ "CorsHandler:_options_exposedHeaders": [
"Location",
"Updates-Via" "Updates-Via"
] ]
}, },

View File

@ -11,7 +11,7 @@ const port = 6002;
class SimpleHttpHandler extends HttpHandler { class SimpleHttpHandler extends HttpHandler {
public async handle(input: { request: HttpRequest; response: HttpResponse }): Promise<void> { public async handle(input: { request: HttpRequest; response: HttpResponse }): Promise<void> {
input.response.writeHead(200); input.response.writeHead(200, { location: '/' });
input.response.end('Hello World'); input.response.end('Hello World');
} }
} }
@ -65,6 +65,12 @@ describe('An Express server with middleware', (): void => {
expect(res.header).toEqual(expect.objectContaining({ 'access-control-allow-origin': 'test.com' })); expect(res.header).toEqual(expect.objectContaining({ 'access-control-allow-origin': 'test.com' }));
}); });
it('exposes the Location header via CORS.', async(): Promise<void> => {
const res = await request(server).get('/').expect(200);
const exposed = res.header['access-control-expose-headers'];
expect(exposed.split(/\s*,\s*/u)).toContain('Location');
});
it('sends incoming requests to the handler.', async(): Promise<void> => { it('sends incoming requests to the handler.', async(): Promise<void> => {
const response = request(server).get('/').set('Host', 'test.com'); const response = request(server).get('/').set('Host', 'test.com');
expect(response).toBeDefined(); expect(response).toBeDefined();