aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2019-01-22 21:12:58 +0300
committerGravatar Vitaly Takmazov2019-01-22 21:12:58 +0300
commite4f45130797df9dc94d10fd1c79ad8952c6390c1 (patch)
tree56210f5bd946886f283eca8119a84fcdfe9079eb /src
parent0b418caf401c53eb73721a324cd13041c185d0fb (diff)
ActivityPub: make AP requests with correct Accept header
Diffstat (limited to 'src')
-rw-r--r--src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java5
-rw-r--r--src/main/java/com/juick/server/helpers/HeaderRequestInterceptor.java26
2 files changed, 31 insertions, 0 deletions
diff --git a/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java b/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java
index 43b638fe..6cb1126d 100644
--- a/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java
+++ b/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java
@@ -1,11 +1,14 @@
package com.juick.server.configuration;
+import com.juick.server.api.activity.model.Activity;
+import com.juick.server.helpers.HeaderRequestInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
import javax.inject.Inject;
+import java.util.Collections;
@Configuration
public class ActivityPubClientConfig {
@@ -15,6 +18,8 @@ public class ActivityPubClientConfig {
public RestTemplate apClient() {
RestTemplate restTemplate = new RestTemplate(new OkHttp3ClientHttpRequestFactory());
restTemplate.setErrorHandler(activityPubClientErrorHandler);
+ restTemplate.setInterceptors(Collections.singletonList(
+ new HeaderRequestInterceptor("Accept", Activity.ACTIVITY_MEDIA_TYPE)));
return restTemplate;
}
} \ No newline at end of file
diff --git a/src/main/java/com/juick/server/helpers/HeaderRequestInterceptor.java b/src/main/java/com/juick/server/helpers/HeaderRequestInterceptor.java
new file mode 100644
index 00000000..9121f5ce
--- /dev/null
+++ b/src/main/java/com/juick/server/helpers/HeaderRequestInterceptor.java
@@ -0,0 +1,26 @@
+package com.juick.server.helpers;
+
+import org.springframework.http.HttpRequest;
+import org.springframework.http.client.ClientHttpRequestExecution;
+import org.springframework.http.client.ClientHttpRequestInterceptor;
+import org.springframework.http.client.ClientHttpResponse;
+
+import java.io.IOException;
+
+public class HeaderRequestInterceptor implements ClientHttpRequestInterceptor {
+
+ private final String headerName;
+
+ private final String headerValue;
+
+ public HeaderRequestInterceptor(String headerName, String headerValue) {
+ this.headerName = headerName;
+ this.headerValue = headerValue;
+ }
+
+ @Override
+ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
+ request.getHeaders().set(headerName, headerValue);
+ return execution.execute(request, body);
+ }
+}