Conversation
The builders just delegated to the mutable request/response anyway and added unnecessary overhead. Mutable messages are now fluent, have chaining methods like toModifiable and toUnmodifiable, so it obviates the need for builders entirely.
d9a8a1b to
fbbb18f
Compare
| final class HttpBearerAuthSigner implements Signer<HttpRequest, TokenIdentity> { | ||
| static final HttpBearerAuthSigner INSTANCE = new HttpBearerAuthSigner(); | ||
| private static final InternalLogger LOGGER = InternalLogger.getLogger(HttpBearerAuthSigner.class); | ||
| private static final String AUTHORIZATION_HEADER = "authorization"; |
There was a problem hiding this comment.
Should this be in HeaderNames?
| .withReplacedHeader("Content-MD5", ListUtils.of(base64Hash)) | ||
| .build(); | ||
| var modifiable = request.toModifiable(); | ||
| modifiable.headers().setHeader("content-md5", base64Hash); |
There was a problem hiding this comment.
Should this be in HeaderNames?
| private static final int DEFAULT_MIN_COMPRESSION_SIZE_BYTES = 10240; | ||
| // This cap matches ApiGateway's spec: https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-openapi-minimum-compression-size.html | ||
| private static final int MIN_COMPRESSION_SIZE_CAP = 10485760; | ||
| private static final String CONTENT_ENCODING_HEADER = "Content-Encoding"; |
There was a problem hiding this comment.
Should this be in HeaderNames?
| final class HttpBasicAuthSigner implements Signer<HttpRequest, LoginIdentity> { | ||
| static final HttpBasicAuthSigner INSTANCE = new HttpBasicAuthSigner(); | ||
| private static final InternalLogger LOGGER = InternalLogger.getLogger(HttpBasicAuthSigner.class); | ||
| private static final String AUTHORIZATION_HEADER = "authorization"; |
There was a problem hiding this comment.
Should this be in HeaderNames?
| builder.addHeader("x-amz-target", target) | ||
| .addHeader("content-type", "application/vnd.amazon.eventstream") | ||
| .addHeader("accept", contentType()) |
There was a problem hiding this comment.
There are a lot of usages of basic strings for headers throughout the protocols that are already defined in HeaderNames.
| private Map<String, List<String>> headers() { | ||
| return Map.of("smithy-protocol", SMITHY_PROTOCOL, "Content-Type", CONTENT_TYPE, "Accept", CONTENT_TYPE); | ||
| } | ||
|
|
||
| private Map<String, List<String>> headersForEmptyBody() { | ||
| return Map.of("smithy-protocol", SMITHY_PROTOCOL, "Accept", CONTENT_TYPE); | ||
| } | ||
|
|
||
| private Map<String, List<String>> headersForEventStreaming() { | ||
| return Map.of("smithy-protocol", | ||
| SMITHY_PROTOCOL, | ||
| "Content-Type", | ||
| List.of("application/vnd.amazon.eventstream"), | ||
| "Accept", | ||
| CONTENT_TYPE); | ||
| } |
There was a problem hiding this comment.
More headers to use HeaderNames for
| .addHeader("Content-Type", "application/json") | ||
| .addHeader("Accept", "application/json, text/event-stream") | ||
| .addHeader("MCP-Protocol-Version", protocolVersionHeader); |
There was a problem hiding this comment.
This and more in the MCP content to move to HeaderNames use.
| return new SignResult<>(request.toBuilder().headers(HttpHeaders.of(signedHeaders)).build(), | ||
| signatureAndSignedHeaders.left); | ||
| var mod = request.toModifiable(); | ||
| mod.setHeaders(HttpHeaders.of(signedHeaders).toModifiable()); |
There was a problem hiding this comment.
Could the private path to signedHeaders use a modifiable HttpHeaders instead?
|
|
||
| // AWS4 requires a number of headers to be set before signing including 'Host' and 'X-Amz-Date' | ||
| var hostHeader = uriUsingStandardPort(uri) ? uri.getHost() + ':' + uri.getPort() : uri.getHost(); | ||
| headers.put("host", List.of(hostHeader)); |
There was a problem hiding this comment.
Some more HeaderNames uses in here.
Remove request/response builders
The builders just delegated to the mutable request/response anyway and added unnecessary overhead. Mutable messages are now fluent, have chaining methods like toModifiable and toUnmodifiable, so it obviates the need for builders entirely.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.