(crawler) Refactored IpInterceptingNetworkInterceptor for clarity.

This commit is contained in:
Viktor Lofgren 2023-12-08 17:45:46 +01:00
parent 3bbffd3c22
commit 968dce50fc
2 changed files with 9 additions and 3 deletions

View File

@ -6,7 +6,14 @@ import org.jetbrains.annotations.NotNull;
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 {
private static final String pseudoHeaderName = "X-Marginalia-Remote-IP";
@NotNull
@Override
public Response intercept(@NotNull Interceptor.Chain chain) throws IOException {
@ -14,11 +21,11 @@ public class IpInterceptingNetworkInterceptor implements Interceptor {
return chain.proceed(chain.request())
.newBuilder()
.addHeader("X-Marginalia-Remote-IP", IP)
.addHeader(pseudoHeaderName, IP)
.build();
}
public static String getIpFromResponse(Response response) {
return response.header("X-Marginalia-Remote-IP");
return response.header(pseudoHeaderName);
}
}

View File

@ -29,7 +29,6 @@ public class NoSecuritySSL {
}
};
@SneakyThrows
public static SSLSocketFactory buildSocketFactory() {
// Install the all-trusting trust manager