httpcachecontrol.java
来自「很棒的web服务器源代码」· Java 代码 · 共 835 行 · 第 1/2 页
JAVA
835 行
setDirective(NOCACHE); nocache = fields; invalidateByteValue(); } } /** * Set the <code>no-cache</code> directive globally. */ public void setNoCache() { validate(); setDirective(NOCACHE); invalidateByteValue(); } /** * Add the given header name to the <code>no-cache</code> directive. * @param name The header name to add. */ public void addNoCache(String name) { validate(); // If no-cache is set globally, then skip... if ( checkDirective(NOCACHE) && (nocache.length == 0)) return; // Add or test for presence if ( nocache != null ) { // Check for that header name presence: for (int i = 0 ; i < nocache.length ; i++) if (nocache[i].equalsIgnoreCase(name)) return; invalidateByteValue(); String newcache[] = new String[nocache.length+1]; System.arraycopy(nocache, 0, newcache, 0, nocache.length); newcache[nocache.length] = name; nocache = newcache; } else { invalidateByteValue(); nocache = new String[1]; nocache[0] = name; } setDirective(NOCACHE); } /** * Unset the <code>no-cache</code> directive. */ public void unsetNoCache() { validate(); if ( checkDirective(NOCACHE) ) { invalidateByteValue(); unsetDirective(NOCACHE); nocache = null; } } /** * Is the no-store flag set ? * @return A boolean. */ public boolean checkNoStore() { validate(); return checkDirective(NOSTORE) ? nostore : false; } /** * Set the <code>no-store</code> flag. * @param onoff The value for the no-store directive. */ public void setNoStore(boolean onoff) { validate(); if ( onoff == false ) { if ( nostore ) { invalidateByteValue(); nostore = false; } unsetDirective(NOSTORE); } else if ( ! nostore ) { invalidateByteValue(); setDirective(NOSTORE); nostore = true; } } /** * Get the max-age value defined by this cache control policy. * @return The max-age value, or <strong>-1</strong> if undefined. */ public final int getMaxAge() { validate(); return checkDirective(MAXAGE) ? maxage : -1; } /** * Set the max-age directive for this cache control. * @param age The max allowed age for the cache control policy, or * <strong>-1</strong> to reset value. */ public void setMaxAge(int age) { validate(); if ( age == -1 ) { if ( checkDirective(MAXAGE) ) invalidateByteValue(); maxage = -1; unsetDirective(MAXAGE); } else { if ((age != maxage) || ! checkDirective(MAXAGE)) invalidateByteValue(); setDirective(MAXAGE); maxage = age; } } /** * Get the s-maxage value defined by this cache control policy. * @return The s-maxage value, or <strong>-1</strong> if undefined. */ public final int getSMaxAge() { validate(); return checkDirective(S_MAXAGE) ? s_maxage : -1; } /** * Set the s_maxage directive for this cache control. * @param age The max allowed age for the cache control policy, or * <strong>-1</strong> to reset value. */ public void setSMaxAge(int age) { validate(); if ( age == -1 ) { if ( checkDirective(S_MAXAGE) ) invalidateByteValue(); s_maxage = -1; unsetDirective(S_MAXAGE); } else { if ((age != s_maxage) || ! checkDirective(S_MAXAGE)) invalidateByteValue(); setDirective(S_MAXAGE); s_maxage = age; } } /** * Get the max-stale value defined by this control object. * @return The max-stale value, or <strong>-1</strong> if undefined. */ public int getMaxStale() { validate(); return checkDirective(MAXSTALE) ? maxstale : -1; } /** * Set the max-stale directive value. * @param stale The max-stale value, or <strong>-1</strong> to reset value. */ public void setMaxStale(int stale) { validate(); if ( stale == -1 ) { if ( checkDirective(MAXSTALE) ) invalidateByteValue(); maxstale = -1; unsetDirective(MAXSTALE); } else { if ((stale != maxstale) || ! checkDirective(MAXSTALE)) invalidateByteValue(); setDirective(MAXSTALE); maxstale = stale; } } /** * Get the min-fresh directive value. * @param def The default value to reurn if undefined. */ public int getMinFresh() { validate(); return checkDirective(MINFRESH) ? minfresh : -1; } /** * Set the minfresh directive value. * @param fresh The new minfresh value, or <strong>-1</strong> to reset * value. */ public void setMinFresh(int fresh) { validate(); if ( fresh == -1 ) { if ( checkDirective(MINFRESH) ) invalidateByteValue(); minfresh = -1; unsetDirective(MINFRESH); } else { if ((fresh != minfresh) || ! checkDirective(MINFRESH)) invalidateByteValue(); setDirective(MINFRESH); minfresh = fresh; } } /** * Is the on-if-cached flag value set ? * @return A boolean. */ public boolean checkOnlyIfCached() { validate(); return onlyifcached; } /** * Set the only-if-cached directive. * @param onoff The boolean value for the directive. */ public void setOnlyIfCached(boolean onoff) { validate(); if ( ! onoff ) { if ( onlyifcached ) { invalidateByteValue(); onlyifcached = false; } unsetDirective(ONLYIFCACHED); } else if ( ! onlyifcached ) { invalidateByteValue(); setDirective(ONLYIFCACHED); onlyifcached = true; } } /** * Is the public flag set ? * @return A boolean. */ public boolean checkPublic() { validate(); return pub; } /** * Set the public directive. * @param onoff The public directive value. */ public void setPublic(boolean onoff) { validate(); if ( ! onoff ) { if ( pub ) { invalidateByteValue(); pub = false; } unsetDirective(PUB); } else if ( ! pub ) { invalidateByteValue(); setDirective(PUB); pub = true; } } /** * Check and get the private value. * @param def The default value if undefined. * @return A list of field-names, as a String array, or the provided * default value otherwise. */ public String[] getPrivate() { validate(); return (priv == null) ? null : priv; } /** * Set the private directive value. * @param priv The list of field-names as a String array. */ public void setPrivate(String priv[]) { validate(); invalidateByteValue(); setDirective(PRIV); this.priv = priv; } /** * Unset the <code>private</code> directive. */ public void unsetPrivate() { validate(); if ( checkDirective(PRIV) ) invalidateByteValue(); unsetDirective(PRIV); priv = null; } /** * Is the no-transform flag set ? * @return A boolean. */ public boolean checkNoTransform() { validate(); return notransform; } /** * Set the no-transform directive. * @param onoff The new boolean value for the no-transform directive. */ public void setNoTransform(boolean onoff) { validate(); if ( ! onoff ) { if ( notransform ) { invalidateByteValue(); notransform = false; } unsetDirective(NOTRANSFORM); } else if ( ! notransform ) { invalidateByteValue(); setDirective(NOTRANSFORM); notransform = true; } } /** * Is the must-revalidate flag set ? * @return A boolean. */ public boolean checkMustRevalidate() { validate(); return mustrevalidate; } /** * Set the must-revalidate directive. * @param onoff The new value for the must-revalidate directive. */ public void setMustRevalidate(boolean onoff) { validate(); if ( ! onoff ) { if ( mustrevalidate ) { invalidateByteValue(); mustrevalidate = false; } unsetDirective(MUSTREVALIDATE); } else if ( ! mustrevalidate ) { invalidateByteValue(); setDirective(MUSTREVALIDATE); mustrevalidate = true; } } /** * Is the proxy-revalidate flag set ? * @return A boolean. */ public boolean checkProxyRevalidate() { validate(); return proxyrevalidate; } /** * Set the proxy-revalidate directive. * @param onoff The new proxy-revalidate value. */ public void setProxyRevalidate(boolean onoff) { validate(); if ( ! onoff ) { if ( proxyrevalidate ) { invalidateByteValue(); proxyrevalidate = false; } unsetDirective(PROXYREVALIDATE); } else if ( ! proxyrevalidate ) { invalidateByteValue(); setDirective(PROXYREVALIDATE); proxyrevalidate = true; } } /** * Create a new empty HttpCacheControl object descriptor. * @param isValid A boolean indicating if this object will be filled in * by parsing a value, or is for internal purposes. */ HttpCacheControl(boolean isValid) { this.raw = null ; this.isValid = isValid; } /** * Create a new empty cache control object descriptor. * The value will be provided through parsing. */ public HttpCacheControl() { this(false); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?