mirror of
https://github.com/MarginaliaSearch/MarginaliaSearch.git
synced 2025-02-24 05:18:58 +00:00
(crawler) Refactored IpInterceptingNetworkInterceptor for clarity.
This commit is contained in:
parent
3bbffd3c22
commit
968dce50fc
@ -6,7 +6,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
|
||||||
|
/** An interceptor that intercepts network requests and adds the remote IP address as
|
||||||
|
* a header in the response. This is used to pass the remote IP address to the Warc
|
||||||
|
* writer, as this information is not available in the response.
|
||||||
|
*/
|
||||||
public class IpInterceptingNetworkInterceptor implements Interceptor {
|
public class IpInterceptingNetworkInterceptor implements Interceptor {
|
||||||
|
private static final String pseudoHeaderName = "X-Marginalia-Remote-IP";
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Response intercept(@NotNull Interceptor.Chain chain) throws IOException {
|
public Response intercept(@NotNull Interceptor.Chain chain) throws IOException {
|
||||||
@ -14,11 +21,11 @@ public class IpInterceptingNetworkInterceptor implements Interceptor {
|
|||||||
|
|
||||||
return chain.proceed(chain.request())
|
return chain.proceed(chain.request())
|
||||||
.newBuilder()
|
.newBuilder()
|
||||||
.addHeader("X-Marginalia-Remote-IP", IP)
|
.addHeader(pseudoHeaderName, IP)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getIpFromResponse(Response response) {
|
public static String getIpFromResponse(Response response) {
|
||||||
return response.header("X-Marginalia-Remote-IP");
|
return response.header(pseudoHeaderName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ public class NoSecuritySSL {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static SSLSocketFactory buildSocketFactory() {
|
public static SSLSocketFactory buildSocketFactory() {
|
||||||
// Install the all-trusting trust manager
|
// Install the all-trusting trust manager
|
||||||
|
Loading…
Reference in New Issue
Block a user