use of com.azure.core.http.HttpHeaders in project ApplicationInsights-Java by microsoft.
the class QuickPulseNetworkHelper method getQuickPulseHeaderInfo.
public QuickPulseHeaderInfo getQuickPulseHeaderInfo(HttpResponse response) {
HttpHeaders headers = response.getHeaders();
QuickPulseStatus status = QuickPulseStatus.ERROR;
long servicePollingIntervalHint = -1;
String serviceEndpointRedirect = null;
for (HttpHeader header : headers) {
if (QPS_STATUS_HEADER.equalsIgnoreCase(header.getName())) {
String qpStatus = header.getValue();
if ("true".equalsIgnoreCase(qpStatus)) {
status = QuickPulseStatus.QP_IS_ON;
} else {
status = QuickPulseStatus.QP_IS_OFF;
}
} else if (QPS_SERVICE_POLLING_INTERVAL_HINT.equalsIgnoreCase(header.getName())) {
String servicePollingIntervalHintHeaderValue = header.getValue();
if (!Strings.isNullOrEmpty(servicePollingIntervalHintHeaderValue)) {
servicePollingIntervalHint = Long.parseLong(servicePollingIntervalHintHeaderValue);
}
} else if (QPS_SERVICE_ENDPOINT_REDIRECT.equalsIgnoreCase(header.getName())) {
serviceEndpointRedirect = header.getValue();
}
}
return new QuickPulseHeaderInfo(status, serviceEndpointRedirect, servicePollingIntervalHint);
}
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