forked from Blendman974/faceclaw
HTTP requests identify Faceclaw in their user-agent string
This commit is contained in:
1 parent
c27dcacfee
commit
8cdee2a701
14 files changed
+115
-9
No files matched your search
@@ -0,0 +1,42 @@
|
||||
package com.faceclaw.app;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
/**
|
||||
* Shared HTTP identity for the Java networking helpers. The version lives in
|
||||
* app/version.ts, so the TypeScript side pushes the real string in at startup
|
||||
* (see installNativeUserAgent in app/util/http.ts); the default below is only
|
||||
* a fallback for requests that somehow beat that call.
|
||||
*/
|
||||
public final class FaceclawHttp {
|
||||
private static volatile String userAgent = "Faceclaw";
|
||||
|
||||
private FaceclawHttp() {}
|
||||
|
||||
public static void setUserAgent(String value) {
|
||||
if (value != null && !value.trim().isEmpty()) {
|
||||
userAgent = value.trim();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getUserAgent() {
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
/** Stamps our User-Agent on any request that doesn't already carry one. */
|
||||
public static Interceptor userAgentInterceptor() {
|
||||
return new Interceptor() {
|
||||
@Override public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
if (request.header("User-Agent") != null) {
|
||||
return chain.proceed(request);
|
||||
}
|
||||
return chain.proceed(request.newBuilder().header("User-Agent", userAgent).build());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -63,6 +63,7 @@ public class FaceclawModelDownloader {
|
||||
sharedClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(30, TimeUnit.SECONDS)
|
||||
.readTimeout(60, TimeUnit.SECONDS)
|
||||
.addInterceptor(FaceclawHttp.userAgentInterceptor())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ public class FaceclawSseRequest {
|
||||
sharedClient = new OkHttpClient.Builder()
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(180, TimeUnit.SECONDS)
|
||||
.addInterceptor(FaceclawHttp.userAgentInterceptor())
|
||||
.build();
|
||||
}
|
||||
client = sharedClient;
|
||||
|
||||
@@ -112,6 +112,7 @@ public class FaceclawWebSocket {
|
||||
if (sharedClient == null) {
|
||||
sharedClient = new OkHttpClient.Builder()
|
||||
.pingInterval(20, TimeUnit.SECONDS)
|
||||
.addInterceptor(FaceclawHttp.userAgentInterceptor())
|
||||
.build();
|
||||
}
|
||||
client = sharedClient;
|
||||
|
||||
Reference in new issue
Block a user