use of software.amazon.awssdk.crt.http.HttpHeader in project aws-sdk-java-v2 by aws.
the class AwsCrt4aSigningAdapter method signTrailerHeaders.
public AwsSigningResult signTrailerHeaders(Map<String, List<String>> headerMap, byte[] previousSignature, AwsSigningConfig signingConfig) {
List<HttpHeader> httpHeaderList = headerMap.entrySet().stream().map(entry -> new HttpHeader(entry.getKey(), String.join(",", entry.getValue()))).collect(Collectors.toList());
// All the config remains the same as signing config except the Signature Type.
AwsSigningConfig configCopy = signingConfig.clone();
configCopy.setSignatureType(AwsSigningConfig.AwsSignatureType.HTTP_REQUEST_TRAILING_HEADERS);
CompletableFuture<AwsSigningResult> future = AwsSigner.sign(httpHeaderList, previousSignature, configCopy);
try {
return future.get();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw SdkClientException.create("The thread got interrupted while attempting to sign request: " + e.getMessage(), e);
} catch (Exception e) {
throw SdkClientException.create("Unable to sign request: " + e.getMessage(), e);
}
}
use of software.amazon.awssdk.crt.http.HttpHeader in project aws-sdk-java-v2 by aws.
the class CrtHttpRequestConverter method createHttpHeaderArray.
private HttpHeader[] createHttpHeaderArray(SdkHttpFullRequest request) {
List<HttpHeader> crtHeaderList = new ArrayList<>(request.headers().size() + 2);
// Set Host Header if needed
if (isNullOrEmpty(request.headers().get(HOST_HEADER))) {
crtHeaderList.add(new HttpHeader(HOST_HEADER, request.host()));
}
// Add the rest of the Headers
for (Map.Entry<String, List<String>> headerList : request.headers().entrySet()) {
for (String val : headerList.getValue()) {
HttpHeader h = new HttpHeader(headerList.getKey(), val);
crtHeaderList.add(h);
}
}
return crtHeaderList.toArray(new HttpHeader[0]);
}
use of software.amazon.awssdk.crt.http.HttpHeader in project aws-sdk-java-v2 by aws.
the class CrtHttpRequestConverter method requestToCrt.
public HttpRequest requestToCrt(SdkHttpFullRequest inputRequest) {
String method = inputRequest.method().name();
String encodedPath = encodedPathToCrtFormat(inputRequest.encodedPath());
String encodedQueryString = SdkHttpUtils.encodeAndFlattenQueryParameters(inputRequest.rawQueryParameters()).map(value -> "?" + value).orElse("");
HttpHeader[] crtHeaderArray = createHttpHeaderArray(inputRequest);
Optional<ContentStreamProvider> contentProvider = inputRequest.contentStreamProvider();
HttpRequestBodyStream crtInputStream = null;
if (contentProvider.isPresent()) {
crtInputStream = new CrtHttpRequestConverter.CrtInputStream(contentProvider.get());
}
return new HttpRequest(method, encodedPath + encodedQueryString, crtHeaderArray, crtInputStream);
}
use of software.amazon.awssdk.crt.http.HttpHeader in project aws-sdk-java-v2 by aws.
the class S3CrtAsyncHttpClient method createHttpHeaderList.
private static List<HttpHeader> createHttpHeaderList(URI uri, AsyncExecuteRequest asyncRequest) {
SdkHttpRequest sdkRequest = asyncRequest.request();
List<HttpHeader> crtHeaderList = new ArrayList<>();
// Set Host Header if needed
if (isNullOrEmpty(sdkRequest.headers().get(Header.HOST))) {
crtHeaderList.add(new HttpHeader(Header.HOST, uri.getHost()));
}
// Set Content-Length if needed
Optional<Long> contentLength = asyncRequest.requestContentPublisher().contentLength();
if (isNullOrEmpty(sdkRequest.headers().get(Header.CONTENT_LENGTH)) && contentLength.isPresent()) {
crtHeaderList.add(new HttpHeader(Header.CONTENT_LENGTH, Long.toString(contentLength.get())));
}
// Add the rest of the Headers
sdkRequest.headers().forEach((key, value) -> value.stream().map(val -> new HttpHeader(key, val)).forEach(crtHeaderList::add));
return crtHeaderList;
}
use of software.amazon.awssdk.crt.http.HttpHeader in project aws-sdk-java-v2 by aws.
the class S3CrtAsyncHttpClient method toCrtRequest.
private static HttpRequest toCrtRequest(AsyncExecuteRequest asyncRequest) {
URI uri = asyncRequest.request().getUri();
SdkHttpRequest sdkRequest = asyncRequest.request();
String method = sdkRequest.method().name();
String encodedPath = sdkRequest.encodedPath();
if (encodedPath == null || encodedPath.isEmpty()) {
encodedPath = "/";
}
String encodedQueryString = SdkHttpUtils.encodeAndFlattenQueryParameters(sdkRequest.rawQueryParameters()).map(value -> "?" + value).orElse("");
HttpHeader[] crtHeaderArray = createHttpHeaderList(uri, asyncRequest).toArray(new HttpHeader[0]);
S3CrtRequestBodyStreamAdapter sdkToCrtRequestPublisher = new S3CrtRequestBodyStreamAdapter(asyncRequest.requestContentPublisher());
return new HttpRequest(method, encodedPath + encodedQueryString, crtHeaderArray, sdkToCrtRequestPublisher);
}
Aggregations