mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 21:00:16 +02:00
fix: re-enable content length header for book downloads
this will allow progress bar to be displayed in clients
This commit is contained in:
parent
73949d514e
commit
535c6d7eca
2 changed files with 27 additions and 9 deletions
|
|
@ -3,18 +3,35 @@ package org.gotson.komga.infrastructure.web
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean
|
import org.springframework.boot.web.servlet.FilterRegistrationBean
|
||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
|
import org.springframework.http.server.PathContainer
|
||||||
import org.springframework.web.filter.ShallowEtagHeaderFilter
|
import org.springframework.web.filter.ShallowEtagHeaderFilter
|
||||||
|
import org.springframework.web.util.pattern.PathPatternParser
|
||||||
|
import javax.servlet.http.HttpServletRequest
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
class EtagFilterConfiguration {
|
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
|
@Bean
|
||||||
fun shallowEtagHeaderFilter(): FilterRegistrationBean<ShallowEtagHeaderFilter> =
|
fun shallowEtagHeaderFilter(): FilterRegistrationBean<out ShallowEtagHeaderFilter> =
|
||||||
FilterRegistrationBean(ShallowEtagHeaderFilter())
|
FilterRegistrationBean(
|
||||||
.also {
|
object : ShallowEtagHeaderFilter() {
|
||||||
it.addUrlPatterns(
|
override fun shouldNotFilter(request: HttpServletRequest): Boolean {
|
||||||
"/api/*",
|
val path = PathContainer.parsePath(request.servletPath)
|
||||||
"/opds/*",
|
return excludePatterns.any { it.matches(path) }
|
||||||
)
|
}
|
||||||
it.setName("etagFilter")
|
},
|
||||||
}
|
).also {
|
||||||
|
it.addUrlPatterns(
|
||||||
|
"/api/*",
|
||||||
|
"/opds/*",
|
||||||
|
)
|
||||||
|
it.setName("etagFilter")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -391,6 +391,7 @@ class BookController(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.contentType(getMediaTypeOrDefault(media.mediaType))
|
.contentType(getMediaTypeOrDefault(media.mediaType))
|
||||||
|
.contentLength(this.contentLength())
|
||||||
.body(stream)
|
.body(stream)
|
||||||
}
|
}
|
||||||
} catch (ex: FileNotFoundException) {
|
} catch (ex: FileNotFoundException) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue