Skip to content

Commit

Permalink
feat: make headers accessible to browser despite CORS
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Feb 26, 2024
1 parent 296d747 commit 4877c04
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4877c04

Please sign in to comment.