@@ -1679,6 +1679,22 @@ private void generateOperationRequestDeserializer(
1679
1679
writer .write ("" );
1680
1680
}
1681
1681
1682
+ /**
1683
+ * Writes out handling for the content-type header. The following rules apply:
1684
+ *
1685
+ * - The content-type header may always be omitted.
1686
+ * - If the input shape has a member with the httpPaylaod trait then the following apply:
1687
+ * - If the target is a shape with the mediaType trait, the value of the content-type header must
1688
+ * match if present.
1689
+ * - If the target is a blob shape without a media type, the content-type header may have any value.
1690
+ * - Otherwise the content-type header must match the implied content type of the target shape, e.g.
1691
+ * text/plain for a string.
1692
+ * - If the input shape has no members with the httpPayload trait, but does have members bound to
1693
+ * the document, the content-type header must match the default protocol document content type if
1694
+ * present.
1695
+ * - If the input shape has no members bound to the payload / document, the content-type header
1696
+ * must not be set.
1697
+ */
1682
1698
private void handleContentType (
1683
1699
GenerationContext context ,
1684
1700
OperationShape operation ,
@@ -1717,6 +1733,19 @@ private void handleContentType(
1717
1733
});
1718
1734
}
1719
1735
1736
+ /**
1737
+ * Writes out handling for the accept header. The following rules apply:
1738
+ *
1739
+ * - The accept header may always be omitted.
1740
+ * - If the output shape has a member with the httpPaylaod trait then the following apply:
1741
+ * - If the target is a shape with the mediaType trait, the value of the accept header must
1742
+ * match if present.
1743
+ * - If the target is a blob shape without a media type, the accept header may have any value.
1744
+ * - Otherwise the accept header must match the implied content type of the target shape, e.g.
1745
+ * text/plain for a string.
1746
+ * - If the output shape has no members with the httpPayload trait, the accept header must match
1747
+ * the default protocol document content type if present.
1748
+ */
1720
1749
private void handleAccept (
1721
1750
GenerationContext context ,
1722
1751
OperationShape operation ,
@@ -1740,18 +1769,12 @@ private void handleAccept(
1740
1769
+ ".find(key => key.toLowerCase() === 'accept');" );
1741
1770
writer .openBlock ("if (acceptHeaderKey !== undefined && acceptHeaderKey !== null) {" , "};" , () -> {
1742
1771
writer .write ("const accept = output.headers[acceptHeaderKey];" );
1743
- if (optionalContentType .isPresent () || operation .getOutput ().isPresent ()) {
1744
- String contentType = optionalContentType .orElse (getDocumentContentType ());
1745
- // If the operation will return a content type, ensure that the accept matches.
1746
- writer .openBlock ("if (accept !== undefined && accept !== $S) {" , "};" , contentType , () -> {
1747
- writer .write ("throw new __NotAcceptableException();" );
1748
- });
1749
- } else {
1750
- // If the operation won't return a content-type, ensure that accept isn't set.
1751
- writer .openBlock ("if (accept !== undefined) {" , "};" , () -> {
1752
- writer .write ("throw new __NotAcceptableException();" );
1753
- });
1754
- }
1772
+ String contentType = optionalContentType .orElse (getDocumentContentType ());
1773
+ // Validate that the content type matches the protocol default, or what's modeled if there's
1774
+ // a modeled type.
1775
+ writer .openBlock ("if (accept !== undefined && accept !== $S) {" , "};" , contentType , () -> {
1776
+ writer .write ("throw new __NotAcceptableException();" );
1777
+ });
1755
1778
});
1756
1779
}
1757
1780
0 commit comments