public final class AcceptHeader extends Object
Typical usage:
HttpResponse doXyz(@Header("Accept") AcceptHeader accept, ...) { swtich (accept.select("application/json","text/xml")) { case "application/json": ... case "text/html": ... } }
A port to Java of Joe Gregorio's MIME-Type Parser: http://code.google.com/p/mimeparse/ Ported by Tom Zellman <tzellman@gmail.com>.
Modifier and Type | Class and Description |
---|---|
protected static class |
AcceptHeader.Atom
Media range plus parameters and extensions
|
static class |
AcceptHeader.StaplerConverterImpl |
Constructor and Description |
---|
AcceptHeader(String ranges)
Parse the accept header value into a typed object.
|
Modifier and Type | Method and Description |
---|---|
protected AcceptHeader.Atom |
match(String mimeType)
Given a MIME type, find the entry from this Accept header that fits the best.
|
String |
select(Iterable<String> supported)
Takes a list of supported mime-types and finds the best match for all the
media-ranges listed in header.
|
String |
select(String... supported) |
String |
toString() |
public AcceptHeader(String ranges)
ranges
- something like "text/*;q=0.5,*; q=0.1"@Nullable protected AcceptHeader.Atom match(String mimeType)
mimeType
- public String select(Iterable<String> supported)
// Client: I prefer text/*, but if not I'm happy to take anything // Server: I can serve you xbel or xml // Result: let's serve you text/xml new AcceptHeader("text/*;q=0.5, *;q=0.1").select("application/xbel+xml", "text/xml") => "text/xml" // Client: I want image, ideally PNG // Server: I can give you plain text or XML // Result: there's nothing to serve you here new AcceptHeader("image/*;q=0.5, image/png;q=1").select("text/plain","text/xml") => null
supported
is acceptable to the client.Copyright © 2016. All rights reserved.