Skip to content

Remove message builders#1121

Open
mtdowling wants to merge 2 commits intomainfrom
remove-message-builders
Open

Remove message builders#1121
mtdowling wants to merge 2 commits intomainfrom
remove-message-builders

Conversation

@mtdowling
Copy link
Copy Markdown
Member

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.

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.
@mtdowling mtdowling force-pushed the remove-message-builders branch from d9a8a1b to fbbb18f Compare April 1, 2026 03:50
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";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in HeaderNames?

.withReplacedHeader("Content-MD5", ListUtils.of(base64Hash))
.build();
var modifiable = request.toModifiable();
modifiable.headers().setHeader("content-md5", base64Hash);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in HeaderNames?

Comment on lines +88 to +90
builder.addHeader("x-amz-target", target)
.addHeader("content-type", "application/vnd.amazon.eventstream")
.addHeader("accept", contentType())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a lot of usages of basic strings for headers throughout the protocols that are already defined in HeaderNames.

Comment on lines 140 to 155
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);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More headers to use HeaderNames for

Comment on lines +114 to +116
.addHeader("Content-Type", "application/json")
.addHeader("Accept", "application/json, text/event-stream")
.addHeader("MCP-Protocol-Version", protocolVersionHeader);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some more HeaderNames uses in here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants