Skip to content

Commit

Permalink
Added status code 406 for unsupported Accept values
Browse files Browse the repository at this point in the history
  • Loading branch information
x7airworker committed Oct 31, 2023
1 parent c6b9a7f commit 402aff7
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ public String transform(Exchange exchange, Object object) {
if (rawAccept != null) {
HeaderValue accept = new HeaderValue(rawAccept);

exchange.contentType(rawAccept);
switch (accept.getValue().toLowerCase()) {
case "application/x-yaml":
case "application/yaml":
case "text/yaml":
case "text/x-yaml":
exchange.contentType(rawAccept);
return this.mapper.map(object).toYaml();
case "application/x-www-form-urlencoded":
exchange.contentType(rawAccept);
return this.mapper.map(object).toFormDataString();
case "application/json":
return this.mapper.map(object).toJsonString();
default:
exchange.status(406);
return "Not Acceptable";
}
}

Expand Down

0 comments on commit 402aff7

Please sign in to comment.