diff options
author | Vitaly Takmazov | 2023-01-18 20:39:41 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-19 14:30:01 +0300 |
commit | 12e2206f9d24b29c8276b2743603635620643444 (patch) | |
tree | 3af762f3fa6a1ce016df219fb88ab2b394ba35bb /src/main/java/com/juick/util | |
parent | 5b0f0bebda5d6369111ae35f8c335324ffa4cc7e (diff) |
RestTemplate -> OkHttpClient
Diffstat (limited to 'src/main/java/com/juick/util')
-rw-r--r-- | src/main/java/com/juick/util/ActivityPubRequestInterceptor.java | 22 |
1 files changed, 11 insertions, 11 deletions
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()); } } |