Skip to content

Commit

Permalink
Add lenient mode to MediaType parser
Browse files Browse the repository at this point in the history
Users often find it surprising that methods like message.contentType()
can throw IllegalArgumentException when the media type is invalid. So
this adds a MediaType.parseLeniently() method that tries to recover from
 invalid media type strings and uses it in such cases.

Fixes #83
  • Loading branch information
ato committed Feb 14, 2024
1 parent 29afed7 commit 6ac5da8
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/org/netpreserve/jwarc/GeminiResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public MediaType contentType() {
if (meta.isEmpty()) {
return MediaType.parse("text/gemini; charset=utf-8");
}
return MediaType.parse(meta);
return MediaType.parseLeniently(meta);
} else {
return MediaType.OCTET_STREAM;
}
Expand Down
Loading

0 comments on commit 6ac5da8

Please sign in to comment.