From 12e2206f9d24b29c8276b2743603635620643444 Mon Sep 17 00:00:00 2001 From: Vitaly Takmazov Date: Wed, 18 Jan 2023 20:39:41 +0300 Subject: RestTemplate -> OkHttpClient --- .../juick/util/ActivityPubRequestInterceptor.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/main/java/com/juick/util/ActivityPubRequestInterceptor.java') diff --git a/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java b/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java index 138a3d09..65720910 100644 --- a/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java +++ b/src/main/java/com/juick/util/ActivityPubRequestInterceptor.java @@ -17,21 +17,21 @@ package com.juick.util; +import okhttp3.Interceptor; +import okhttp3.Response; +import org.jetbrains.annotations.NotNull; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpRequestExecution; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.lang.NonNull; import java.io.IOException; -public class ActivityPubRequestInterceptor implements ClientHttpRequestInterceptor { - +public class ActivityPubRequestInterceptor implements Interceptor { + @NotNull @Override - public @NonNull ClientHttpResponse intercept(HttpRequest request, @NonNull byte[] body, - ClientHttpRequestExecution execution) throws IOException { - request.getHeaders().set(HttpHeaders.USER_AGENT, "Juick/2.x"); - return execution.execute(request, body); + public Response intercept(@NotNull Interceptor.Chain chain) throws IOException { + var original = chain.request(); + var request = original.newBuilder() + .addHeader(HttpHeaders.USER_AGENT, "Juick/2.x") + .method(original.method(), original.body()); + return chain.proceed(request.build()); } } -- cgit v1.2.3