Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature]add X-Request-ID and X-User-IP fields to headers. #4

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,10 @@
public interface Constants {
SecureParameter AUTHORIZATION_SECURE_PARAM = new SecureParameter("authorization", MaskType.COMPLETE);
SecureParameter PROXY_AUTHORIZATION_SECURE_PARAM = new SecureParameter("proxy-authorization", MaskType.COMPLETE);
String X_USER_IP = "X-User-IP";
String MDC_CLIENT_IP = "clientIP";
String MDC_REQUEST_ID = "requestId";
String X_REQUEST_ID = "X-Request-ID";
String ACCEPT_HEADER = "Accept";
String CONTENT_TYPE_HEADER = "Content-Type";
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.core5.http.ContentType;
import org.slf4j.MDC;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.AnnotatedParameterProcessor;
Expand All @@ -49,6 +50,7 @@
import java.util.List;
import java.util.concurrent.TimeUnit;

import static com.tosan.client.http.core.Constants.*;
import static com.tosan.tools.mask.starter.configuration.MaskBeanConfiguration.SECURED_PARAMETERS;

/**
Expand Down Expand Up @@ -110,8 +112,14 @@ public Client feignClient(HttpClient httpClient) {

public RequestInterceptor requestInterceptor() {
return requestTemplate -> {
requestTemplate.header("Accept", ContentType.APPLICATION_JSON.getMimeType());
requestTemplate.header("Content-Type", ContentType.APPLICATION_JSON.getMimeType());
requestTemplate.header(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
requestTemplate.header(CONTENT_TYPE_HEADER, ContentType.APPLICATION_JSON.getMimeType());
if (MDC.get(MDC_REQUEST_ID) != null) {
requestTemplate.header(X_REQUEST_ID, MDC.get(MDC_REQUEST_ID));
}
if (MDC.get(MDC_CLIENT_IP) != null) {
requestTemplate.header(X_USER_IP, MDC.get(MDC_CLIENT_IP));
}
};
}

Expand Down
Loading