diff options
author | 2019-07-04 11:55:47 +0300 | |
---|---|---|
committer | 2019-07-04 11:55:47 +0300 | |
commit | 52d88dd00b260c54ba90ab52e283b5b1b1ba851d (patch) | |
tree | ea83390e6e8800359e4f57e3832e48a0ec054127 /src/main/java/com/juick/server | |
parent | 7b3e944ab25ae723f78410396ae3d81b0be27790 (diff) |
ActivityPub: ignore cookies from client responses
Diffstat (limited to 'src/main/java/com/juick/server')
-rw-r--r-- | src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java b/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java index 1cf676cd..637b9fd7 100644 --- a/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java +++ b/src/main/java/com/juick/server/configuration/ActivityPubClientConfig.java @@ -3,13 +3,19 @@ package com.juick.server.configuration; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.api.activity.model.Activity; import com.juick.server.helpers.HeaderRequestInterceptor; +import org.apache.http.client.config.CookieSpecs; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.protocol.HttpContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; import javax.inject.Inject; +import java.net.URI; import java.util.Collections; @Configuration @@ -27,7 +33,19 @@ public class ActivityPubClientConfig { @Bean public RestTemplate apClient() { RestTemplate restTemplate = new RestTemplate(); - restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory()); + restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory() { + @Override + protected HttpContext createHttpContext(HttpMethod httpMethod, URI uri) { + HttpClientContext context = HttpClientContext.create(); + context.setRequestConfig(getRequestConfig()); + return context; + } + RequestConfig getRequestConfig() { + RequestConfig.Builder builder = RequestConfig.custom() + .setCookieSpec(CookieSpecs.IGNORE_COOKIES); + return builder.build(); + } + }); restTemplate.getMessageConverters().add(0, mappingJacksonHttpMessageConverter()); restTemplate.setErrorHandler(activityPubClientErrorHandler); restTemplate.setInterceptors(Collections.singletonList( |