Class UserAgentUtil

java.lang.Object
uk.ac.starlink.vo.UserAgentUtil

public class UserAgentUtil extends Object
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 Details

    • PURPOSE_TEST

      public static final String PURPOSE_TEST
      Purpose verb indicating testing/monitoring/validation: "test".
      See Also:
    • PURPOSE_COPY

      public static final String PURPOSE_COPY
      Purpose verb indicating copying/mirroring/harvesting: "copy".
      See Also:
    • IVOA_PREFIX

      public static final String IVOA_PREFIX
      String prefixed to purpose verb to introduce IVOA operation comment.
      See Also:
    • COMMENT_TEST

      public static final String COMMENT_TEST
      Comment token indicating client performs VO test/monitor/validate.
    • COMMENT_COPY

      public static final String COMMENT_COPY
      Comment token indicating client performs VO copy/mirror/harvest.
    • AGENT_PROPNAME

      public static final String AGENT_PROPNAME
      System property that can be used to manipulate the UserAgent header.
      See Also:
  • Method Details

    • pushUserAgentToken

      public static void pushUserAgentToken(String token)
      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

      public static void popUserAgentToken(String token)
      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

      public static String createOpPurposeComment(String purpose, String extra)
      Assembles a string of the form (IVOA-<purpose> <extra>).
      Parameters:
      purpose - operational purpose string; recommended values are PURPOSE_* static members of this class
      extra - 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

      public static String[] parseProducts(String productsTxt)
      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