mirror of
https://gitlab.com/mangadex-pub/mangadex_at_home.git
synced 2024-01-19 02:48:37 +00:00
Merge branch 'feature/x-cache-header' into 'master'
Added X-Cache header to image responses See merge request mangadex/mangadex_at_home!20
This commit is contained in:
commit
4986bfb003
|
@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
### Added
|
### Added
|
||||||
- [2020-06-13] Allow for the two log levels to be configurable by [@lflare].
|
- [2020-06-13] Allow for the two log levels to be configurable by [@lflare].
|
||||||
|
- [2020-06-13] Added X-Cache header to image responses by [@lflare].
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- [2020-06-13] Modified AsyncAppender queue size to 1024 by [@lflare].
|
- [2020-06-13] Modified AsyncAppender queue size to 1024 by [@lflare].
|
||||||
|
|
|
@ -85,7 +85,7 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
|
||||||
statistics.get().requestsServed.incrementAndGet()
|
statistics.get().requestsServed.incrementAndGet()
|
||||||
|
|
||||||
// Netty doesn't do Content-Length or Content-Type, so we have the pleasure of doing that ourselves
|
// Netty doesn't do Content-Length or Content-Type, so we have the pleasure of doing that ourselves
|
||||||
fun respondWithImage(input: InputStream, length: String?, type: String, lastModified: String?): Response =
|
fun respondWithImage(input: InputStream, length: String?, type: String, lastModified: String?, cached: Boolean): Response =
|
||||||
Response(Status.OK)
|
Response(Status.OK)
|
||||||
.header("Content-Type", type)
|
.header("Content-Type", type)
|
||||||
.header("X-Content-Type-Options", "nosniff")
|
.header("X-Content-Type-Options", "nosniff")
|
||||||
|
@ -108,6 +108,13 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.let {
|
||||||
|
if (cached != null && cached == true) {
|
||||||
|
it.header("X-Cache", "HIT")
|
||||||
|
} else {
|
||||||
|
it.header("X-Cache", "MISS")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val snapshot = cache.get(cacheId)
|
val snapshot = cache.get(cacheId)
|
||||||
if (snapshot != null) {
|
if (snapshot != null) {
|
||||||
|
@ -131,7 +138,8 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
|
||||||
|
|
||||||
respondWithImage(
|
respondWithImage(
|
||||||
CipherInputStream(BufferedInputStream(snapshot.getInputStream(0)), getRc4(rc4Bytes)),
|
CipherInputStream(BufferedInputStream(snapshot.getInputStream(0)), getRc4(rc4Bytes)),
|
||||||
snapshot.getLength(0).toString(), snapshot.getString(1), snapshot.getString(2)
|
snapshot.getLength(0).toString(), snapshot.getString(1), snapshot.getString(2),
|
||||||
|
true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -187,14 +195,14 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
|
||||||
editor.abort()
|
editor.abort()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
respondWithImage(tee, contentLength, contentType, lastModified)
|
respondWithImage(tee, contentLength, contentType, lastModified, false)
|
||||||
} else {
|
} else {
|
||||||
editor?.abort()
|
editor?.abort()
|
||||||
|
|
||||||
if (LOGGER.isTraceEnabled) {
|
if (LOGGER.isTraceEnabled) {
|
||||||
LOGGER.trace("Request for $sanitizedUri is being served")
|
LOGGER.trace("Request for $sanitizedUri is being served")
|
||||||
}
|
}
|
||||||
respondWithImage(mdResponse.body.stream, contentLength, contentType, lastModified)
|
respondWithImage(mdResponse.body.stream, contentLength, contentType, lastModified, false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue