Skip to content

Commit

Permalink
Update header serialization to include empty headers
Browse files Browse the repository at this point in the history
  • Loading branch information
landonxjames committed Oct 20, 2024
1 parent 894cf94 commit 2a7b98b
Showing 1 changed file with 26 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -617,17 +617,26 @@ class HttpBindingGenerator(
)(this)
}

rustBlock("for ${loopVariable.name} in ${context.valueExpression.asRef()}") {
this.renderHeaderValue(
headerName,
loopVariable,
model.expectShape(shape.member.target),
isMultiValuedHeader = true,
timestampFormat,
renderErrorMessage,
serializeIfDefault = true,
shape.member,
)
rustTemplate(
"""
// Empty vecs in headers are serialized as the empty string
if ${context.valueExpression.asRef()}.len() == 0 {
builder = builder.header("$headerName", "");
}""",
)
rustBlock("else") {
rustBlock("for ${loopVariable.name} in ${context.valueExpression.asRef()}") {
this.renderHeaderValue(
headerName,
loopVariable,
model.expectShape(shape.member.target),
isMultiValuedHeader = true,
timestampFormat,
renderErrorMessage,
serializeIfDefault = true,
shape.member,
)
}
}
}

Expand Down Expand Up @@ -671,14 +680,12 @@ class HttpBindingGenerator(
val safeName = safeName("formatted")
rustTemplate(
"""
let $safeName = $formatted;
if !$safeName.is_empty() {
let header_value = $safeName;
let header_value: #{HeaderValue} = header_value.parse().map_err(|err| {
#{invalid_field_error:W}
})?;
builder = builder.header("$headerName", header_value);
}
let header_value = $formatted;
let header_value: #{HeaderValue} = header_value.parse().map_err(|err| {
#{invalid_field_error:W}
})?;
builder = builder.header("$headerName", header_value);
""",
"HeaderValue" to RuntimeType.Http.resolve("HeaderValue"),
"invalid_field_error" to renderErrorMessage("header_value"),
Expand Down

0 comments on commit 2a7b98b

Please sign in to comment.