@@ -1746,6 +1746,9 @@ private void handleContentType(
1746
1746
* text/plain for a string.
1747
1747
* - If the output shape has no members with the httpPayload trait, the accept header must match
1748
1748
* the default protocol document content type if present.
1749
+ *
1750
+ * Note: matching is performed based on the rules in https://datatracker.ietf.org/doc/html/rfc7231#section-5.3.2
1751
+ * and any match is considered acceptable, regardless of the supplied accept-params.
1749
1752
*/
1750
1753
private void handleAccept (
1751
1754
GenerationContext context ,
@@ -1766,16 +1769,16 @@ private void handleAccept(
1766
1769
writer .addImport ("NotAcceptableException" ,
1767
1770
"__NotAcceptableException" ,
1768
1771
"@aws-smithy/server-common" );
1772
+ writer .addImport ("acceptMatches" , "__acceptMatches" , "@aws-smithy/server-common" );
1769
1773
writer .write ("const acceptHeaderKey: string | undefined = Object.keys(output.headers)"
1770
1774
+ ".find(key => key.toLowerCase() === 'accept');" );
1771
1775
writer .openBlock ("if (acceptHeaderKey !== undefined && acceptHeaderKey !== null) {" , "};" , () -> {
1772
1776
writer .write ("const accept = output.headers[acceptHeaderKey];" );
1773
1777
String contentType = optionalContentType .orElse (getDocumentContentType ());
1774
1778
// Validate that the content type matches the protocol default, or what's modeled if there's
1775
1779
// a modeled type.
1776
- writer .openBlock ("if (accept !== undefined && accept !== $S) {" , "};" , contentType , () -> {
1777
- writer .write ("throw new __NotAcceptableException();" );
1778
- });
1780
+ writer .openBlock ("if (!__acceptMatches(accept, $S)) {" , "};" , contentType ,
1781
+ () -> writer .write ("throw new __NotAcceptableException();" ));
1779
1782
});
1780
1783
}
1781
1784
0 commit comments