Skip to content

Commit

Permalink
fixup! feat: also enable returning TSV #284
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Aug 4, 2023
1 parent f2ef102 commit 9253695
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import jakarta.servlet.http.HttpServletRequestWrapper
import jakarta.servlet.http.HttpServletResponse
import mu.KotlinLogging
import org.genspectrum.lapis.util.CachedBodyHttpServletRequest
import org.springframework.http.MediaType
import org.springframework.stereotype.Component
import org.springframework.web.filter.OncePerRequestFilter
import java.util.Collections
Expand Down Expand Up @@ -39,15 +40,20 @@ class AcceptHeaderModifyingRequestWrapper(
if (name.equals("Accept", ignoreCase = true)) {
when (reReadableRequest.getRequestFields()[FORMAT_PROPERTY]?.textValue()?.uppercase()) {
"CSV" -> {
log.debug { "Overwriting Accept header to text/csv due to format property" }
log.debug { "Overwriting Accept header to $TEXT_CSV_HEADER due to format property" }
return TEXT_CSV_HEADER
}

"TSV" -> {
log.debug { "Overwriting Accept header to text/csv due to format property" }
log.debug { "Overwriting Accept header to $TEXT_TSV_HEADER due to format property" }
return TEXT_TSV_HEADER
}

"JSON" -> {
log.debug { "Overwriting Accept header to ${MediaType.APPLICATION_JSON_VALUE} due to format property" }
return MediaType.APPLICATION_JSON_VALUE
}

else -> {}
}
}
Expand All @@ -59,15 +65,20 @@ class AcceptHeaderModifyingRequestWrapper(
if (name.equals("Accept", ignoreCase = true)) {
when (reReadableRequest.getRequestFields()[FORMAT_PROPERTY]?.textValue()?.uppercase()) {
"CSV" -> {
log.debug { "Overwriting Accept header to text/csv due to format property" }
log.debug { "Overwriting Accept header to $TEXT_CSV_HEADER due to format property" }
return Collections.enumeration(listOf(TEXT_CSV_HEADER))
}

"TSV" -> {
log.debug { "Overwriting Accept header to text/csv due to format property" }
log.debug { "Overwriting Accept header to $TEXT_TSV_HEADER due to format property" }
return Collections.enumeration(listOf(TEXT_TSV_HEADER))
}

"JSON" -> {
log.debug { "Overwriting Accept header to ${MediaType.APPLICATION_JSON_VALUE} due to format property" }
return Collections.enumeration(listOf(MediaType.APPLICATION_JSON_VALUE))
}

else -> {}
}
}
Expand Down

0 comments on commit 9253695

Please sign in to comment.