Skip to content

Commit a559238

Browse files
committed
Don't enforce https for streams
These don't support https.
1 parent 79f2423 commit a559238

4 files changed

Lines changed: 45 additions & 9 deletions

File tree

library/src/main/java/me/proxer/library/api/HttpsEnforcingInterceptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ class HttpsEnforcingInterceptor implements Interceptor {
1616
public Response intercept(final Chain chain) throws IOException {
1717
final Request request = chain.request();
1818

19-
if (ProxerUrls.hasProxerHost(request.url()) && !request.isHttps()) {
19+
final boolean appliesToUrl = ProxerUrls.hasProxerWebOrCdnHost(request.url())
20+
|| ProxerUrls.hasProxerMangaHost(request.url());
21+
22+
if (appliesToUrl && !request.isHttps()) {
2023
return chain.proceed(request.newBuilder()
2124
.url(request.url().newBuilder()
2225
.scheme("https")

library/src/main/java/me/proxer/library/util/ProxerUrls.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
@Accessors(fluent = true)
2020
public final class ProxerUrls {
2121

22-
private static final Pattern PROXER_SUB_HOST_PATTERN = Pattern
23-
.compile("(manga[0-9]+|(s[0-9]+\\.)?stream)\\.proxer\\.me");
22+
private static final Pattern PROXER_STREAM_HOST_PATTERN = Pattern.compile("(s[0-9]+\\.)?stream\\.proxer\\.me");
23+
private static final Pattern PROXER_MANGA_HOST_PATTERN = Pattern.compile("manga[0-9]+\\.proxer\\.me");
2424

2525
/**
2626
* Returns the base url for all web pages.
@@ -240,7 +240,27 @@ public HttpUrl captchaWeb(final Device device) {
240240
* Returns if the passed url has a valid host of proxer.
241241
*/
242242
public boolean hasProxerHost(final HttpUrl url) {
243-
return url.host().equals(webBase.host()) || url.host().equals(cdnBase.host())
244-
|| PROXER_SUB_HOST_PATTERN.matcher(url.host()).matches();
243+
return hasProxerWebOrCdnHost(url) || hasProxerStreamHost(url) || hasProxerMangaHost(url);
244+
}
245+
246+
/**
247+
* Returns if the passed url has a valid host of proxer or the proxer cdn..
248+
*/
249+
public boolean hasProxerWebOrCdnHost(final HttpUrl url) {
250+
return url.host().equals(webBase.host()) || url.host().equals(cdnBase.host());
251+
}
252+
253+
/**
254+
* Returns if the passed url has a valid proxer stream host.
255+
*/
256+
public boolean hasProxerStreamHost(final HttpUrl url) {
257+
return PROXER_STREAM_HOST_PATTERN.matcher(url.host()).matches();
258+
}
259+
260+
/**
261+
* Returns if the passed url has a valid proxer manga host.
262+
*/
263+
public boolean hasProxerMangaHost(final HttpUrl url) {
264+
return PROXER_MANGA_HOST_PATTERN.matcher(url.host()).matches();
245265
}
246266
}

library/src/test/java/me/proxer/library/api/HttpsEnforcingInterceptorTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,25 @@ public void testHttpsUpgradeCdn() throws IOException, InterruptedException {
3030
}
3131

3232
@Test
33-
public void testHttpsUpgradeSub() throws IOException, InterruptedException {
33+
public void testHttpsUpgradeManga() throws IOException, InterruptedException {
3434
server.enqueue(new MockResponse());
3535

3636
client.newCall(new Request.Builder().url("http://manga1.proxer.me").build()).execute();
3737

3838
assertThat(server.takeRequest().getRequestUrl().isHttps()).isEqualTo(true);
3939
}
4040

41+
@Test
42+
public void testHttpsStreamUntouched() throws IOException, InterruptedException {
43+
startHttpOnlyServer();
44+
45+
server.enqueue(new MockResponse());
46+
47+
client.newCall(new Request.Builder().url("http://stream.proxer.me").build()).execute();
48+
49+
assertThat(server.takeRequest().getRequestUrl().isHttps()).isEqualTo(false);
50+
}
51+
4152
@Test
4253
public void testHttpsUntouched() throws IOException, InterruptedException {
4354
server.enqueue(new MockResponse());

library/src/test/java/me/proxer/library/api/LoginTokenInterceptorTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,14 @@ public void testTokenNotSetForCdnHost() throws IOException, InterruptedException
159159
@Test
160160
public void testTokenNotSetForStreamHost() throws IOException, InterruptedException, ProxerException {
161161
server.enqueue(new MockResponse().setBody(fromResource("login.json")));
162-
server.enqueue(new MockResponse());
163162

164163
api.user().login("test", "secret").build().execute();
165-
api.client().newCall(new Request.Builder().url("http://s3.stream.proxer.me").build()).execute();
166164

167-
server.takeRequest();
165+
startHttpOnlyServer();
166+
167+
server.enqueue(new MockResponse());
168+
169+
api.client().newCall(new Request.Builder().url("http://s3.stream.proxer.me").build()).execute();
168170

169171
assertThat(server.takeRequest().getHeaders().get("proxer-api-token")).isNull();
170172
}

0 commit comments

Comments
 (0)