We're using the Jersey reference implementation of Jax-RS. The Jax-RS client implementation of Jersey is appending a default accept header to the request if no accept header is specified. The default accept header looks like this:
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
As you can see, it uses a single asterisk '*' as content-type (after image/jpeg).
In the Jax-RS spec (see here), this single * is defined as
/**
* The value of a type or subtype wildcard {@value #MEDIA_TYPE_WILDCARD}.
*/
public static final String MEDIA_TYPE_WILDCARD = "*";
which I interpret as "wildcard for any media type"
The '*/*' is defined as
/**
* A {@code String} constant representing wildcard {@value #WILDCARD} media type .
*/
public final static String WILDCARD = "*/*";
which I interpret as "wildcard for any media range"
However, the HTTP spec (RFC7231) does not mention an "any media type" wildcard, only media-range wildcards:
media-range = ( "*/*"
/ ( type "/" "*" )
/ ( type "/" subtype )
) *( OWS ";" OWS parameter )
(..)
The asterisk "*" character is used to group media types into ranges,
with "*/*" indicating all media types and "type/*" indicating all
subtypes of that type. The media-range can include media type
parameters that are applicable to that range.
Which I interpret as allowed content-types:
- */*
- text/*
- text/plain
in other words, the content type has to be always of the form "something slash something" or "a single * is not a valid content type". Although, the latter is not explicitly stated.
Now both specs are publicly standardized, with the HTTP spec being somewhat the parent document to the Jax-RS spec as Jax-RS is based on HTTP. IMHO both standards contradict each other regarding the wildcard content types.
Question is, what is applicable?
- Is a single asterisk "*" a valid content type (allowing the server to respond with any content type")
- OR should the use of the single asterisk should produce an error? If yes, which one?
- 400 Bad Requst
- 406 not acceptable
- OR should the server be more tolerant and treat the * same as the wildcard */* although * is no valid content type (and probably produce a warning in the log or something)?
Edit
While dealing with Jsoup (not JaxRS/Jersey), I observed, that JSoup is using the same default accept types and it seems, the default headers are an implementation detail of the sun.net.www.protocol.http.HttpURLConnection
static final String acceptString = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
So in case this is a bug, it's not a bug in Jersey, but Java's HttpURLConnection
You say:
I think that is incorrect. It is a wildcard for type or subtype. The wildcard for any media type is defined as
*/*, like in the HTTP spec.Also, when in doubt, follow the HTTP spec. In the end, that is the communication protocol you are using. The other party might not know about the Jax-RS spec.