Class UserAgentUtil
java.lang.Object
uk.ac.starlink.vo.UserAgentUtil
Utilities for manipulating the HTTP
User-Agent
header from the JVM, following IVOA usage conventions.
These conventions are codified in the
SoftID IVOA Note.
Typical usage for a validator client would be:
String uaComment = UserAgentUtil.COMMENT_TEST; // "(IVOA-test)" UserAgentUtil.pushUserAgentToken( uaComment ); ... do validation ... UserAgentUtil.popUserAgentToken( uaComment );
- Since:
- 12 Apr 2019
- Author:
- Mark Taylor
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSystem property that can be used to manipulate the UserAgent header.static final StringComment token indicating client performs VO copy/mirror/harvest.static final StringComment token indicating client performs VO test/monitor/validate.static final StringString prefixed to purpose verb to introduce IVOA operation comment.static final StringPurpose verb indicating copying/mirroring/harvesting: "copy".static final StringPurpose verb indicating testing/monitoring/validation: "test". -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateOpPurposeComment(String purpose, String extra) Assembles a string of the form(IVOA-<purpose> <extra>).static String[]parseProducts(String productsTxt) Parses a products string as found in the HTTP User-Agent or Server header.static voidpopUserAgentToken(String token) Removes a token/comment from the currently-used User-Agent string.static voidpushUserAgentToken(String token) Appends a token/comment to the currently used User-Agent string.
-
Field Details
-
PURPOSE_TEST
Purpose verb indicating testing/monitoring/validation: "test".- See Also:
-
PURPOSE_COPY
Purpose verb indicating copying/mirroring/harvesting: "copy".- See Also:
-
IVOA_PREFIX
String prefixed to purpose verb to introduce IVOA operation comment.- See Also:
-
COMMENT_TEST
Comment token indicating client performs VO test/monitor/validate. -
COMMENT_COPY
Comment token indicating client performs VO copy/mirror/harvest. -
AGENT_PROPNAME
System property that can be used to manipulate the UserAgent header.- See Also:
-
-
Method Details
-
pushUserAgentToken
Appends a token/comment to the currently used User-Agent string. This does not overwrite existing text, which is in general useful.- Parameters:
token- string to add
-
popUserAgentToken
Removes a token/comment from the currently-used User-Agent string. This only has effect if the given token is at the end of the current list, that is if it has just been added. If it's not present or not at the end, a warning is logged and there is no other effect.- Parameters:
token- previously added string to remove
-
createOpPurposeComment
Assembles a string of the form(IVOA-<purpose> <extra>).- Parameters:
purpose- operational purpose string; recommended values arePURPOSE_*static members of this classextra- free form additional text excluding "(" or ")"; may be null- Returns:
- string suitable for User-Agent header comment
- Throws:
IllegalArgumentException- if rudimentary syntax checking detects errors
-
parseProducts
Parses a products string as found in the HTTP User-Agent or Server header. See RFC 7231 sec 5.5.3 and RFC 7230 sec 3.2.6 for the relevant syntax productions.- Parameters:
productsTxt- string giving product and comment tokens as found in User-Agent or Server header- Returns:
- array of tokens; each may be either a product or a comment; comments start with a "("
- Throws:
IllegalArgumentException- if the syntax is not as required
-