From 153d2d9fe44a8993da94ebc513e7b520f0b7eea8 Mon Sep 17 00:00:00 2001 From: Ruben Verborgh Date: Tue, 26 Jan 2021 10:30:05 +0100 Subject: [PATCH] feat: Set Accept-Patch header. --- config/presets/ldp/response-writer.json | 4 ++++ config/presets/middleware.json | 1 + test/integration/LdpHandlerWithoutAuth.test.ts | 1 + test/integration/Middleware.test.ts | 6 ++++++ 4 files changed, 12 insertions(+) diff --git a/config/presets/ldp/response-writer.json b/config/presets/ldp/response-writer.json index 57c6b5183..3a474dd16 100644 --- a/config/presets/ldp/response-writer.json +++ b/config/presets/ldp/response-writer.json @@ -8,6 +8,10 @@ { "@type": "ConstantMetadataWriter", "ConstantMetadataWriter:_headers": [ + { + "ConstantMetadataWriter:_headers_key": "Accept-Patch", + "ConstantMetadataWriter:_headers_value": "application/sparql-update" + }, { "ConstantMetadataWriter:_headers_key": "MS-Author-Via", "ConstantMetadataWriter:_headers_value": "SPARQL" diff --git a/config/presets/middleware.json b/config/presets/middleware.json index e82f72ebf..6aa2c9be3 100644 --- a/config/presets/middleware.json +++ b/config/presets/middleware.json @@ -18,6 +18,7 @@ ], "CorsHandler:_options_credentials": true, "CorsHandler:_options_exposedHeaders": [ + "Accept-Patch", "Location", "MS-Author-Via", "Updates-Via" diff --git a/test/integration/LdpHandlerWithoutAuth.test.ts b/test/integration/LdpHandlerWithoutAuth.test.ts index cb137aa13..492f7ac67 100644 --- a/test/integration/LdpHandlerWithoutAuth.test.ts +++ b/test/integration/LdpHandlerWithoutAuth.test.ts @@ -81,6 +81,7 @@ describe.each(stores)('An LDP handler without auth using %s', (name, { storeUrn, expect(response.statusCode).toBe(200); expect(response._getBuffer().toString()).toContain('TESTFILE0'); expect(response.getHeaders().link).toBe(`<${LDP.Resource}>; rel="type"`); + expect(response.getHeaders()['accept-patch']).toBe('application/sparql-update'); expect(response.getHeaders()['ms-author-via']).toBe('SPARQL'); // DELETE diff --git a/test/integration/Middleware.test.ts b/test/integration/Middleware.test.ts index 19f569b0c..323260043 100644 --- a/test/integration/Middleware.test.ts +++ b/test/integration/Middleware.test.ts @@ -86,6 +86,12 @@ describe('An Express server with middleware', (): void => { expect(res.header).toEqual(expect.objectContaining({ 'access-control-allow-origin': 'test.com' })); }); + it('exposes the Accept-Patch header via CORS.', async(): Promise => { + const res = await request(server).get('/').expect(200); + const exposed = res.header['access-control-expose-headers']; + expect(exposed.split(/\s*,\s*/u)).toContain('Accept-Patch'); + }); + it('exposes the Location header via CORS.', async(): Promise => { const res = await request(server).get('/').expect(200); const exposed = res.header['access-control-expose-headers'];