All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.redcom.lib.integration.api.client.dadata.HeaderRequestInterceptor Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2018 Boris Fox, REDCOM-Internet CJSC
 * All rights reserved.
 */

package ru.redcom.lib.integration.api.client.dadata;

import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.lang.NonNull;

import java.io.IOException;

/**
 * Request Interceptor to add credentials headers.
 *
 * @author boris
 */
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
class HeaderRequestInterceptor implements ClientHttpRequestInterceptor {
	@NonNull private final String headerName;
	@NonNull private final String headerValue;


	@NonNull
	@Override
	public ClientHttpResponse intercept(@NonNull final HttpRequest request, @NonNull final byte[] body,
	                                    @NonNull final ClientHttpRequestExecution execution) throws IOException {
		request.getHeaders().set(headerName, headerValue);
		return execution.execute(request, body);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy