use of com.azure.core.http.HttpHeaders in project lowkey-vault by nagyesta.
the class ApacheHttpRequestTest method testConstructorShouldConvertValuesWhenCalled.
@Test
void testConstructorShouldConvertValuesWhenCalled() throws MalformedURLException, URISyntaxException {
// given
final HttpMethod method = HttpMethod.POST;
final URL url = new URL("https://localhost");
final HttpHeaders headers = new HttpHeaders(Map.of(HEADER_1, HEADER_VALUE_1, HEADER_2, HEADER_VALUE_2));
// when
final ApacheHttpRequest actual = new ApacheHttpRequest(method, url, headers, Function.identity());
// then
Assertions.assertEquals(method.toString(), actual.getMethod());
Assertions.assertEquals(url.toURI(), actual.getURI());
Assertions.assertEquals(HEADER_VALUE_1, actual.getHeaders(HEADER_1)[0].getValue());
Assertions.assertEquals(HEADER_VALUE_2, actual.getHeaders(HEADER_2)[0].getValue());
}
use of com.azure.core.http.HttpHeaders in project bulk-scan-processor by hmcts.
the class BlobManagerTest method tryMoveFileToRejectedContainer_retry_delete_when_lease_lost.
@Test
void tryMoveFileToRejectedContainer_retry_delete_when_lease_lost() {
// given
given(inputContainerClient.getBlobClient(INPUT_FILE_NAME)).willReturn(inputBlobClient);
given(rejectedContainerClient.getBlobClient(INPUT_FILE_NAME)).willReturn(rejectedBlobClient);
given(blobServiceClient.getBlobContainerClient(INPUT_CONTAINER_NAME)).willReturn(inputContainerClient);
given(blobServiceClient.getBlobContainerClient(REJECTED_CONTAINER_NAME)).willReturn(rejectedContainerClient);
given(rejectedBlobClient.exists()).willReturn(Boolean.FALSE);
mockBeginCopy("http://retry", UUID.randomUUID().toString());
HttpResponse response = mock(HttpResponse.class);
given(response.getStatusCode()).willReturn(412);
HttpHeaders httpHeaders = mock(HttpHeaders.class);
given(response.getHeaders()).willReturn(httpHeaders);
given(httpHeaders.getValue(ERROR_CODE)).willReturn(BlobErrorCode.LEASE_LOST.toString());
willThrow(new BlobStorageException(BlobErrorCode.LEASE_LOST.toString(), response, null)).willReturn(mock(Response.class)).given(inputBlobClient).deleteWithResponse(any(), any(), any(), any());
// when
blobManager.tryMoveFileToRejectedContainer(INPUT_FILE_NAME, INPUT_CONTAINER_NAME);
// then
verify(rejectedBlobClient).beginCopy(any(), any(), any(), any(), any(), any(), any());
verify(inputBlobClient, times(2)).deleteWithResponse(any(), any(), any(), any());
}
use of com.azure.core.http.HttpHeaders in project camel-quarkus by apache.
the class VertxHttpClientTests method validateHeadersReturnAsIs.
@Test
public void validateHeadersReturnAsIs() {
HttpClient client = new VertxHttpClientProvider().createInstance();
final String singleValueHeaderName = "singleValue";
final String singleValueHeaderValue = "value";
final String multiValueHeaderName = "Multi-value";
final List<String> multiValueHeaderValue = Arrays.asList("value1", "value2");
HttpHeaders headers = new HttpHeaders().set(singleValueHeaderName, singleValueHeaderValue).set(multiValueHeaderName, multiValueHeaderValue);
StepVerifier.create(client.send(new HttpRequest(HttpMethod.GET, url(server, RETURN_HEADERS_AS_IS_PATH), headers, Flux.empty()))).assertNext(response -> {
Assertions.assertEquals(200, response.getStatusCode());
HttpHeaders responseHeaders = response.getHeaders();
HttpHeader singleValueHeader = responseHeaders.get(singleValueHeaderName);
assertEquals(singleValueHeaderName, singleValueHeader.getName());
assertEquals(singleValueHeaderValue, singleValueHeader.getValue());
HttpHeader multiValueHeader = responseHeaders.get("Multi-value");
assertEquals(multiValueHeaderName, multiValueHeader.getName());
}).expectComplete().verify(Duration.ofSeconds(10));
}
use of com.azure.core.http.HttpHeaders in project camel-quarkus by apache.
the class VertxHttpResponse method fromVertxHttpHeaders.
private HttpHeaders fromVertxHttpHeaders(MultiMap headers) {
HttpHeaders azureHeaders = new HttpHeaders();
headers.names().forEach(name -> azureHeaders.set(name, headers.getAll(name)));
return azureHeaders;
}
use of com.azure.core.http.HttpHeaders in project terra-cloud-resource-lib by DataBiosphere.
the class AzureResponseLogger method logBody.
private static void logBody(HttpHeaders headers, Flux<ByteBuffer> body, Consumer<String> consumer) {
// Ensure we have a valid content length
String contentLengthString = headers.getValue("Content-Length");
if (CoreUtils.isNullOrEmpty(contentLengthString)) {
return;
}
final long contentLength;
try {
contentLength = Long.parseLong(contentLengthString);
} catch (NumberFormatException | NullPointerException e) {
return;
}
// The body is logged if the Content-Type is not "application/octet-stream" and the
// body isn't empty and is less than 16KB in size.
String contentTypeHeader = headers.getValue("Content-Type");
if (!ContentType.APPLICATION_OCTET_STREAM.equalsIgnoreCase(contentTypeHeader) && contentLength != 0 && contentLength < MAX_BODY_LOG_SIZE) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream((int) contentLength);
WritableByteChannel bodyContentChannel = Channels.newChannel(outputStream);
body.flatMap(byteBuffer -> {
try {
bodyContentChannel.write(byteBuffer.duplicate());
return Mono.just(byteBuffer);
} catch (IOException e) {
return Mono.error(e);
}
}).doFinally(ignored -> consumer.accept(outputStream.toString(Charsets.UTF_8)));
}
}
Aggregations