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' group = 'com.mangadex'
version = '1.0.0-rc1' version = '1.0.0-rc2'
mainClassName = 'mdnet.base.MangadexClient' mainClassName = 'mdnet.base.MangadexClient'
repositories { repositories {

View file

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

View file

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

View file

@ -149,13 +149,10 @@ private val HTTP_TIME_FORMATTER = DateTimeFormatter.ofPattern("EEE, dd MMM yyyy
private fun addCommonHeaders(): Filter { private fun addCommonHeaders(): Filter {
return Filter { next: HttpHandler -> return Filter { next: HttpHandler ->
{ request: Request -> { request: Request ->
val now = ZonedDateTime.now(ZoneOffset.UTC)
val response = next(request) 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("Server", "Mangadex@Home Node")
.header("Cache-Control", listOf("public", MaxAgeTtl(Constants.MAX_AGE_CACHE).toHeaderValue()).joinToString(", ")) .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") .header("Timing-Allow-Origin", "https://mangadex.org")
} }
} }