1
0
Fork 1
mirror of https://gitlab.com/mangadex-pub/mangadex_at_home.git synced 2024-01-19 02:48:37 +00:00

Cache updates

This commit is contained in:
carbotaniuman 2020-06-06 22:34:43 -05:00
parent 198f790bed
commit 4238717460
4 changed files with 35 additions and 14 deletions

View file

@ -7,7 +7,7 @@ plugins {
}
group = 'com.mangadex'
version = '1.0.0-rc1'
version = '1.0.0-rc2'
mainClassName = 'mdnet.base.MangadexClient'
repositories {

View file

@ -48,6 +48,12 @@ public class MangadexClient {
public void runLoop() {
statistics.set(new Statistics());
loginAndStartServer();
if (serverSettings.getLatestBuild() > Constants.CLIENT_BUILD) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Outdated build detected! Latest: {}, Current: {}", serverSettings.getLatestBuild(),
Constants.CLIENT_BUILD);
}
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("MDNet initialization completed successfully. Starting normal operation.");
@ -94,19 +100,29 @@ public class MangadexClient {
}
ServerSettings n = serverHandler.pingControl(serverSettings);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Server settings received: {}", n);
}
if (n != null && (n.getTls() != null || !n.getImageServer().equals(serverSettings.getImageServer()))) {
// certificates or upstream url must have changed, restart webserver
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Doing internal restart of HTTP server to refresh certs/upstream URL");
if (n != null) {
if (n.getLatestBuild() > Constants.CLIENT_BUILD) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Outdated build detected! Latest: {}, Current: {}", n.getLatestBuild(),
Constants.CLIENT_BUILD);
}
}
synchronized (shutdownLock) {
logoutAndStopServer();
loginAndStartServer();
if (n.getTls() != null || !n.getImageServer().equals(serverSettings.getImageServer())) {
// certificates or upstream url must have changed, restart webserver
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Doing internal restart of HTTP server to refresh certs/upstream URL");
}
synchronized (shutdownLock) {
logoutAndStopServer();
loginAndStartServer();
}
}
}
}, 45, 45, TimeUnit.SECONDS);

View file

@ -8,10 +8,13 @@ public final class ServerSettings {
@SerializedName("image_server")
private final String imageServer;
private final TlsCert tls;
@SerializedName("latest_build")
private final int latestBuild;
public ServerSettings(String imageServer, TlsCert tls) {
public ServerSettings(String imageServer, TlsCert tls, int latestBuild) {
this.imageServer = Objects.requireNonNull(imageServer);
this.tls = tls;
this.latestBuild = latestBuild;
}
public String getImageServer() {
@ -22,9 +25,14 @@ public final class ServerSettings {
return tls;
}
public int getLatestBuild() {
return latestBuild;
}
@Override
public String toString() {
return "ServerSettings{" + "imageServer='" + imageServer + '\'' + ", tls=" + "<hidden>" + '}';
return "ServerSettings{" + "imageServer='" + imageServer + '\'' + ", tls=" + tls + ", latestBuild="
+ latestBuild + '}';
}
@Override

View file

@ -149,13 +149,10 @@ private val HTTP_TIME_FORMATTER = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy
private fun addCommonHeaders(): Filter {
return Filter { next: HttpHandler ->
{ request: Request ->
val now = ZonedDateTime.now(ZoneOffset.UTC)
val response = next(request)
response.header("Date", HTTP_TIME_FORMATTER.format(now))
response.header("Date", HTTP_TIME_FORMATTER.format(ZonedDateTime.now(ZoneOffset.UTC)))
.header("Server", "Mangadex@Home Node")
.header("Cache-Control", listOf("public", MaxAgeTtl(Constants.MAX_AGE_CACHE).toHeaderValue()).joinToString(", "))
.header("Expires", HTTP_TIME_FORMATTER.format(now.plusSeconds(Constants.MAX_AGE_CACHE.seconds)))
.header("Cache-Control", "public, max-age=604800") // 1 week browser cache
.header("Timing-Allow-Origin", "https://mangadex.org")
}
}