Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code-generate const Mime values for each expected Content-Type in a request #3703

Open
david-perez opened this issue Jun 18, 2024 · 0 comments
Labels
good first issue Good for newcomers server Rust server SDK

Comments

@david-perez
Copy link
Contributor

Currently, we re-parse expected request Content-Type header values into mime::Mimes every time we service a request. It'd be more efficient if aws_smithy_http_server::protocol::content_type_header_classifier_smithy took in directly a const Mime type.

Note that we already do this to check the Accept header (against the Content-Type of the response):

val verifyAcceptHeaderStaticContentTypeInit =
writable {
httpBindingResolver.responseContentType(operationShape)?.also { contentType ->
val init =
when (contentType) {
"application/json" -> "const $staticContentType: #{Mime}::Mime = #{Mime}::APPLICATION_JSON;"
"application/octet-stream" -> "const $staticContentType: #{Mime}::Mime = #{Mime}::APPLICATION_OCTET_STREAM;"
"application/x-www-form-urlencoded" -> "const $staticContentType: #{Mime}::Mime = #{Mime}::APPLICATION_WWW_FORM_URLENCODED;"
else ->
"""
static $staticContentType: #{OnceCell}::sync::Lazy<#{Mime}::Mime> = #{OnceCell}::sync::Lazy::new(|| {
${contentType.dq()}.parse::<#{Mime}::Mime>().expect("BUG: MIME parsing failed, content_type is not valid")
});
"""
}
rustTemplate(init, *codegenScope)
}
}

It's probably better if we decide on #2666 before tackling this issue, to avoid throwaway work.

Originally source of this issue is #3690 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers server Rust server SDK
Projects
None yet
Development

No branches or pull requests

1 participant