From 4877c04054b274d8db9c7cc73f337cc8120126b9 Mon Sep 17 00:00:00 2001 From: Fabian Engelniederhammer Date: Mon, 26 Feb 2024 16:46:31 +0100 Subject: [PATCH] feat: make headers accessible to browser despite CORS --- .../main/kotlin/org/genspectrum/lapis/CorsConfiguration.kt | 4 ++++ .../org/genspectrum/lapis/controller/ExceptionHandler.kt | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/CorsConfiguration.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/CorsConfiguration.kt index 1bd66151..03415bbc 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/CorsConfiguration.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/CorsConfiguration.kt @@ -1,6 +1,9 @@ package org.genspectrum.lapis +import org.genspectrum.lapis.openApi.REQUEST_ID_HEADER +import org.genspectrum.lapis.request.LAPIS_DATA_VERSION_HEADER import org.springframework.context.annotation.Configuration +import org.springframework.http.HttpHeaders.RETRY_AFTER import org.springframework.web.servlet.config.annotation.CorsRegistry import org.springframework.web.servlet.config.annotation.WebMvcConfigurer @@ -11,6 +14,7 @@ class CorsConfiguration : WebMvcConfigurer { .allowedOrigins("*") .allowedMethods("GET", "POST", "OPTIONS") .allowedHeaders("*") + .exposedHeaders(LAPIS_DATA_VERSION_HEADER, REQUEST_ID_HEADER, RETRY_AFTER) .maxAge(3600) } } diff --git a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ExceptionHandler.kt b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ExceptionHandler.kt index a17341d7..31915ea8 100644 --- a/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ExceptionHandler.kt +++ b/lapis2/src/main/kotlin/org/genspectrum/lapis/controller/ExceptionHandler.kt @@ -5,6 +5,7 @@ import org.genspectrum.lapis.model.SiloNotImplementedError import org.genspectrum.lapis.silo.SiloException import org.genspectrum.lapis.silo.SiloUnavailableException import org.springframework.core.annotation.Order +import org.springframework.http.HttpHeaders.RETRY_AFTER import org.springframework.http.HttpStatus import org.springframework.http.HttpStatusCode import org.springframework.http.MediaType @@ -85,7 +86,7 @@ class ExceptionHandler : ResponseEntityExceptionHandler() { fun handleSiloUnavailableException(e: SiloUnavailableException): ErrorResponse { log.warn(e) { "Caught SiloUnavailableException: ${e.message}" } - return responseEntity(HttpStatus.SERVICE_UNAVAILABLE, e.message) { header("Retry-After", e.retryAfter) } + return responseEntity(HttpStatus.SERVICE_UNAVAILABLE, e.message) { header(RETRY_AFTER, e.retryAfter) } } private fun responseEntity(