Here are the examples of the java api org.springframework.http.HttpRequest taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
264 Examples
19
Source : HttpHeaderInterceptor.java
with Apache License 2.0
from yuanmabiji
with Apache License 2.0
from yuanmabiji
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add(this.name, this.value);
return execution.execute(request, body);
}
19
Source : OAuth2RequestsInterceptor.java
with Apache License 2.0
from xaecbd
with Apache License 2.0
from xaecbd
@Override
public ClientHttpResponse intercept(final HttpRequest request, final byte[] body, ClientHttpRequestExecution execution) throws IOException {
HttpRequest protectedResourceRequest = new HttpRequestDecorators(request);
protectedResourceRequest.getHeaders().set("Authorization", "Bearer " + accessToken);
return execution.execute(protectedResourceRequest, body);
}
19
Source : WebClientResponseException.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
private static String initMessage(int status, String reasonPhrase, @Nullable HttpRequest request) {
return status + " " + reasonPhrase + (request != null ? " from " + request.getMethodValue() + " " + request.getURI() : "");
}
19
Source : UriComponentsBuilderTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
// gh-19890
@Test
public void fromHttpRequestWithEmptyScheme() {
HttpRequest request = new HttpRequest() {
@Override
public String getMethodValue() {
return "GET";
}
@Override
public URI getURI() {
return UriComponentsBuilder.fromUriString("/").build().toUri();
}
@Override
public HttpHeaders getHeaders() {
return new HttpHeaders();
}
};
UriComponents result = UriComponentsBuilder.fromHttpRequest(request).build();
replacedertEquals("/", result.toString());
}
19
Source : UriComponentsBuilderTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
// SPR-11856
@Test
public void fromHttpRequestForwardedHeader() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "proto=https; host=84.198.58.199");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
replacedertEquals("https", result.getScheme());
replacedertEquals("84.198.58.199", result.getHost());
replacedertEquals("/rest/mobile/users/1", result.getPath());
}
19
Source : UriComponentsBuilderTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void fromHttpRequestForwardedHeaderQuoted() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "proto=\"https\"; host=\"84.198.58.199\"");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
replacedertEquals("https", result.getScheme());
replacedertEquals("84.198.58.199", result.getHost());
replacedertEquals("/rest/mobile/users/1", result.getPath());
}
19
Source : UriComponentsBuilderTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void fromHttpRequestMultipleForwardedHeader() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "host=84.198.58.199;proto=https");
request.addHeader("Forwarded", "proto=ftp; host=1.2.3.4");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
replacedertEquals("https", result.getScheme());
replacedertEquals("84.198.58.199", result.getHost());
replacedertEquals("/rest/mobile/users/1", result.getPath());
}
19
Source : UriComponentsBuilderTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void fromHttpRequestForwardedHeaderWithHostPortAndWithoutServerPort() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "proto=https; host=84.198.58.199:9090");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
replacedertEquals("https", result.getScheme());
replacedertEquals("84.198.58.199", result.getHost());
replacedertEquals("/rest/mobile/users/1", result.getPath());
replacedertEquals(9090, result.getPort());
replacedertEquals("https://84.198.58.199:9090/rest/mobile/users/1", result.toUriString());
}
19
Source : UriComponentsBuilderTests.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
@Test
public void fromHttpRequestMultipleForwardedHeaderComma() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Forwarded", "host=84.198.58.199 ;proto=https, proto=ftp; host=1.2.3.4");
request.setScheme("http");
request.setServerName("example.com");
request.setRequestURI("/rest/mobile/users/1");
HttpRequest httpRequest = new ServletServerHttpRequest(request);
UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
replacedertEquals("https", result.getScheme());
replacedertEquals("84.198.58.199", result.getHost());
replacedertEquals("/rest/mobile/users/1", result.getPath());
}
19
Source : WebUtils.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Check if the request is a same-origin one, based on {@code Origin}, {@code Host},
* {@code Forwarded}, {@code X-Forwarded-Proto}, {@code X-Forwarded-Host} and
* {@code X-Forwarded-Port} headers.
*
* <p><strong>Note:</strong> as of 5.1 this method ignores
* {@code "Forwarded"} and {@code "X-Forwarded-*"} headers that specify the
* client-originated address. Consider using the {@code ForwardedHeaderFilter}
* to extract and use, or to discard such headers.
*
* @return {@code true} if the request is a same-origin one, {@code false} in case
* of cross-origin request
* @since 4.2
*/
public static boolean isSameOrigin(HttpRequest request) {
HttpHeaders headers = request.getHeaders();
String origin = headers.getOrigin();
if (origin == null) {
return true;
}
String scheme;
String host;
int port;
if (request instanceof ServletServerHttpRequest) {
// Build more efficiently if we can: we only need scheme, host, port for origin comparison
HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest();
scheme = servletRequest.getScheme();
host = servletRequest.getServerName();
port = servletRequest.getServerPort();
} else {
URI uri = request.getURI();
scheme = uri.getScheme();
host = uri.getHost();
port = uri.getPort();
}
UriComponents originUrl = UriComponentsBuilder.fromOriginHeader(origin).build();
return (ObjectUtils.nullSafeEquals(scheme, originUrl.getScheme()) && ObjectUtils.nullSafeEquals(host, originUrl.getHost()) && getPort(scheme, port) == getPort(originUrl.getScheme(), originUrl.getPort()));
}
19
Source : WebUtils.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Check the given request origin against a list of allowed origins.
* A list containing "*" means that all origins are allowed.
* An empty list means only same origin is allowed.
*
* <p><strong>Note:</strong> as of 5.1 this method ignores
* {@code "Forwarded"} and {@code "X-Forwarded-*"} headers that specify the
* client-originated address. Consider using the {@code ForwardedHeaderFilter}
* to extract and use, or to discard such headers.
*
* @return {@code true} if the request origin is valid, {@code false} otherwise
* @since 4.1.5
* @see <a href="https://tools.ietf.org/html/rfc6454">RFC 6454: The Web Origin Concept</a>
*/
public static boolean isValidOrigin(HttpRequest request, Collection<String> allowedOrigins) {
replacedert.notNull(request, "Request must not be null");
replacedert.notNull(allowedOrigins, "Allowed origins must not be null");
String origin = request.getHeaders().getOrigin();
if (origin == null || allowedOrigins.contains("*")) {
return true;
} else if (CollectionUtils.isEmpty(allowedOrigins)) {
return isSameOrigin(request);
} else {
return allowedOrigins.contains(origin);
}
}
19
Source : UriComponentsBuilder.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Create a new {@code UriComponents} object from the URI replacedociated with
* the given HttpRequest while also overlaying with values from the headers
* "Forwarded" (<a href="https://tools.ietf.org/html/rfc7239">RFC 7239</a>),
* or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
* "Forwarded" is not found.
* @param request the source request
* @return the URI components of the URI
* @since 4.1.5
*/
public static UriComponentsBuilder fromHttpRequest(HttpRequest request) {
return fromUri(request.getURI()).adaptFromForwardedHeaders(request.getHeaders());
}
19
Source : HttpRequestWrapper.java
with MIT License
from Vip-Augus
with MIT License
from Vip-Augus
/**
* Provides a convenient implementation of the {@link HttpRequest} interface
* that can be overridden to adapt the request.
*
* <p>These methods default to calling through to the wrapped request object.
*
* @author Arjen Poutsma
* @since 3.1
*/
public clreplaced HttpRequestWrapper implements HttpRequest {
private final HttpRequest request;
/**
* Create a new {@code HttpRequest} wrapping the given request object.
* @param request the request object to be wrapped
*/
public HttpRequestWrapper(HttpRequest request) {
replacedert.notNull(request, "HttpRequest must not be null");
this.request = request;
}
/**
* Return the wrapped request.
*/
public HttpRequest getRequest() {
return this.request;
}
/**
* Return the method of the wrapped request.
*/
@Override
@Nullable
public HttpMethod getMethod() {
return this.request.getMethod();
}
/**
* Return the method value of the wrapped request.
*/
@Override
public String getMethodValue() {
return this.request.getMethodValue();
}
/**
* Return the URI of the wrapped request.
*/
@Override
public URI getURI() {
return this.request.getURI();
}
/**
* Return the headers of the wrapped request.
*/
@Override
public HttpHeaders getHeaders() {
return this.request.getHeaders();
}
}
19
Source : LoggingClientHttpRequestInterceptor.java
with GNU Lesser General Public License v2.1
from Verdoso
with GNU Lesser General Public License v2.1
from Verdoso
protected void logResponse(HttpRequest request, ClientHttpResponse response) {
try {
log.info("Response: {}", ObjectJoiner.join(" ", response.getRawStatusCode(), response.getStatusText(), " from ", request.getMethod(), ": ", request.getURI()));
if (log.isDebugEnabled()) {
HttpHeaders responseHeaders = response.getHeaders();
for (String header : response.getHeaders().keySet()) {
for (String value : response.getHeaders().get(header)) {
logHeader(header, value);
}
}
if (log.isTraceEnabled() && hasTextBody(responseHeaders) && isBuffered(response)) {
logBody(StreamUtils.copyToString(response.getBody(), determineCharset(responseHeaders)), responseHeaders);
}
}
} catch (IOException e) {
log.warn("Failed to log response for {} request to {}", request.getMethod(), request.getURI(), e);
}
}
19
Source : LoggingClientHttpRequestInterceptor.java
with GNU Lesser General Public License v2.1
from Verdoso
with GNU Lesser General Public License v2.1
from Verdoso
protected void logRequest(HttpRequest request, byte[] body) {
log.info("Request: {}", ObjectJoiner.join(" ", request.getURI().getScheme(), request.getMethod(), request.getURI()));
final boolean hasRequestBody = body != null && body.length > 0;
if (log.isDebugEnabled()) {
// If the request has a body, sometimes these headers are not
// present, so let's make them explicit
if (hasRequestBody) {
logHeader(CONTENT_LENGTH_HEADER, Long.toString(body.length));
final MediaType contentType = request.getHeaders().getContentType();
if (contentType != null) {
logHeader(CONTENT_TYPE_HEADER, contentType.toString());
}
}
// Log the other headers
for (String header : request.getHeaders().keySet()) {
if (!CONTENT_TYPE_HEADER.equalsIgnoreCase(header) && !CONTENT_LENGTH_HEADER.equalsIgnoreCase(header)) {
for (String value : request.getHeaders().get(header)) {
logHeader(header, value);
}
}
}
if (log.isTraceEnabled() && hasRequestBody) {
logBody(new String(body, determineCharset(request.getHeaders())), request.getHeaders());
}
}
}
19
Source : LoggingClientHttpRequestInterceptor.java
with GNU Lesser General Public License v2.1
from Verdoso
with GNU Lesser General Public License v2.1
from Verdoso
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
if (log.isInfoEnabled()) {
logRequest(request, body);
}
ClientHttpResponse response = execution.execute(request, body);
if (log.isInfoEnabled()) {
logResponse(request, response);
}
return response;
}
19
Source : LoggingRequestInterceptor.java
with Apache License 2.0
from telstra
with Apache License 2.0
from telstra
private String genereateCurl(HttpRequest request, byte[] payload) throws IOException {
StringBuilder sb = new StringBuilder();
sb.append(format("curl -X %s \\\n", request.getMethodValue()));
sb.append(request.getURI().toString()).append(" \\\n");
request.getHeaders().forEach((k, v) -> sb.append(format("-H '%s: %s' \\\n", k, StringUtils.substringBetween(v.toString(), "[", "]"))));
String body = new String(payload, "UTF-8");
if (!StringUtils.isEmpty(body)) {
sb.append(format("-d '%s' \n", toJson(body)));
}
return sb.toString();
}
19
Source : LoggingRequestInterceptor.java
with Apache License 2.0
from telstra
with Apache License 2.0
from telstra
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
traceRequest(request, body);
ClientHttpResponse response = execution.execute(request, body);
traceResponse(response);
return response;
}
19
Source : GrayClientHttpRequestIntercptor.java
with Apache License 2.0
from SpringCloud
with Apache License 2.0
from SpringCloud
@SneakyThrows
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
URI uri = request.getURI();
GrayHttpRequest grayRequest = new GrayHttpRequest();
grayRequest.setUri(uri);
grayRequest.setServiceId(uri.getHost());
grayRequest.setParameters(WebUtils.getQueryParams(uri.getQuery()));
if (grayRequestProperties.isLoadBody()) {
grayRequest.setBody(body);
}
grayRequest.setMethod(request.getMethod().name());
grayRequest.addHeaders(request.getHeaders());
grayRequest.setAttribute(GRAY_REQUEST_ATTRIBUTE_RESTTEMPLATE_REQUEST, request);
RoutingConnectPointContext connectPointContext = RoutingConnectPointContext.builder().interceptroType(GrayNetflixClientConstants.INTERCEPTRO_TYPE_RESTTEMPLATE).grayRequest(grayRequest).build();
GrayRequestHelper.setPreviousServerInfoToHttpHeaderByInstanceLocalInfo(grayRequest);
return routingConnectionPoint.executeOrMock(connectPointContext, () -> execution.execute(request, body), this::mockResultConvert);
// try {
// ribbonConnectionPoint.executeConnectPoint(connectPointContext);
// return execution.execute(request, body);
// } catch (Exception e) {
// connectPointContext.setThrowable(e);
// throw e;
// } finally {
// ribbonConnectionPoint.shutdownconnectPoint(connectPointContext);
// }
}
19
Source : CustomClientHttpRequestInterceptor.java
with GNU General Public License v3.0
from spring-framework-guru
with GNU General Public License v3.0
from spring-framework-guru
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] bytes, ClientHttpRequestExecution execution) throws IOException {
// log the http request
LOG.info("URI: {}", request.getURI());
LOG.info("HTTP Method: {}", request.getMethodValue());
LOG.info("HTTP Headers: {}", request.getHeaders());
return execution.execute(request, bytes);
}
19
Source : RestTemplateGrayHeaderCustomizer.java
with Apache License 2.0
from spring-avengers
with Apache License 2.0
from spring-avengers
@Override
protected void addHeaderToRequest(HttpRequest request, String key, String value) {
request.getHeaders().set(key, value);
}
19
Source : RestTemplateGrayHeaderCustomizer.java
with Apache License 2.0
from spring-avengers
with Apache License 2.0
from spring-avengers
@Override
protected boolean containsKey(HttpRequest request, String key) {
return request.getHeaders().containsKey(key);
}
19
Source : GrayClientHttpRequestInterceptor.java
with Apache License 2.0
from spring-avengers
with Apache License 2.0
from spring-avengers
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
restTemplateGrayHeaderCustomizer.apply(request);
return execution.execute(request, body);
}
19
Source : UriComponentsBuilderTests.java
with Apache License 2.0
from SourceHot
with Apache License 2.0
from SourceHot
// gh-19890
@Test
public void fromHttpRequestWithEmptyScheme() {
HttpRequest request = new HttpRequest() {
@Override
public String getMethodValue() {
return "GET";
}
@Override
public URI getURI() {
return UriComponentsBuilder.fromUriString("/").build().toUri();
}
@Override
public HttpHeaders getHeaders() {
return new HttpHeaders();
}
};
UriComponents result = UriComponentsBuilder.fromHttpRequest(request).build();
replacedertThat(result.toString()).isEqualTo("/");
}
19
Source : RestTemplateRequestCarrier.java
with Apache License 2.0
from sofastack
with Apache License 2.0
from sofastack
/**
* RestTemplateRequestCarrier
* @author: guolei.sgl
* @since: v2.3.0
*/
public clreplaced RestTemplateRequestCarrier implements TextMap {
private final HttpRequest request;
public RestTemplateRequestCarrier(HttpRequest request) {
this.request = request;
}
@Override
public Iterator<Map.Entry<String, String>> iterator() {
throw new UnsupportedOperationException();
}
@Override
public void put(String key, String value) {
request.getHeaders().add(key, value);
}
}
19
Source : HttpClientInterceptor.java
with Mozilla Public License 2.0
from opfab
with Mozilla Public License 2.0
from opfab
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
log.info("Request body: " + new String(body));
ClientHttpResponse response = execution.execute(request, body);
return response;
}
19
Source : RestTemplateTracer.java
with Apache License 2.0
from open-telemetry
with Apache License 2.0
from open-telemetry
@Override
protected URI url(HttpRequest request) {
return request.getURI();
}
19
Source : RestTemplateTracer.java
with Apache License 2.0
from open-telemetry
with Apache License 2.0
from open-telemetry
@Override
protected String method(HttpRequest httpRequest) {
return httpRequest.getMethod().name();
}
19
Source : RestTemplateTracer.java
with Apache License 2.0
from open-telemetry
with Apache License 2.0
from open-telemetry
@Override
protected String requestHeader(HttpRequest request, String name) {
return request.getHeaders().getFirst(name);
}
19
Source : RestTemplateStrategyInterceptor.java
with Apache License 2.0
from Nepxion
with Apache License 2.0
from Nepxion
private void interceptOutputHeader(HttpRequest request) {
if (!interceptDebugEnabled) {
return;
}
System.out.println("------- " + getInterceptorName() + " Intercept Output Header Information ------");
HttpHeaders headers = request.getHeaders();
for (Iterator<Entry<String, List<String>>> iterator = headers.entrySet().iterator(); iterator.hasNext(); ) {
Entry<String, List<String>> header = iterator.next();
String headerName = header.getKey();
boolean isHeaderContains = isHeaderContains(headerName.toLowerCase());
if (isHeaderContains) {
List<String> headerValue = header.getValue();
System.out.println(headerName + "=" + headerValue);
}
}
System.out.println("--------------------------------------------------");
}
19
Source : RestTemplateStrategyInterceptor.java
with Apache License 2.0
from Nepxion
with Apache License 2.0
from Nepxion
private void applyInnerHeader(HttpRequest request) {
HttpHeaders headers = request.getHeaders();
headers.add(DiscoveryConstant.N_D_SERVICE_GROUP, pluginAdapter.getGroup());
headers.add(DiscoveryConstant.N_D_SERVICE_TYPE, pluginAdapter.getServiceType());
String serviceAppId = pluginAdapter.getServiceAppId();
if (StringUtils.isNotEmpty(serviceAppId)) {
headers.add(DiscoveryConstant.N_D_SERVICE_APP_ID, serviceAppId);
}
headers.add(DiscoveryConstant.N_D_SERVICE_ID, pluginAdapter.getServiceId());
headers.add(DiscoveryConstant.N_D_SERVICE_ADDRESS, pluginAdapter.getHost() + ":" + pluginAdapter.getPort());
headers.add(DiscoveryConstant.N_D_SERVICE_VERSION, pluginAdapter.getVersion());
headers.add(DiscoveryConstant.N_D_SERVICE_REGION, pluginAdapter.getRegion());
headers.add(DiscoveryConstant.N_D_SERVICE_ENVIRONMENT, pluginAdapter.getEnvironment());
headers.add(DiscoveryConstant.N_D_SERVICE_ZONE, pluginAdapter.getZone());
}
19
Source : RestTemplateStrategyInterceptor.java
with Apache License 2.0
from Nepxion
with Apache License 2.0
from Nepxion
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
interceptInputHeader();
applyInnerHeader(request);
applyOuterHeader(request);
interceptOutputHeader(request);
return execution.execute(request, body);
}
19
Source : UriComponentsBuilder.java
with MIT License
from mindcarver
with MIT License
from mindcarver
/**
* Create a new {@code UriComponents} object from the URI replacedociated with
* the given HttpRequest while also overlaying with values from the headers
* "Forwarded" (<a href="http://tools.ietf.org/html/rfc7239">RFC 7239</a>),
* or "X-Forwarded-Host", "X-Forwarded-Port", and "X-Forwarded-Proto" if
* "Forwarded" is not found.
* @param request the source request
* @return the URI components of the URI
* @since 4.1.5
*/
public static UriComponentsBuilder fromHttpRequest(HttpRequest request) {
return fromUri(request.getURI()).adaptFromForwardedHeaders(request.getHeaders());
}
19
Source : DefaultLogFormatter.java
with Apache License 2.0
from markhobson
with Apache License 2.0
from markhobson
// ----------------------------------------------------------------------------------------------------------------
// LogFormatter methods
// ----------------------------------------------------------------------------------------------------------------
@Override
public String formatRequest(HttpRequest request, byte[] body) {
String formattedBody = formatBody(body, getCharset(request));
return String.format("Request: %s %s %s", request.getMethod(), request.getURI(), formattedBody);
}
19
Source : JenkinsAuthorizationInterceptor.java
with MIT License
from ls1intum
with MIT License
from ls1intum
@NotNull
@Override
public ClientHttpResponse intercept(HttpRequest request, @NotNull byte[] body, @NotNull ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().setBasicAuth(username, preplacedword);
if (useCrumb) {
setCrumb(request.getHeaders());
}
return execution.execute(request, body);
}
19
Source : GitLabAuthorizationInterceptor.java
with MIT License
from ls1intum
with MIT License
from ls1intum
@NotNull
@Override
public ClientHttpResponse intercept(HttpRequest request, @NotNull byte[] body, @NotNull ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add("Private-Token", gitlabPrivateToken);
return execution.execute(request, body);
}
19
Source : BitbucketAuthorizationInterceptor.java
with MIT License
from ls1intum
with MIT License
from ls1intum
private static boolean isAddUserToGroupsRequest(HttpRequest request) {
return request.getURI().toString().endsWith("latest/admin/users/add-groups") && HttpMethod.POST.equals(request.getMethod());
}
19
Source : BitbucketAuthorizationInterceptor.java
with MIT License
from ls1intum
with MIT License
from ls1intum
private static boolean isCreateProjectRequest(HttpRequest request) {
return request.getURI().toString().endsWith("latest/projects") && HttpMethod.POST.equals(request.getMethod());
}
19
Source : BitbucketAuthorizationInterceptor.java
with MIT License
from ls1intum
with MIT License
from ls1intum
private static boolean needsBasicAuth(HttpRequest request) {
return isCreateProjectRequest(request) || isCreateUserRequest(request) || isAddUserToGroupsRequest(request);
}
19
Source : BitbucketAuthorizationInterceptor.java
with MIT License
from ls1intum
with MIT License
from ls1intum
private static boolean isCreateUserRequest(HttpRequest request) {
return request.getURI().toString().contains("latest/admin/users") && HttpMethod.POST.equals(request.getMethod());
}
19
Source : JiraAuthorizationInterceptor.java
with MIT License
from ls1intum
with MIT License
from ls1intum
@NotNull
@Override
public ClientHttpResponse intercept(HttpRequest request, @NotNull byte[] body, @NotNull ClientHttpRequestExecution execution) throws IOException {
if (!request.getHeaders().containsKey(HttpHeaders.AUTHORIZATION)) {
request.getHeaders().setBasicAuth(JIRA_USER, JIRA_PreplacedWORD);
}
return execution.execute(request, body);
}
19
Source : LoggingRequestResponseInterceptor.java
with Apache License 2.0
from line
with Apache License 2.0
from line
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
if (log.isDebugEnabled()) {
return Execution.from(request, body, config).logRequest().execute(execution).logResponse().getResponse();
}
return execution.execute(request, body);
}
19
Source : WebUtils.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Check if the request is a same-origin one, based on {@code Origin}, {@code Host},
* {@code Forwarded} and {@code X-Forwarded-Host} headers.
* @return {@code true} if the request is a same-origin one, {@code false} in case
* of cross-origin request.
* @since 4.2
*/
public static boolean isSameOrigin(HttpRequest request) {
String origin = request.getHeaders().getOrigin();
if (origin == null) {
return true;
}
UriComponents actualUrl = UriComponentsBuilder.fromHttpRequest(request).build();
UriComponents originUrl = UriComponentsBuilder.fromOriginHeader(origin).build();
return (actualUrl.getHost().equals(originUrl.getHost()) && getPort(actualUrl) == getPort(originUrl));
}
19
Source : WebUtils.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Check the given request origin against a list of allowed origins.
* A list containing "*" means that all origins are allowed.
* An empty list means only same origin is allowed.
* @return {@code true} if the request origin is valid, {@code false} otherwise
* @since 4.1.5
* @see <a href="https://tools.ietf.org/html/rfc6454">RFC 6454: The Web Origin Concept</a>
*/
public static boolean isValidOrigin(HttpRequest request, Collection<String> allowedOrigins) {
replacedert.notNull(request, "Request must not be null");
replacedert.notNull(allowedOrigins, "Allowed origins must not be null");
String origin = request.getHeaders().getOrigin();
if (origin == null || allowedOrigins.contains("*")) {
return true;
} else if (CollectionUtils.isEmpty(allowedOrigins)) {
return isSameOrigin(request);
} else {
return allowedOrigins.contains(origin);
}
}
19
Source : HttpRequestWrapper.java
with Apache License 2.0
from langtianya
with Apache License 2.0
from langtianya
/**
* Provides a convenient implementation of the {@link HttpRequest} interface
* that can be overridden to adapt the request.
*
* <p>These methods default to calling through to the wrapped request object.
*
* @author Arjen Poutsma
* @since 3.1
*/
public clreplaced HttpRequestWrapper implements HttpRequest {
private final HttpRequest request;
/**
* Create a new {@code HttpRequest} wrapping the given request object.
* @param request the request object to be wrapped
*/
public HttpRequestWrapper(HttpRequest request) {
replacedert.notNull(request, "HttpRequest must not be null");
this.request = request;
}
/**
* Return the wrapped request.
*/
public HttpRequest getRequest() {
return this.request;
}
/**
* Return the method of the wrapped request.
*/
@Override
public HttpMethod getMethod() {
return this.request.getMethod();
}
/**
* Return the URI of the wrapped request.
*/
@Override
public URI getURI() {
return this.request.getURI();
}
/**
* Return the headers of the wrapped request.
*/
@Override
public HttpHeaders getHeaders() {
return this.request.getHeaders();
}
}
19
Source : DtmRestTemplateInterceptor.java
with Apache License 2.0
from huaweicloud
with Apache License 2.0
from huaweicloud
@Override
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
exportDtmContextToHeader(httpRequest);
return clientHttpRequestExecution.execute(httpRequest, bytes);
}
19
Source : LoggingHttpInterceptor.java
with Apache License 2.0
from fridujo
with Apache License 2.0
from fridujo
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
ClientHttpResponse response = execution.execute(request, body);
String responseBody = toString((ByteArrayInputStream) response.getBody());
logger.info("Config server received request " + request.getMethodValue() + " " + request.getURI() + " and responded:\n" + responseBody);
return response;
}
19
Source : BasicJwtInterceptor.java
with GNU Lesser General Public License v2.1
from fanhualei
with GNU Lesser General Public License v2.1
from fanhualei
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
System.out.println("get " + token);
request.getHeaders().add("Authorization", token);
return execution.execute(request, body);
}
19
Source : BasicJwtInterceptor.java
with GNU Lesser General Public License v2.1
from fanhualei
with GNU Lesser General Public License v2.1
from fanhualei
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
request.getHeaders().add("Authorization", token);
return execution.execute(request, body);
}
19
Source : GrayInterceptor.java
with Apache License 2.0
from fangjian0423
with Apache License 2.0
from fangjian0423
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
if (rule.getType().equalsIgnoreCase("header")) {
if (request.getHeaders().containsKey(rule.getName())) {
String value = request.getHeaders().get(rule.getName()).iterator().next();
if (value.equals(rule.getValue())) {
RibbonRequestContextHolder.getCurrentContext().put("Gray", Boolean.TRUE.toString());
}
}
} else if (rule.getType().equalsIgnoreCase("param")) {
String query = request.getURI().getQuery();
String[] queryKV = query.split("&");
for (String queryItem : queryKV) {
String[] queryInfo = queryItem.split("=");
if (queryInfo[0].equalsIgnoreCase(rule.getName()) && queryInfo[1].equals(rule.getValue())) {
RibbonRequestContextHolder.getCurrentContext().put("Gray", Boolean.TRUE.toString());
}
}
}
return execution.execute(request, body);
}
See More Examples