Content negotiation is a mechanism defined in the HTTP specification that makes it possible to serve different versions of a document (or more generally, a resource representation) at the same URI, so that user agents can specify which version fit their capabilities the best.
ConNeg is used in Fuseki to help matching the content media type requested by the user, against the list of offered media types.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MediaType
chooseCharset
(javax.servlet.http.HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType) Chooses the charset by using the Accept-Charset HTTP header.static MediaType
chooseContentType
(javax.servlet.http.HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType) Choose the content media type by extracting the Accept HTTP header from the HTTP request and choosing (seechoose(String, AcceptList, MediaType)
) a content media type that matches the header.static String
Match a single media type against a header string.static MediaType
match
(String headerString, AcceptList offerList) Creates aAcceptList
with the given HTTP header string and uses theAcceptList.match(MediaType)
method to decide which media type matches the HTTP header string.static MediaType
Parses the content type.
-
Constructor Details
-
ConNeg
public ConNeg()
-
-
Method Details
-
parse
Parses the content type. It splits the string by semi-colon and finds the other features such as the "q" quality factor. For a complete documentation on how the parsing happens, see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.1.- Parameters:
contentType
- content type string- Returns:
- parsed media type
-
match
Creates a
AcceptList
with the given HTTP header string and uses theAcceptList.match(MediaType)
method to decide which media type matches the HTTP header string.The q quality factor is used to decide which choice is the best match.
- Parameters:
headerString
- HTTP header stringofferList
- accept list- Returns:
- matched media type
-
match
Match a single media type against a header string.- Parameters:
headerString
- HTTP header stringmediaRangeStr
- Semi-colon separated list of media types- Returns:
- the matched media type or
null
if there was no match
-
chooseCharset
public static MediaType chooseCharset(javax.servlet.http.HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType) Chooses the charset by using the Accept-Charset HTTP header.
See
choose(String, AcceptList, MediaType)
.- Parameters:
httpRequest
- HTTP requestmyPrefs
- accept listdefaultMediaType
- default media type- Returns:
- media type chosen
-
chooseContentType
public static MediaType chooseContentType(javax.servlet.http.HttpServletRequest httpRequest, AcceptList myPrefs, MediaType defaultMediaType) Choose the content media type by extracting the Accept HTTP header from the HTTP request and choosing (see
choose(String, AcceptList, MediaType)
) a content media type that matches the header.- Parameters:
httpRequest
- HTTP requestmyPrefs
- accept listdefaultMediaType
- default media type- Returns:
- media type chosen
-