aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/helpers')
-rw-r--r--src/main/java/com/juick/server/helpers/HeaderRequestInterceptor.java26
1 files changed, 26 insertions, 0 deletions
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);
+ }
+}