appIdentifier

fun appIdentifier(name: String, version: String? = null): Gravatar

Identifies the app calling the SDK, for the X-Source header and the User-Agent.

Takes precedence over whatever context derived, whichever order the two are called in, so call this one when the app has a stable name it is already known by server-side. A later context call is then ignored.

Both values end up in a header, so this rejects anything that cannot be sent as one rather than letting OkHttp fail every request later with an opaque error. The name is held to the stricter bar of a User-Agent product token — no whitespace, no /, unaccented ASCII — so that the string a server keys a rule on is exactly the string you passed. A label that only context could produce is cleaned up instead; an identifier you chose is not guessed at.

Parameters

name

The app name, e.g. wp-android.

version

The app version, e.g. 27.6. Omitted from the User-Agent when null, which also discards a version context had already derived — this call states the whole identity.

Throws

if either value is blank, if version holds a character that cannot be sent as a header, such as a newline or anything non-ASCII, or if name is not a product token — whitespace, /, (, ), ; and accented or non-ASCII letters are all rejected, and the message names the token it would have made of what you passed.