forked from j62/ctbrec
1
0
Fork 0

Add cache control headers to Cam4 requests

This commit is contained in:
0xb00bface 2020-12-21 15:07:50 +01:00
parent e90ef22fa1
commit 43d8b9d2de
2 changed files with 14 additions and 1 deletions

View File

@ -4,12 +4,15 @@ public class HttpConstants {
public static final String ACCEPT = "Accept";
public static final String ACCEPT_LANGUAGE = "Accept-Language";
public static final String CACHE_CONTROL = "Cache-Control";
public static final String CONNECTION = "Connection";
public static final String CONTENT_TYPE = "Content-Type";
public static final String COOKIE = "Cookie";
public static final String KEEP_ALIVE = "keep-alive";
public static final String MIMETYPE_APPLICATION_JSON = "application/json";
public static final String NO_CACHE = "no-cache";
public static final String ORIGIN = "Origin";
public static final String PRAGMA = "Pragma";
public static final String REFERER = "Referer";
public static final String USER_AGENT = "User-Agent";
public static final String XML_HTTP_REQUEST = "XMLHttpRequest";

View File

@ -141,6 +141,8 @@ public class Cam4Model extends AbstractModel {
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.header(ACCEPT, "*/*")
.header(ACCEPT_LANGUAGE, "*")
.header(CACHE_CONTROL, NO_CACHE)
.header(PRAGMA, NO_CACHE)
.header(REFERER, getUrl())
.build(); // @formatter:on
try (Response response = site.getHttpClient().execute(req)) {
@ -161,7 +163,15 @@ public class Cam4Model extends AbstractModel {
}
private String loadModelPage() throws IOException {
Request req = new Request.Builder().url(getUrl()).build();
Request req = new Request.Builder()
.url(getUrl())
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
.header(ACCEPT, "text/html")
.header(ACCEPT_LANGUAGE, "en")
.header(CACHE_CONTROL, NO_CACHE)
.header(PRAGMA, NO_CACHE)
.header(REFERER, site.getBaseUrl())
.build();
try (Response response = site.getHttpClient().execute(req)) {
if (response.isSuccessful()) {
return response.body().string();