Skip to content

Commit

Permalink
fix: re-enable content length header for book downloads
Browse files Browse the repository at this point in the history
this will allow progress bar to be displayed in clients
  • Loading branch information
Snd-R committed Jun 30, 2022
1 parent 73949d5 commit 535c6d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
Expand Up @@ -3,18 +3,35 @@ package org.gotson.komga.infrastructure.web
import org.springframework.boot.web.servlet.FilterRegistrationBean
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.server.PathContainer
import org.springframework.web.filter.ShallowEtagHeaderFilter
import org.springframework.web.util.pattern.PathPatternParser
import javax.servlet.http.HttpServletRequest

@Configuration
class EtagFilterConfiguration {

private val excludePatterns = listOf(
PathPatternParser.defaultInstance.parse("/api/v1/books/*/file/**"),
PathPatternParser.defaultInstance.parse("/opds/v1.2/books/*/file/**"),
PathPatternParser.defaultInstance.parse("/api/v1/readlists/*/file/**"),
PathPatternParser.defaultInstance.parse("/api/v1/series/*/file/**"),
)

@Bean
fun shallowEtagHeaderFilter(): FilterRegistrationBean<ShallowEtagHeaderFilter> =
FilterRegistrationBean(ShallowEtagHeaderFilter())
.also {
it.addUrlPatterns(
"/api/*",
"/opds/*",
)
it.setName("etagFilter")
}
fun shallowEtagHeaderFilter(): FilterRegistrationBean<out ShallowEtagHeaderFilter> =
FilterRegistrationBean(
object : ShallowEtagHeaderFilter() {
override fun shouldNotFilter(request: HttpServletRequest): Boolean {
val path = PathContainer.parsePath(request.servletPath)
return excludePatterns.any { it.matches(path) }
}
},
).also {
it.addUrlPatterns(
"/api/*",
"/opds/*",
)
it.setName("etagFilter")
}
}
Expand Up @@ -391,6 +391,7 @@ class BookController(
},
)
.contentType(getMediaTypeOrDefault(media.mediaType))
.contentLength(this.contentLength())
.body(stream)
}
} catch (ex: FileNotFoundException) {
Expand Down

0 comments on commit 535c6d7

Please sign in to comment.