Skip to content

Commit

Permalink
Noops when encoding an empty body in xml
Browse files Browse the repository at this point in the history
  • Loading branch information
epau committed Nov 16, 2022
1 parent 9c48ff6 commit f5eb55b
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,11 @@ class HttpBodyMiddleware(
renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
}
writer.indent()
writer.openBlock("if encoder is JSONEncoder {", "} else if encoder is XMLEncoder {") {
writer.openBlock("if encoder is JSONEncoder {", "}") {
writer.write("// Encode an empty body as an empty structure in JSON")
writer.write("let \$L = \"{}\".data(using: .utf8)!", dataDeclaration)
renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
}
writer.indent()
writer.write("// Encode an empty body as an empty string in XML")
writer.write("let \$L = \"\".data(using: .utf8)!", dataDeclaration)
renderEncodedBodyAddedToRequest(bodyDeclaration, dataDeclaration)
writer.dedent()
writer.write("}")
writer.dedent()
writer.write("}")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ class HttpBodyMiddlewareTests {
let payload1data = "{}".data(using: .utf8)!
let payload1body = ClientRuntime.HttpBody.data(payload1data)
input.builder.withBody(payload1body)
} else if encoder is XMLEncoder {
// Encode an empty body as an empty string in XML
let payload1data = "".data(using: .utf8)!
let payload1body = ClientRuntime.HttpBody.data(payload1data)
input.builder.withBody(payload1body)
}
}
} catch let err {
Expand Down

0 comments on commit f5eb55b

Please sign in to comment.