larksuite-oapi/src/main/java/com/larksuite/oapi/okhttp3_14/CacheControl.java
public static CacheControl parse(Headers headers) {
    boolean noCache = false;
    boolean noStore = false;
    int maxAgeSeconds = -1;
    int sMaxAgeSeconds = -1;
    boolean isPrivate = false;
    boolean isPublic = false;
    boolean mustRevalidate = false;
    int maxStaleSeconds = -1;
    int minFreshSeconds = -1;
    boolean onlyIfCached = false;
    boolean noTransform = false;
    boolean immutable = false;

    boolean canUseHeaderValue = true;
    String headerValue = null;

    for (int i = 0, size = headers.size(); i < size; i++) {
      String name = headers.name(i);
      String value = headers.value(i);

      if (name.equalsIgnoreCase("Cache-Control")) {
        if (headerValue != null) {
          // Multiple cache-control headers means we can't use the raw value.
          canUseHeaderValue = false;
        } else {
          headerValue = value;
        }
      } else if (name.equalsIgnoreCase("Pragma")) {
        // Might specify additional cache-control params. We invalidate just in case.
        canUseHeaderValue = false;
      } else {
        continue;
      }

      int pos = 0;
      while (pos < value.length()) {
        int tokenStart = pos;
        pos = HttpHeaders.skipUntil(value, pos, "=,;");
        String directive = value.substring(tokenStart, pos).trim();
        String parameter;

        if (pos == value.length() || value.charAt(pos) == ',' || value.charAt(pos) == ';') {
          pos++; // consume ',' or ';' (if necessary)
          parameter = null;
        } else {
          pos++; // consume '='
          pos = HttpHeaders.skipWhitespace(value, pos);

          // quoted string
          if (pos < value.length() && value.charAt(pos) == '\"') {
            pos++; // consume '"' open quote
            int parameterStart = pos;
            pos = HttpHeaders.skipUntil(value, pos, "\"");
            parameter = value.substring(parameterStart, pos);
            pos++; // consume '"' close quote (if necessary)

            // unquoted string
          } else {
            int parameterStart = pos;
            pos = HttpHeaders.skipUntil(value, pos, ",;");
            parameter = value.substring(parameterStart, pos).trim();
          }
        }

        if ("no-cache".equalsIgnoreCase(directive)) {
          noCache = true;
        } else if ("no-store".equalsIgnoreCase(directive)) {
          noStore = true;
        } else if ("max-age".equalsIgnoreCase(directive)) {
          maxAgeSeconds = HttpHeaders.parseSeconds(parameter, -1);
        } else if ("s-maxage".equalsIgnoreCase(directive)) {
          sMaxAgeSeconds = HttpHeaders.parseSeconds(parameter, -1);
        } else if ("private".equalsIgnoreCase(directive)) {
          isPrivate = true;
        } else if ("public".equalsIgnoreCase(directive)) {
          isPublic = true;
        } else if ("must-revalidate".equalsIgnoreCase(directive)) {
          mustRevalidate = true;
        } else if ("max-stale".equalsIgnoreCase(directive)) {
          maxStaleSeconds = HttpHeaders.parseSeconds(parameter, Integer.MAX_VALUE);
        } else if ("min-fresh".equalsIgnoreCase(directive)) {
          minFreshSeconds = HttpHeaders.parseSeconds(parameter, -1);
        } else if ("only-if-cached".equalsIgnoreCase(directive)) {
          onlyIfCached = true;
        } else if ("no-transform".equalsIgnoreCase(directive)) {
          noTransform = true;
        } else if ("immutable".equalsIgnoreCase(directive)) {
          immutable = true;
        }
      }
    }

    if (!canUseHeaderValue) {
      headerValue = null;
    }
    return new CacheControl(noCache, noStore, maxAgeSeconds, sMaxAgeSeconds, isPrivate, isPublic,
        mustRevalidate, maxStaleSeconds, minFreshSeconds, onlyIfCached, noTransform, immutable,
        headerValue);
  }
/**
   * Returns the cache directives of {@code headers}. This honors both Cache-Control and Pragma
   * headers if they are present.
   */
Returns the cache directives of  headers. This honors both Cache-Control and Pragma
headers if they are present.
Returns the cache directives of headers . This honors both Cache - Control and Pragma headers if they are present .
public static CacheControl parse(Headers headers) {
    boolean noCache = false;
    boolean noStore = false;
    int maxAgeSeconds = -1;
    int sMaxAgeSeconds = -1;
    boolean isPrivate = false;
    boolean isPublic = false;
    boolean mustRevalidate = false;
    int maxStaleSeconds = -1;
    int minFreshSeconds = -1;
    boolean onlyIfCached = false;
    boolean noTransform = false;
    boolean immutable = false;
    boolean canUseHeaderValue = true;
    String headerValue = null;
    for (int i = 0, size = headers.size(); i < size; i++) {
      String name = headers.name(i);
      String value = headers.value(i);
      if (name.equalsIgnoreCase("Cache-Control")) {
        if (headerValue != null) {
          canUseHeaderValue = false;
        } else {
          headerValue = value;
        }
      } else if (name.equalsIgnoreCase("Pragma")) {
        canUseHeaderValue = false;
      } else {
        continue;
      }
      int pos = 0;
      while (pos < value.length()) {
        int tokenStart = pos;
        pos = HttpHeaders.skipUntil(value, pos, "=,;");
        String directive = value.substring(tokenStart, pos).trim();
        String parameter;
        if (pos == value.length() || value.charAt(pos) == ',' || value.charAt(pos) == ';') {
          pos++; 
          parameter = null;
        } else {
          pos++; 
          pos = HttpHeaders.skipWhitespace(value, pos);
          if (pos < value.length() && value.charAt(pos) == '\"') {
            pos++; 
            int parameterStart = pos;
            pos = HttpHeaders.skipUntil(value, pos, "\"");
            parameter = value.substring(parameterStart, pos);
            pos++; 
          } else {
            int parameterStart = pos;
            pos = HttpHeaders.skipUntil(value, pos, ",;");
            parameter = value.substring(parameterStart, pos).trim();
          }
        }
        if ("no-cache".equalsIgnoreCase(directive)) {
          noCache = true;
        } else if ("no-store".equalsIgnoreCase(directive)) {
          noStore = true;
        } else if ("max-age".equalsIgnoreCase(directive)) {
          maxAgeSeconds = HttpHeaders.parseSeconds(parameter, -1);
        } else if ("s-maxage".equalsIgnoreCase(directive)) {
          sMaxAgeSeconds = HttpHeaders.parseSeconds(parameter, -1);
        } else if ("private".equalsIgnoreCase(directive)) {
          isPrivate = true;
        } else if ("public".equalsIgnoreCase(directive)) {
          isPublic = true;
        } else if ("must-revalidate".equalsIgnoreCase(directive)) {
          mustRevalidate = true;
        } else if ("max-stale".equalsIgnoreCase(directive)) {
          maxStaleSeconds = HttpHeaders.parseSeconds(parameter, Integer.MAX_VALUE);
        } else if ("min-fresh".equalsIgnoreCase(directive)) {
          minFreshSeconds = HttpHeaders.parseSeconds(parameter, -1);
        } else if ("only-if-cached".equalsIgnoreCase(directive)) {
          onlyIfCached = true;
        } else if ("no-transform".equalsIgnoreCase(directive)) {
          noTransform = true;
        } else if ("immutable".equalsIgnoreCase(directive)) {
          immutable = true;
        }
      }
    }
    if (!canUseHeaderValue) {
      headerValue = null;
    }
    return new CacheControl(noCache, noStore, maxAgeSeconds, sMaxAgeSeconds, isPrivate, isPublic,
        mustRevalidate, maxStaleSeconds, minFreshSeconds, onlyIfCached, noTransform, immutable,
        headerValue);
  }
public static CacheControl parse ( Headers headers ) { boolean noCache = false ; boolean noStore = false ; int maxAgeSeconds = - 1 ; int sMaxAgeSeconds = - 1 ; boolean isPrivate = false ; boolean isPublic = false ; boolean mustRevalidate = false ; int maxStaleSeconds = - 1 ; int minFreshSeconds = - 1 ; boolean onlyIfCached = false ; boolean noTransform = false ; boolean immutable = false ; boolean canUseHeaderValue = true ; String headerValue = null ; for ( int i = 0 , size = headers . size ( ) ; i < size ; i ++ ) { String name = headers . name ( i ) ; String value = headers . value ( i ) ; if ( name . equalsIgnoreCase ( "Cache-Control" ) ) { if ( headerValue != null ) { canUseHeaderValue = false ; } else { headerValue = value ; } } else if ( name . equalsIgnoreCase ( "Pragma" ) ) { canUseHeaderValue = false ; } else { continue ; } int pos = 0 ; while ( pos < value . length ( ) ) { int tokenStart = pos ; pos = HttpHeaders . skipUntil ( value , pos , "=,;" ) ; String directive = value . substring ( tokenStart , pos ) . trim ( ) ; String parameter ; if ( pos == value . length ( ) || value . charAt ( pos ) == ',' || value . charAt ( pos ) == ';' ) { pos ++ ; parameter = null ; } else { pos ++ ; pos = HttpHeaders . skipWhitespace ( value , pos ) ; if ( pos < value . length ( ) && value . charAt ( pos ) == '\"' ) { pos ++ ; int parameterStart = pos ; pos = HttpHeaders . skipUntil ( value , pos , "\"" ) ; parameter = value . substring ( parameterStart , pos ) ; pos ++ ; } else { int parameterStart = pos ; pos = HttpHeaders . skipUntil ( value , pos , ",;" ) ; parameter = value . substring ( parameterStart , pos ) . trim ( ) ; } } if ( "no-cache" . equalsIgnoreCase ( directive ) ) { noCache = true ; } else if ( "no-store" . equalsIgnoreCase ( directive ) ) { noStore = true ; } else if ( "max-age" . equalsIgnoreCase ( directive ) ) { maxAgeSeconds = HttpHeaders . parseSeconds ( parameter , - 1 ) ; } else if ( "s-maxage" . equalsIgnoreCase ( directive ) ) { sMaxAgeSeconds = HttpHeaders . parseSeconds ( parameter , - 1 ) ; } else if ( "private" . equalsIgnoreCase ( directive ) ) { isPrivate = true ; } else if ( "public" . equalsIgnoreCase ( directive ) ) { isPublic = true ; } else if ( "must-revalidate" . equalsIgnoreCase ( directive ) ) { mustRevalidate = true ; } else if ( "max-stale" . equalsIgnoreCase ( directive ) ) { maxStaleSeconds = HttpHeaders . parseSeconds ( parameter , Integer . MAX_VALUE ) ; } else if ( "min-fresh" . equalsIgnoreCase ( directive ) ) { minFreshSeconds = HttpHeaders . parseSeconds ( parameter , - 1 ) ; } else if ( "only-if-cached" . equalsIgnoreCase ( directive ) ) { onlyIfCached = true ; } else if ( "no-transform" . equalsIgnoreCase ( directive ) ) { noTransform = true ; } else if ( "immutable" . equalsIgnoreCase ( directive ) ) { immutable = true ; } } } if ( ! canUseHeaderValue ) { headerValue = null ; } return new CacheControl ( noCache , noStore , maxAgeSeconds , sMaxAgeSeconds , isPrivate , isPublic , mustRevalidate , maxStaleSeconds , minFreshSeconds , onlyIfCached , noTransform , immutable , headerValue ) ; }
Returns the cache directives of {@code headers}.
Returns the cache directives of { @code headers } .
// Multiple cache-control headers means we can't use the raw value. // Might specify additional cache-control params. We invalidate just in case. // consume ',' or ';' (if necessary) // consume '=' // quoted string // consume '"' open quote // consume '"' close quote (if necessary) // unquoted string