Page Speed Optimization Libraries  1.11.33.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
rewrite_options.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_REWRITE_OPTIONS_H_
21 
22 #include <bitset>
23 #include <cstddef>
24 #include <map>
25 #include <set>
26 #include <utility>
27 #include <vector>
28 
29 #include "base/logging.h"
34 #include "pagespeed/kernel/base/basictypes.h"
35 #include "pagespeed/kernel/base/dense_hash_map.h"
36 #include "pagespeed/kernel/base/enum_set.h"
37 #include "pagespeed/kernel/base/fast_wildcard_group.h"
38 #include "pagespeed/kernel/base/gtest_prod.h"
39 #include "pagespeed/kernel/base/hasher.h"
40 #include "pagespeed/kernel/base/md5_hasher.h"
41 #include "pagespeed/kernel/base/proto_util.h"
42 #include "pagespeed/kernel/base/rde_hash_map.h"
43 #include "pagespeed/kernel/base/scoped_ptr.h"
44 #include "pagespeed/kernel/base/sha1_signature.h"
45 #include "pagespeed/kernel/base/string.h"
46 #include "pagespeed/kernel/base/string_hash.h"
47 #include "pagespeed/kernel/base/string_util.h"
48 #include "pagespeed/kernel/base/thread_annotations.h"
49 #include "pagespeed/kernel/base/thread_system.h"
50 #include "pagespeed/kernel/base/wildcard.h"
51 #include "pagespeed/kernel/http/http_names.h"
52 #include "pagespeed/kernel/http/semantic_type.h"
53 #include "pagespeed/kernel/http/user_agent_matcher.h"
54 #include "pagespeed/kernel/util/copy_on_write.h"
55 
56 namespace net_instaweb {
57 
58 class MessageHandler;
59 class PurgeSet;
60 class RequestHeaders;
61 
62 struct HttpOptions;
63 
85  protected:
90  class PropertyBase;
91  template<class ValueType> class Property;
92  template<class RewriteOptionsSubclass, class OptionClass> class PropertyLeaf;
93 
94  public:
107  enum Filter {
109  kAddHead,
110  kAddIds,
111  kAddInstrumentation,
112  kComputeStatistics,
113  kCachePartialHtmlDeprecated,
114  kCanonicalizeJavascriptLibraries,
115  kCollapseWhitespace,
116  kCollectFlushEarlyContentFilter,
117  kCombineCss,
118  kCombineHeads,
119  kCombineJavascript,
120  kComputeCriticalCss,
121  kComputeVisibleTextDeprecated,
122  kConvertGifToPng,
123  kConvertJpegToProgressive,
124  kConvertJpegToWebp,
125  kConvertMetaTags,
126  kConvertPngToJpeg,
127  kConvertToWebpAnimated,
128  kConvertToWebpLossless,
129  kDebug,
130  kDecodeRewrittenUrls,
131  kDedupInlinedImages,
132  kDeferIframe,
133  kDeferJavascript,
134  kDelayImages,
135  kDeterministicJs,
136  kDisableJavascript,
137  kDivStructure,
138  kElideAttributes,
139  kExperimentCollectMobImageInfo,
141  kExplicitCloseTags,
142  kExtendCacheCss,
143  kExtendCacheImages,
144  kExtendCachePdfs,
145  kExtendCacheScripts,
146  kFallbackRewriteCssUrls,
147  kFixReflows,
148  kFlattenCssImports,
149  kFlushSubresources,
150  kHandleNoscriptRedirect,
151  kHtmlWriterFilter,
152  kIncludeJsSourceMaps,
153  kInlineCss,
154  kInlineGoogleFontCss,
155  kInlineImages,
156  kInlineImportToLink,
157  kInlineJavascript,
158  kInPlaceOptimizeForBrowser,
159  kInsertAmpLink,
160  kInsertDnsPrefetch,
161  kInsertGA,
162  kInsertImageDimensions,
163  kJpegSubsampling,
164  kLazyloadImages,
165  kLeftTrimUrls,
166  kLocalStorageCache,
167  kMakeGoogleAnalyticsAsync,
168  kMakeShowAdsAsync,
169  kMobilize,
171  kMoveCssAboveScripts,
172  kMoveCssToHead,
173  kOutlineCss,
174  kOutlineJavascript,
175  kPedantic,
176  kPrioritizeCriticalCss,
177  kRecompressJpeg,
178  kRecompressPng,
179  kRecompressWebp,
180  kRemoveComments,
181  kRemoveQuotes,
182  kResizeImages,
183  kResizeMobileImages,
184  kResizeToRenderedImageDimensions,
185  kResponsiveImages,
186  kResponsiveImagesZoom,
187  kRewriteCss,
188  kRewriteDomains,
189  kRewriteJavascriptExternal,
190  kRewriteJavascriptInline,
191  kRewriteStyleAttributes,
192  kRewriteStyleAttributesWithUrl,
193  kServeDeprecationNotice,
194  kSplitHtml,
195  kSplitHtmlHelper,
196  kSpriteImages,
197  kStripImageColorProfile,
198  kStripImageMetaData,
199  kStripScripts,
200  kEndOfFilters
201  };
202 
203  enum EnabledEnum {
212  };
213 
220  static const char kAcceptInvalidSignatures[];
221  static const char kAccessControlAllowOrigins[];
222  static const char kAddOptionsToUrls[];
223  static const char kAllowLoggingUrlsInLogRecord[];
224  static const char kAllowOptionsToBeSetByCookies[];
225  static const char kAllowVaryOn[];
226  static const char kAlwaysMobilize[];
227  static const char kAlwaysRewriteCss[];
228  static const char kAmpLinkPattern[];
229  static const char kAnalyticsID[];
230  static const char kAvoidRenamingIntrospectiveJavascript[];
231  static const char kAwaitPcacheLookup[];
232  static const char kBeaconReinstrumentTimeSec[];
233  static const char kBeaconUrl[];
234  static const char kCacheFragment[];
235  static const char kCacheSmallImagesUnrewritten[];
236  static const char kClientDomainRewrite[];
237  static const char kCombineAcrossPaths[];
238  static const char kContentExperimentID[];
239  static const char kContentExperimentVariantID[];
240  static const char kCriticalImagesBeaconEnabled[];
241  static const char kCssFlattenMaxBytes[];
242  static const char kCssImageInlineMaxBytes[];
243  static const char kCssInlineMaxBytes[];
244  static const char kCssOutlineMinBytes[];
245  static const char kCssPreserveURLs[];
246  static const char kDefaultCacheHtml[];
247  static const char kDisableBackgroundFetchesForBots[];
248  static const char kDisableRewriteOnNoTransform[];
249  static const char kDistributeFetches[];
250  static const char kDistributedRewriteKey[];
251  static const char kDistributedRewriteServers[];
252  static const char kDistributedRewriteTimeoutMs[];
253  static const char kDomainRewriteCookies[];
254  static const char kDomainRewriteHyperlinks[];
255  static const char kDomainShardCount[];
256  static const char kDownstreamCachePurgeMethod[];
257  static const char kDownstreamCacheRebeaconingKey[];
258  static const char kDownstreamCacheRewrittenPercentageThreshold[];
259  static const char kEnableAggressiveRewritersForMobile[];
260  static const char kEnableCachePurge[];
261  static const char kEnableDeferJsExperimental[];
262  static const char kEnableExtendedInstrumentation[];
263  static const char kEnableFlushEarlyCriticalCss[];
264  static const char kEnableLazyLoadHighResImages[];
265  static const char kEnablePrioritizingScripts[];
266  static const char kEnabled[];
267  static const char kEnrollExperiment[];
268  static const char kExperimentCookieDurationMs[];
269  static const char kExperimentSlot[];
270  static const char kFetcherTimeOutMs[];
271  static const char kFinderPropertiesCacheExpirationTimeMs[];
272  static const char kFinderPropertiesCacheRefreshTimeMs[];
273  static const char kFlushBufferLimitBytes[];
274  static const char kFlushHtml[];
275  static const char kFlushMoreResourcesEarlyIfTimePermits[];
276  static const char kGoogleFontCssInlineMaxBytes[];
277  static const char kForbidAllDisabledFilters[];
278  static const char kHideRefererUsingMeta[];
279  static const char kHttpCacheCompressionLevel[];
280  static const char kIdleFlushTimeMs[];
281  static const char kImageInlineMaxBytes[];
284  static const char kImageJpegNumProgressiveScans[];
285  static const char kImageJpegNumProgressiveScansForSmallScreens[];
286  static const char kImageJpegQualityForSaveData[];
287  static const char kImageJpegRecompressionQuality[];
288  static const char kImageJpegRecompressionQualityForSmallScreens[];
289  static const char kImageLimitOptimizedPercent[];
290  static const char kImageLimitRenderedAreaPercent[];
291  static const char kImageLimitResizeAreaPercent[];
292  static const char kImageMaxRewritesAtOnce[];
293  static const char kImagePreserveURLs[];
294  static const char kImageRecompressionQuality[];
295  static const char kImageResolutionLimitBytes[];
296  static const char kImageWebpQualityForSaveData[];
297  static const char kImageWebpRecompressionQuality[];
298  static const char kImageWebpRecompressionQualityForSmallScreens[];
299  static const char kImageWebpAnimatedRecompressionQuality[];
300  static const char kImageWebpTimeoutMs[];
301  static const char kImplicitCacheTtlMs[];
302  static const char kIncreaseSpeedTracking[];
303  static const char kInlineOnlyCriticalImages[];
304  static const char kInPlacePreemptiveRewriteCss[];
305  static const char kInPlacePreemptiveRewriteCssImages[];
306  static const char kInPlacePreemptiveRewriteImages[];
307  static const char kInPlacePreemptiveRewriteJavascript[];
308  static const char kInPlaceResourceOptimization[];
309  static const char kInPlaceRewriteDeadlineMs[];
310  static const char kInPlaceSMaxAgeSec[];
311  static const char kInPlaceWaitForOptimized[];
312  static const char kJsInlineMaxBytes[];
313  static const char kJsOutlineMinBytes[];
314  static const char kJsPreserveURLs[];
315  static const char kLazyloadImagesAfterOnload[];
316  static const char kLazyloadImagesBlankUrl[];
317  static const char kLoadFromFileCacheTtlMs[];
318  static const char kLogBackgroundRewrite[];
319  static const char kLogMobilizationSamples[];
320  static const char kLogRewriteTiming[];
321  static const char kLogUrlIndices[];
322  static const char kLowercaseHtmlNames[];
323  static const char kMaxCacheableResponseContentLength[];
324  static const char kMaxCombinedCssBytes[];
325  static const char kMaxCombinedJsBytes[];
326  static const char kMaxHtmlCacheTimeMs[];
327  static const char kMaxHtmlParseBytes[];
328  static const char kMaxImageSizeLowResolutionBytes[];
329  static const char kMaxInlinedPreviewImagesIndex[];
330  static const char kMaxLowResImageSizeBytes[];
331  static const char kMaxLowResToHighResImageSizePercentage[];
332  static const char kMaxPrefetchJsElements[];
333  static const char kMaxRewriteInfoLogSize[];
334  static const char kMaxUrlSegmentSize[];
335  static const char kMaxUrlSize[];
336  static const char kMetadataCacheStalenessThresholdMs[];
337  static const char kMinCacheTtlMs[];
338  static const char kMinImageSizeLowResolutionBytes[];
339  static const char kMinResourceCacheTimeToRewriteMs[];
340  static const char kMobBeaconCategory[];
341  static const char kMobBeaconUrl[];
342  static const char kMobMapLocation[];
343  static const char kMobPhoneNumber[];
344  static const char kMobConversionId[];
345  static const char kMobMapConversionLabel[];
346  static const char kMobPhoneConversionLabel[];
347  static const char kMobIframe[];
348  static const char kMobIframeDisable[];
349  static const char kMobIframeViewport[];
350  static const char kMobNav[];
351  static const char kMobLabeledMode[];
352  static const char kMobNavClasses[];
353  static const char kMobStatic[];
354  static const char kMobTheme[];
355  static const char kModifyCachingHeaders[];
356  static const char kNoop[];
357  static const char kNoTransformOptimizedImages[];
358  static const char kNonCacheablesForCachePartialHtml[];
359  static const char kObliviousPagespeedUrls[];
360  static const char kOptionCookiesDurationMs[];
361  static const char kOverrideCachingTtlMs[];
362  static const char kPreserveSubresourceHints[];
363  static const char kPreserveUrlRelativity[];
364  static const char kPrivateNotVaryForIE[];
365  static const char kProactiveResourceFreshening[];
366  static const char kProactivelyFreshenUserFacingRequest[];
367  static const char kProgressiveJpegMinBytes[];
368  static const char kPubliclyCacheMismatchedHashesExperimental[];
369  static const char kRejectBlacklistedStatusCode[];
370  static const char kRejectBlacklisted[];
371  static const char kRemoteConfigurationTimeoutMs[];
372  static const char kRemoteConfigurationUrl[];
373  static const char kReportUnloadTime[];
374  static const char kRequestOptionOverride[];
375  static const char kRespectVary[];
376  static const char kRespectXForwardedProto[];
377  static const char kResponsiveImageDensities[];
378  static const char kRewriteDeadlineMs[];
379  static const char kRewriteLevel[];
380  static const char kRewriteRandomDropPercentage[];
381  static const char kRewriteUncacheableResources[];
382  static const char kRunningExperiment[];
383  static const char kServeStaleIfFetchError[];
384  static const char kServeStaleWhileRevalidateThresholdSec[];
385  static const char kServeXhrAccessControlHeaders[];
386  static const char kStickyQueryParameters[];
387  static const char kSupportNoScriptEnabled[];
388  static const char kTestOnlyPrioritizeCriticalCssDontApplyOriginalCss[];
389  static const char kUrlSigningKey[];
390  static const char kUseAnalyticsJs[];
391  static const char kUseBlankImageForInlinePreview[];
392  static const char kUseExperimentalJsMinifier[];
393  static const char kUseFallbackPropertyCacheValues[];
394  static const char kUseImageScanlineApi[];
395  static const char kXModPagespeedHeaderValue[];
396  static const char kXPsaBlockingRewrite[];
398  static const char kAllow[];
399  static const char kBlockingRewriteRefererUrls[];
400  static const char kDisableFilters[];
401  static const char kDisallow[];
402  static const char kDistributableFilters[];
403  static const char kDomain[];
404  static const char kDownstreamCachePurgeLocationPrefix[];
405  static const char kEnableFilters[];
406  static const char kExperimentVariable[];
407  static const char kExperimentSpec[];
408  static const char kForbidFilters[];
409  static const char kInlineResourcesWithoutExplicitAuthorization[];
410  static const char kRetainComment[];
412  static const char kAddResourceHeader[];
413  static const char kCustomFetchHeader[];
414  static const char kLoadFromFile[];
415  static const char kLoadFromFileMatch[];
416  static const char kLoadFromFileRule[];
417  static const char kLoadFromFileRuleMatch[];
418  static const char kMapOriginDomain[];
419  static const char kMapProxyDomain[];
420  static const char kMapRewriteDomain[];
421  static const char kShardDomain[];
423  static const char kLibrary[];
424  static const char kUrlValuedAttribute[];
427  static const char kCacheFlushFilename[];
428  static const char kCacheFlushPollIntervalSec[];
429  static const char kCompressMetadataCache[];
430  static const char kFetcherProxy[];
431  static const char kFetchFromModSpdy[];
432  static const char kFetchHttps[];
433  static const char kFileCacheCleanInodeLimit[];
434  static const char kFileCacheCleanIntervalMs[];
435  static const char kFileCacheCleanSizeKb[];
436  static const char kFileCachePath[];
437  static const char kLogDir[];
438  static const char kLruCacheByteLimit[];
439  static const char kLruCacheKbPerProcess[];
440  static const char kMemcachedServers[];
441  static const char kMemcachedThreads[];
442  static const char kMemcachedTimeoutUs[];
443  static const char kProxySuffix[];
444  static const char kRateLimitBackgroundFetches[];
445  static const char kServeWebpToAnyAgent[];
446  static const char kSlurpDirectory[];
447  static const char kSlurpFlushLimit[];
448  static const char kSlurpReadOnly[];
449  static const char kSslCertDirectory[];
450  static const char kSslCertFile[];
451  static const char kStatisticsEnabled[];
452  static const char kStatisticsLoggingChartsCSS[];
453  static const char kStatisticsLoggingChartsJS[];
454  static const char kStatisticsLoggingEnabled[];
455  static const char kStatisticsLoggingIntervalMs[];
456  static const char kStatisticsLoggingMaxFileSizeKb[];
457  static const char kTestProxy[];
458  static const char kTestProxySlurp[];
459  static const char kUseSharedMemLocking[];
461  static const char kNullOption[];
462 
470  struct BeaconUrl {
471  GoogleString http;
472  GoogleString https;
473  GoogleString http_in;
474  GoogleString https_in;
475  };
476 
477  struct Color {
478  unsigned char r;
479  unsigned char g;
480  unsigned char b;
481  };
482 
483  struct MobTheme {
484  Color background_color;
485  Color foreground_color;
486  GoogleString logo_url;
487  };
488 
489  struct NameValue {
490  NameValue(StringPiece name_in, StringPiece value_in) {
491  name_in.CopyToString(&name);
492  value_in.CopyToString(&value);
493  }
494  GoogleString name;
495  GoogleString value;
496  };
497 
500  class ResponsiveDensities : public std::vector<double> {
501  };
502 
503  class AllowVaryOn {
504  public:
506  static const char kNoneString[];
507  static const char kAutoString[];
508 
509  AllowVaryOn() :
510  allow_auto_(false),
511  allow_accept_(false),
512  allow_save_data_(false),
513  allow_user_agent_(false) {
514  }
515 
516  GoogleString ToString() const;
517 
518  bool allow_auto() const {
519  return allow_auto_;
520  }
521  void set_allow_auto(bool v) {
522  allow_auto_ = v;
523  }
524  bool allow_accept() const {
525  return allow_accept_;
526  }
527  void set_allow_accept(bool v) {
528  allow_accept_ = v;
529  }
530  bool allow_save_data() const {
531  return allow_save_data_ || allow_auto_;
532  }
533  void set_allow_save_data(bool v) {
534  allow_save_data_ = v;
535  }
536  bool allow_user_agent() const {
537  return allow_user_agent_;
538  }
539  void set_allow_user_agent(bool v) {
540  allow_user_agent_ = v;
541  }
542 
543  private:
546  bool allow_auto_;
547  bool allow_accept_;
548  bool allow_save_data_;
549  bool allow_user_agent_;
550  };
551 
552  bool AllowVaryOnAuto() const {
553  return allow_vary_on_.value().allow_auto();
554  }
555  bool AllowVaryOnAccept() const {
556  return allow_vary_on_.value().allow_accept();
557  }
558  bool AllowVaryOnSaveData() const {
559  return allow_vary_on_.value().allow_save_data();
560  }
561  bool AllowVaryOnUserAgent() const {
562  return allow_vary_on_.value().allow_user_agent();
563  }
564  GoogleString AllowVaryOnToString() const {
565  return ToString(allow_vary_on_.value());
566  }
567 
571  bool SupportSaveData() const {
572  return (HasValidSaveDataQualities() && AllowVaryOnSaveData());
573  }
574 
575  void set_allow_vary_on(const AllowVaryOn& x) {
576  set_option(x, &allow_vary_on_);
577  }
578 
580  int64 ImageJpegQuality() const;
581  int64 ImageJpegQualityForSmallScreen() const;
582  int64 ImageJpegQualityForSaveData() const;
583  int64 ImageWebpQuality() const;
584  int64 ImageWebpQualityForSmallScreen() const;
585  int64 ImageWebpQualityForSaveData() const;
586  int64 ImageWebpAnimatedQuality() const;
587  int64 ImageJpegNumProgressiveScansForSmallScreen() const;
590  bool HasValidSmallScreenQualities() const;
593  bool HasValidSaveDataQualities() const;
594 
611  static const int kOptionsVersion = 14;
612 
614  static const int kHashBytes = 20;
615 
617  static const int kCachePurgeBytes = 25000;
618 
625  enum OptionScope {
632  };
633 
634  static const char kCacheExtenderId[];
635  static const char kCollectFlushEarlyContentFilterId[];
636  static const char kCssCombinerId[];
637  static const char kCssFilterId[];
638  static const char kCssImportFlattenerId[];
639  static const char kCssInlineId[];
640  static const char kGoogleFontCssInlineId[];
641  static const char kImageCombineId[];
642  static const char kImageCompressionId[];
643  static const char kInPlaceRewriteId[];
644  static const char kJavascriptCombinerId[];
645  static const char kJavascriptInlineId[];
646  static const char kJavascriptMinId[];
647  static const char kJavascriptMinSourceMapId[];
648  static const char kLocalStorageCacheId[];
649  static const char kPrioritizeCriticalCssId[];
650 
653  static const char* FilterName(Filter filter);
654 
657  static const char* FilterId(Filter filter);
658 
661  static int NumFilterIds();
662 
665 
666  typedef EnumSet<Filter, kEndOfFilters> FilterSet;
667  typedef std::vector<Filter> FilterVector;
668 
670  typedef std::set<GoogleString> FilterIdSet;
671 
677  static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set,
678  MessageHandler* handler);
679 
682  typedef std::pair<GoogleString, GoogleString> OptionStringPair;
683  typedef std::set<OptionStringPair> OptionSet;
684 
685  typedef std::vector<PropertyBase*> PropertyVector;
686 
689  class OptionBase {
690  public:
691  OptionBase() {}
692  virtual ~OptionBase();
693 
697  virtual bool SetFromString(StringPiece value_string,
698  GoogleString* error_detail) = 0;
699  virtual void Merge(const OptionBase* src) = 0;
700  virtual bool was_set() const = 0;
701  virtual GoogleString Signature(const Hasher* hasher) const = 0;
702  virtual GoogleString ToString() const = 0;
703  const char* id() const { return property()->id(); }
704  const char* help_text() const { return property()->help_text(); }
705  OptionScope scope() const { return property()->scope(); }
706  StringPiece option_name() const { return property()->option_name(); }
707  bool is_used_for_signature_computation() const {
708  return property()->is_used_for_signature_computation();
709  }
710  virtual const PropertyBase* property() const = 0;
711  };
712 
714  typedef std::vector<OptionBase*> OptionBaseVector;
715 
724 
729 
736 
740 
745 
749  };
750 
753  kOptionOk,
754  kOptionNameUnknown,
755  kOptionValueInvalid
756  };
757 
758  static const char kDefaultAllowVaryOn[];
759  static const int kDefaultBeaconReinstrumentTimeSec;
760  static const int64 kDefaultCssFlattenMaxBytes;
761  static const int64 kDefaultCssImageInlineMaxBytes;
762  static const int64 kDefaultCssInlineMaxBytes;
763  static const int64 kDefaultCssOutlineMinBytes;
764  static const int64 kDefaultGoogleFontCssInlineMaxBytes;
765  static const int64 kDefaultImageInlineMaxBytes;
766  static const int64 kDefaultJsInlineMaxBytes;
767  static const int64 kDefaultJsOutlineMinBytes;
768  static const int64 kDefaultProgressiveJpegMinBytes;
769  static const int64 kDefaultMaxCacheableResponseContentLength;
770  static const int64 kDefaultMaxHtmlCacheTimeMs;
771  static const int64 kDefaultMaxHtmlParseBytes;
772  static const int64 kDefaultMaxLowResImageSizeBytes;
773  static const int kDefaultMaxLowResToFullResImageSizePercentage;
774  static const int64 kDefaultMetadataInputErrorsCacheTtlMs;
775  static const int64 kDefaultMinResourceCacheTimeToRewriteMs;
776  static const char kDefaultDownstreamCachePurgeMethod[];
777  static const int64 kDefaultDownstreamCacheRewrittenPercentageThreshold;
778  static const int64 kDefaultIdleFlushTimeMs;
779  static const int64 kDefaultFlushBufferLimitBytes;
780  static const int64 kDefaultImplicitCacheTtlMs;
781  static const int64 kDefaultMinCacheTtlMs;
782  static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs;
783  static const char kDefaultBeaconUrl[];
784  static const int64 kDefaultImageRecompressQuality;
785  static const int64 kDefaultImageJpegQualityForSaveData;
786  static const int64 kDefaultImageJpegRecompressQuality;
787  static const int64 kDefaultImageJpegRecompressQualityForSmallScreens;
788  static const int kDefaultImageLimitOptimizedPercent;
789  static const int kDefaultImageLimitRenderedAreaPercent;
790  static const int kDefaultImageLimitResizeAreaPercent;
791  static const int64 kDefaultImageResolutionLimitBytes;
792  static const int64 kDefaultImageJpegNumProgressiveScans;
793  static const int64 kDefaultImageWebpQualityForSaveData;
794  static const int64 kDefaultImageWebpRecompressQuality;
795  static const int64 kDefaultImageWebpAnimatedRecompressQuality;
796  static const int64 kDefaultImageWebpRecompressQualityForSmallScreens;
797  static const int64 kDefaultImageWebpTimeoutMs;
798  static const int kDefaultDomainShardCount;
799  static const int kDefaultMaxPrefetchJsElements;
800  static const int64 kDefaultOptionCookiesDurationMs;
801  static const int64 kDefaultLoadFromFileCacheTtlMs;
802  static const double kDefaultResponsiveImageDensities[];
803 
806  static const int kDefaultMaxUrlSize;
807 
808  static const int kDefaultImageMaxRewritesAtOnce;
809 
814  static const int kDefaultMaxUrlSegmentSize;
815 
817  static const int kDefaultRewriteDeadlineMs;
818 
820  static const int64 kDefaultDistributedTimeoutMs;
821 
835 
839 
843 
845  static const int64 kDefaultMaxCombinedCssBytes;
846 
848  static const int64 kDefaultMaxCombinedJsBytes;
849 
850  static const int kDefaultExperimentTrafficPercent;
852  static const int kDefaultExperimentSlot;
853 
854  static const char kDefaultBlockingRewriteKey[];
855 
856  static const char kRejectedRequestUrlKeyName[];
857 
858  static const int kDefaultPropertyCacheHttpStatusStabilityThreshold;
859 
860  static const int kDefaultMaxRewriteInfoLogSize;
861 
869  public:
874  ExperimentSpec(const StringPiece& spec, const RewriteOptions* options,
875  MessageHandler* handler);
876 
880  explicit ExperimentSpec(int id);
881 
882  virtual ~ExperimentSpec();
883 
885  virtual ExperimentSpec* Clone();
886 
887  bool is_valid() const { return id_ >= 0; }
888 
890  int id() const { return id_; }
891  int percent() const { return percent_; }
892  const GoogleString& ga_id() const { return ga_id_; }
893  int slot() const { return ga_variable_slot_; }
894  RewriteLevel rewrite_level() const { return rewrite_level_; }
895  FilterSet enabled_filters() const { return enabled_filters_; }
896  FilterSet disabled_filters() const { return disabled_filters_; }
897  OptionSet filter_options() const { return filter_options_; }
898  bool matches_device_type(UserAgentMatcher::DeviceType type) const;
899  bool use_default() const { return use_default_; }
900  GoogleString ToString() const;
901 
904  MessageHandler* handler) const;
905 
906  protected:
911  void Merge(const ExperimentSpec& spec);
912 
913  typedef std::bitset<net_instaweb::UserAgentMatcher::kEndOfDeviceType>
914  DeviceTypeBitSet;
915 
916  static bool ParseDeviceTypeBitSet(const StringPiece& in,
917  DeviceTypeBitSet* out,
918  MessageHandler* handler);
919 
921  StringVector serving_domains;
922  GoogleString origin_domain;
923  GoogleString host_header;
924  };
925 
928  static bool LooksLikeValidHost(const StringPiece& s);
929 
933  static bool ParseAlternateOriginDomain(const StringPiece& in,
935  MessageHandler* handler);
936 
944  static void CombineQuotedHostPort(StringPieceVector* vec, size_t first_pos,
945  GoogleString* combined_container);
946 
950  static GoogleString QuoteHostPort(const GoogleString& in);
951 
952  private:
953  FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
954  FRIEND_TEST(RewriteOptionsTest, DeviceTypeMergeTest);
955  FRIEND_TEST(RewriteOptionsTest, AlternateOriginDomainMergeTest);
956 
959  void Initialize(const StringPiece& spec, MessageHandler* handler);
960 
965  int id_;
966  GoogleString ga_id_;
967  int ga_variable_slot_;
968  int percent_;
969  RewriteLevel rewrite_level_;
970  FilterSet enabled_filters_;
971  FilterSet disabled_filters_;
972  OptionSet filter_options_;
976  scoped_ptr<DeviceTypeBitSet> matches_device_types_;
979  bool use_default_;
982  typedef std::vector<AlternateOriginDomainSpec> AlternateOriginDomains;
983  AlternateOriginDomains alternate_origin_domains_;
984 
985 
986  };
987 
990  GoogleString element;
991  GoogleString attribute;
992  semantic_type::Category category;
993  };
994 
1001  class Properties {
1002  public:
1011  static bool Initialize(Properties** properties);
1012 
1021  static bool Terminate(Properties** properties_handle);
1022 
1024  int size() const { return property_vector_.size(); }
1025 
1026  const PropertyBase* property(int index) const {
1027  return property_vector_[index];
1028  }
1029  PropertyBase* property(int index) { return property_vector_[index]; }
1030 
1036  void Merge(Properties* properties);
1037 
1038  void push_back(PropertyBase* p) { property_vector_.push_back(p); }
1039 
1040  private:
1043  Properties();
1044  ~Properties();
1045 
1049  int initialization_count_;
1050 
1055  bool owns_properties_;
1056  PropertyVector property_vector_;
1057  };
1058 
1061  RewriteOptions::Filter filter_enum;
1062  const char* filter_id;
1063  const char* filter_name;
1064  };
1065 
1066  static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out);
1067 
1068  typedef std::set<semantic_type::Category> ResourceCategorySet;
1069 
1070  static bool ParseInlineUnauthorizedResourceType(
1071  const StringPiece& in,
1072  ResourceCategorySet* resource_types);
1073 
1077  static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out);
1078 
1082  bool ImageOptimizationEnabled() const;
1083 
1084  explicit RewriteOptions(ThreadSystem* thread_system);
1085  virtual ~RewriteOptions();
1086 
1090  static bool Initialize();
1091  static bool Terminate();
1092 
1093 #ifndef NDEBUG
1094  bool ModificationOK() const;
1101 
1108  bool MergeOK() const;
1109 #endif
1110 
1115  void InitializeOptions(const Properties* properties);
1116 
1117  bool modified() const { return modified_; }
1118 
1126  level_.set_default(level);
1127  }
1128  void SetRewriteLevel(RewriteLevel level) {
1129  set_option(level, &level_);
1130  }
1131 
1135  bool ValidateConfiguredHttpHeader(const GoogleString& name,
1136  const GoogleString& value,
1137  GoogleString* error_message);
1138 
1144  bool ValidateAndAddResourceHeader(const StringPiece& name,
1145  const StringPiece& value,
1146  GoogleString* error_message);
1147 
1150  void AddResourceHeader(const StringPiece& name, const StringPiece& value);
1151 
1152  const NameValue* resource_header(int i) const {
1153  return resource_headers_[i];
1154  }
1155 
1156  int num_resource_headers() const {
1157  return resource_headers_.size();
1158  }
1159 
1161  void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value);
1162 
1163  const NameValue* custom_fetch_header(int i) const {
1164  return custom_fetch_headers_[i];
1165  }
1166 
1167  int num_custom_fetch_headers() const {
1168  return custom_fetch_headers_.size();
1169  }
1170 
1173  ExperimentSpec* GetExperimentSpec(int id) const;
1174 
1178  bool AvailableExperimentId(int id);
1179 
1182  virtual ExperimentSpec* AddExperimentSpec(const StringPiece& spec,
1183  MessageHandler* handler);
1184 
1192  virtual bool SetExperimentState(int id);
1193 
1197  void SetExperimentStateStr(const StringPiece& experiment_index);
1198 
1199  int experiment_id() const { return experiment_id_; }
1200 
1201  int experiment_spec_id(int i) const {
1202  return experiment_specs_[i]->id();
1203  }
1204 
1209  GoogleString GetExperimentStateStr() const;
1210 
1211  ExperimentSpec* experiment_spec(int i) const {
1212  return experiment_specs_[i];
1213  }
1214 
1215  int num_experiments() const { return experiment_specs_.size(); }
1216 
1217  bool enroll_experiment() const {
1218  return enroll_experiment_id() != experiment::kForceNoExperiment;
1219  }
1220 
1232  void AddUrlValuedAttribute(const StringPiece& element,
1233  const StringPiece& attribute,
1234  semantic_type::Category category);
1235 
1238  void UrlValuedAttribute(int index,
1239  StringPiece* element,
1240  StringPiece* attribute,
1241  semantic_type::Category* category) const;
1242 
1243  int num_url_valued_attributes() const {
1244  if (url_valued_attributes_ == NULL) {
1245  return 0;
1246  } else {
1247  return url_valued_attributes_->size();
1248  }
1249  }
1250 
1251  void AddInlineUnauthorizedResourceType(semantic_type::Category category);
1252  bool HasInlineUnauthorizedResourceType(
1253  semantic_type::Category category) const;
1254  void ClearInlineUnauthorizedResourceTypes();
1255  void set_inline_unauthorized_resource_types(ResourceCategorySet x);
1256 
1259  uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) {
1260  return WriteableJavascriptLibraryIdentification()->RegisterLibrary(
1261  bytes, md5_hash, canonical_url);
1262  }
1263 
1267  const {
1268  if (Enabled(kCanonicalizeJavascriptLibraries)) {
1269  return javascript_library_identification_.get();
1270  } else {
1271  return NULL;
1272  }
1273  }
1274 
1275  RewriteLevel level() const { return level_.value(); }
1276 
1281  bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters,
1282  MessageHandler* handler);
1283 
1287  bool EnableFiltersByCommaSeparatedList(const StringPiece& filters,
1288  MessageHandler* handler);
1289 
1293  bool DisableFiltersByCommaSeparatedList(const StringPiece& filters,
1294  MessageHandler* handler);
1295 
1299  bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters,
1300  MessageHandler* handler);
1301 
1303  void DisableAllFilters();
1304 
1313 
1316  void DistributeFiltersByCommaSeparatedList(const StringPiece& filter_ids,
1317  MessageHandler* handler);
1320  void DistributeFilter(const StringPiece& filter_id);
1321 
1324  bool Distributable(const StringPiece& filter_id) const;
1325 
1329  void EnableFilter(Filter filter);
1332  void ForceEnableFilter(Filter filter);
1333  void DisableFilter(Filter filter);
1334  void DisableIfNotExplictlyEnabled(Filter filter);
1335  void ForbidFilter(Filter filter);
1336  void EnableFilters(const FilterSet& filter_set);
1337  void DisableFilters(const FilterSet& filter_set);
1338  void ForbidFilters(const FilterSet& filter_set);
1341  void ClearFilters();
1342 
1360  void SoftEnableFilterForTesting(Filter filter);
1361 
1364  void EnableExtendCacheFilters();
1365 
1366  bool Enabled(Filter filter) const;
1367  bool Forbidden(Filter filter) const;
1368  bool Forbidden(StringPiece filter_id) const;
1369 
1371  void GetEnabledFiltersRequiringScriptExecution(FilterVector* filters) const;
1372 
1375 
1378  bool UsePerOriginPropertyCachePage() const;
1379 
1385  const StringPiece& options, OptionSet* set, MessageHandler* handler);
1386 
1392  StringPiece name, StringPiece value, GoogleString* msg);
1393 
1396  StringPiece name, StringPiece value);
1397 
1401  OptionSettingResult SetOptionFromQuery(StringPiece name, StringPiece value);
1402 
1407  StringPiece value);
1408 
1409  GoogleString ScopeEnumToString(OptionScope scope);
1410 
1419  StringPiece name, StringPiece arg,
1420  GoogleString* msg, MessageHandler* handler);
1426  StringPiece name, StringPiece arg, OptionScope max_scope,
1427  GoogleString* msg, MessageHandler* handler);
1428 
1429  virtual OptionSettingResult ParseAndSetOptionFromName2(
1430  StringPiece name, StringPiece arg1, StringPiece arg2,
1431  GoogleString* msg, MessageHandler* handler);
1432 
1433  virtual OptionSettingResult ParseAndSetOptionFromName3(
1434  StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3,
1435  GoogleString* msg, MessageHandler* handler);
1436 
1442  bool OptionValue(StringPiece option_name, const char** id,
1443  bool* was_set, GoogleString* value) const;
1444 
1447  bool SetOptionsFromName(const OptionSet& option_set, MessageHandler* handler);
1448 
1451  bool SetOptionFromNameAndLog(StringPiece name,
1452  StringPiece value,
1453  MessageHandler* handler);
1454 
1457  static bool ParseFromString(StringPiece value_string, bool* value);
1458  static bool ParseFromString(StringPiece value_string, EnabledEnum* value);
1459  static bool ParseFromString(StringPiece value_string, int* value) {
1460  return StringToInt(value_string, value);
1461  }
1462  static bool ParseFromString(StringPiece value_string, int64* value) {
1463  return StringToInt64(value_string, value);
1464  }
1465  static bool ParseFromString(StringPiece value_string, double* value) {
1466  return StringToDouble(value_string, value);
1467  }
1468  static bool ParseFromString(StringPiece value_string, GoogleString* value) {
1469  value_string.CopyToString(value);
1470  return true;
1471  }
1472  static bool ParseFromString(StringPiece value_string, RewriteLevel* value) {
1473  return ParseRewriteLevel(value_string, value);
1474  }
1475  static bool ParseFromString(StringPiece value_string,
1476  ResourceCategorySet* value) {
1477  return ParseInlineUnauthorizedResourceType(value_string, value);
1478  }
1479  static bool ParseFromString(StringPiece value_string, BeaconUrl* value) {
1480  return ParseBeaconUrl(value_string, value);
1481  }
1482  static bool ParseFromString(StringPiece value_string, Color* color);
1483  static bool ParseFromString(StringPiece value_string, MobTheme* theme);
1484  static bool ParseFromString(StringPiece value_string,
1485  ResponsiveDensities* value);
1486  static bool ParseFromString(StringPiece value_string,
1487  protobuf::MessageLite* proto);
1488  static bool ParseFromString(StringPiece value_string,
1489  AllowVaryOn* allow_vary_on);
1490 
1493  int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); }
1494  void set_css_outline_min_bytes(int64 x) {
1495  set_option(x, &css_outline_min_bytes_);
1496  }
1497 
1498  const GoogleString& ga_id() const { return ga_id_.value(); }
1499  void set_ga_id(const GoogleString& id) {
1500  set_option(id, &ga_id_);
1501  }
1502 
1503  void set_content_experiment_id(const GoogleString& s) {
1504  set_option(s, &content_experiment_id_);
1505  }
1506  const GoogleString& content_experiment_id() const {
1507  return content_experiment_id_.value();
1508  }
1509 
1510  void set_content_experiment_variant_id(const GoogleString& s) {
1511  set_option(s, &content_experiment_variant_id_);
1512  }
1513  const GoogleString& content_experiment_variant_id() const {
1514  return content_experiment_variant_id_.value();
1515  }
1516 
1517  bool is_content_experiment() const {
1518  return !content_experiment_id().empty() &&
1519  !content_experiment_variant_id().empty();
1520  }
1521 
1522  bool use_analytics_js() const {
1523  return use_analytics_js_.value();
1524  }
1525  void set_use_analytics_js(bool x) {
1526  set_option(x, &use_analytics_js_);
1527  }
1528 
1529  bool increase_speed_tracking() const {
1530  return increase_speed_tracking_.value();
1531  }
1532  void set_increase_speed_tracking(bool x) {
1533  set_option(x, &increase_speed_tracking_);
1534  }
1535 
1536  int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); }
1537  void set_js_outline_min_bytes(int64 x) {
1538  set_option(x, &js_outline_min_bytes_);
1539  }
1540 
1541  int64 progressive_jpeg_min_bytes() const {
1542  return progressive_jpeg_min_bytes_.value();
1543  }
1544  void set_progressive_jpeg_min_bytes(int64 x) {
1545  set_option(x, &progressive_jpeg_min_bytes_);
1546  }
1547 
1548  int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); }
1549  void set_css_flatten_max_bytes(int64 x) {
1550  set_option(x, &css_flatten_max_bytes_);
1551  }
1552  bool cache_small_images_unrewritten() const {
1553  return cache_small_images_unrewritten_.value();
1554  }
1555  void set_cache_small_images_unrewritten(bool x) {
1556  set_option(x, &cache_small_images_unrewritten_);
1557  }
1558  int64 image_resolution_limit_bytes() const {
1559  return image_resolution_limit_bytes_.value();
1560  }
1561  void set_image_resolution_limit_bytes(int64 x) {
1562  set_option(x, &image_resolution_limit_bytes_);
1563  }
1564 
1566  int64 ImageInlineMaxBytes() const;
1567  void set_image_inline_max_bytes(int64 x);
1569  int64 CssImageInlineMaxBytes() const;
1570  void set_css_image_inline_max_bytes(int64 x) {
1571  set_option(x, &css_image_inline_max_bytes_);
1572  }
1574  int64 MaxImageInlineMaxBytes() const;
1575  int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); }
1576  void set_css_inline_max_bytes(int64 x) {
1577  set_option(x, &css_inline_max_bytes_);
1578  }
1579  int64 google_font_css_inline_max_bytes() const {
1580  return google_font_css_inline_max_bytes_.value();
1581  }
1582  void set_google_font_css_inline_max_bytes(int64 x) {
1583  set_option(x, &google_font_css_inline_max_bytes_);
1584  }
1585  int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); }
1586  void set_js_inline_max_bytes(int64 x) {
1587  set_option(x, &js_inline_max_bytes_);
1588  }
1589  int64 max_html_cache_time_ms() const {
1590  return max_html_cache_time_ms_.value();
1591  }
1592  void set_max_html_cache_time_ms(int64 x) {
1593  set_option(x, &max_html_cache_time_ms_);
1594  }
1595  int64 max_html_parse_bytes() const {
1596  return max_html_parse_bytes_.value();
1597  }
1598  void set_max_html_parse_bytes(int64 x) {
1599  set_option(x, &max_html_parse_bytes_);
1600  }
1601  int64 max_cacheable_response_content_length() const {
1602  return max_cacheable_response_content_length_.value();
1603  }
1604  void set_max_cacheable_response_content_length(int64 x) {
1605  set_option(x, &max_cacheable_response_content_length_);
1606  }
1607  int64 min_resource_cache_time_to_rewrite_ms() const {
1608  return min_resource_cache_time_to_rewrite_ms_.value();
1609  }
1610  void set_min_resource_cache_time_to_rewrite_ms(int64 x) {
1611  set_option(x, &min_resource_cache_time_to_rewrite_ms_);
1612  }
1613  bool need_to_store_experiment_data() const {
1614  return need_to_store_experiment_data_;
1615  }
1616  void set_need_to_store_experiment_data(bool x) {
1617  need_to_store_experiment_data_ = x;
1618  }
1619 
1620  int64 blocking_fetch_timeout_ms() const {
1621  return blocking_fetch_timeout_ms_.value();
1622  }
1623  void set_blocking_fetch_timeout_ms(int64 x) {
1624  set_option(x, &blocking_fetch_timeout_ms_);
1625  }
1626  bool override_ie_document_mode() const {
1627  return override_ie_document_mode_.value();
1628  }
1629  void set_override_ie_document_mode(bool x) {
1630  set_option(x, &override_ie_document_mode_);
1631  }
1632 
1633  bool preserve_subresource_hints() const {
1634  return preserve_subresource_hints_.value();
1635  }
1636  void set_preserve_subresource_hints(bool x) {
1637  set_option(x, &preserve_subresource_hints_);
1638  }
1639 
1640 
1641  bool preserve_url_relativity() const {
1642  return preserve_url_relativity_.value();
1643  }
1644  void set_preserve_url_relativity(bool x) {
1645  set_option(x, &preserve_url_relativity_);
1646  }
1647 
1664  bool IsUrlCacheValid(StringPiece url, int64 time_ms,
1665  bool search_wildcards) const;
1666 
1683  void AddUrlCacheInvalidationEntry(StringPiece url_pattern,
1684  int64 timestamp_ms,
1685  bool ignores_metadata_and_pcache);
1686 
1688  void PurgeUrl(StringPiece url, int64 timestamp_ms);
1689 
1693 
1696  void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock* lock) {
1697  cache_purge_mutex_.reset(lock);
1698  }
1699 
1704  int64 cache_invalidation_timestamp() const;
1705 
1710 
1719  bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms)
1720  LOCKS_EXCLUDED(cache_purge_mutex_.get());
1721 
1725  bool UpdateCachePurgeSet(const CopyOnWrite<PurgeSet>& purge_set)
1726  LOCKS_EXCLUDED(cache_purge_mutex_.get());
1727 
1730  GoogleString PurgeSetString() const;
1731 
1734  int64 idle_flush_time_ms() const {
1735  return idle_flush_time_ms_.value();
1736  }
1737  void set_idle_flush_time_ms(int64 x) {
1738  set_option(x, &idle_flush_time_ms_);
1739  }
1740 
1743  return flush_buffer_limit_bytes_.value();
1744  }
1745 
1746  void set_flush_buffer_limit_bytes(int64 x) {
1747  set_option(x, &flush_buffer_limit_bytes_);
1748  }
1749 
1752  int max_url_segment_size() const { return max_url_segment_size_.value(); }
1753  void set_max_url_segment_size(int x) {
1754  set_option(x, &max_url_segment_size_);
1755  }
1756 
1757  int image_max_rewrites_at_once() const {
1758  return image_max_rewrites_at_once_.value();
1759  }
1760  void set_image_max_rewrites_at_once(int x) {
1761  set_option(x, &image_max_rewrites_at_once_);
1762  }
1763 
1765  int max_url_size() const { return max_url_size_.value(); }
1766  void set_max_url_size(int x) {
1767  set_option(x, &max_url_size_);
1768  }
1769 
1770  int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); }
1771  void set_rewrite_deadline_ms(int x) {
1772  set_option(x, &rewrite_deadline_ms_);
1773  }
1774 
1775  bool test_instant_fetch_rewrite_deadline() const {
1776  return test_instant_fetch_rewrite_deadline_.value();
1777  }
1778  void set_test_instant_fetch_rewrite_deadline(bool x) {
1779  set_option(x, &test_instant_fetch_rewrite_deadline_);
1780  }
1781 
1782  void set_test_only_prioritize_critical_css_dont_apply_original_css(bool x) {
1783  set_option(x, &test_only_prioritize_critical_css_dont_apply_original_css_);
1784  }
1785  bool test_only_prioritize_critical_css_dont_apply_original_css() const {
1786  return test_only_prioritize_critical_css_dont_apply_original_css_.value();
1787  }
1788 
1789  int domain_shard_count() const { return domain_shard_count_.value(); }
1792  void set_domain_shard_count(int64 x) {
1793  int value = x;
1794  set_option(value, &domain_shard_count_);
1795  }
1796 
1797  void set_enabled(EnabledEnum x) {
1798  set_option(x, &enabled_);
1799  }
1800  bool enabled() const {
1801  return enabled_.value() == kEnabledOn;
1802  }
1803  bool unplugged() const {
1804  return enabled_.value() == kEnabledUnplugged;
1805  }
1806 
1807  void set_add_options_to_urls(bool x) {
1808  set_option(x, &add_options_to_urls_);
1809  }
1810 
1811  bool add_options_to_urls() const {
1812  return add_options_to_urls_.value();
1813  }
1814 
1815  void set_publicly_cache_mismatched_hashes_experimental(bool x) {
1816  set_option(x, &publicly_cache_mismatched_hashes_experimental_);
1817  }
1818 
1819  bool publicly_cache_mismatched_hashes_experimental() const {
1820  return publicly_cache_mismatched_hashes_experimental_.value();
1821  }
1822 
1823  void set_oblivious_pagespeed_urls(bool x) {
1824  set_option(x, &oblivious_pagespeed_urls_);
1825  }
1826 
1827  bool oblivious_pagespeed_urls() const {
1828  return oblivious_pagespeed_urls_.value();
1829  }
1830 
1831  void set_in_place_rewriting_enabled(bool x) {
1832  set_option(x, &in_place_rewriting_enabled_);
1833  }
1834 
1835  bool in_place_rewriting_enabled() const {
1836  return CheckBandwidthOption(in_place_rewriting_enabled_);
1837  }
1838 
1839  void set_in_place_wait_for_optimized(bool x) {
1840  set_option(x, &in_place_wait_for_optimized_);
1841  }
1842 
1843  bool in_place_wait_for_optimized() const {
1844  return (in_place_wait_for_optimized_.value() ||
1845  (in_place_rewrite_deadline_ms() < 0));
1846  }
1847 
1848  void set_in_place_rewrite_deadline_ms(int x) {
1849  set_option(x, &in_place_rewrite_deadline_ms_);
1850  }
1851 
1852  int in_place_rewrite_deadline_ms() const {
1853  return in_place_rewrite_deadline_ms_.value();
1854  }
1855 
1856  void set_in_place_s_maxage_sec(int x) {
1857  set_option(x, &in_place_s_maxage_sec_);
1858  }
1859 
1860  int in_place_s_maxage_sec() const {
1861  return in_place_s_maxage_sec_.value();
1862  }
1863 
1864  int EffectiveInPlaceSMaxAgeSec() const {
1865  return modify_caching_headers() ? in_place_s_maxage_sec() : -1;
1866  }
1867 
1868  void set_in_place_preemptive_rewrite_css(bool x) {
1869  set_option(x, &in_place_preemptive_rewrite_css_);
1870  }
1871  bool in_place_preemptive_rewrite_css() const {
1872  return CheckBandwidthOption(in_place_preemptive_rewrite_css_);
1873  }
1874 
1875  void set_in_place_preemptive_rewrite_css_images(bool x) {
1876  set_option(x, &in_place_preemptive_rewrite_css_images_);
1877  }
1878  bool in_place_preemptive_rewrite_css_images() const {
1879  return CheckBandwidthOption(in_place_preemptive_rewrite_css_images_);
1880  }
1881 
1882  void set_in_place_preemptive_rewrite_images(bool x) {
1883  set_option(x, &in_place_preemptive_rewrite_images_);
1884  }
1885  bool in_place_preemptive_rewrite_images() const {
1886  return CheckBandwidthOption(in_place_preemptive_rewrite_images_);
1887  }
1888 
1889  void set_in_place_preemptive_rewrite_javascript(bool x) {
1890  set_option(x, &in_place_preemptive_rewrite_javascript_);
1891  }
1892  bool in_place_preemptive_rewrite_javascript() const {
1893  return CheckBandwidthOption(in_place_preemptive_rewrite_javascript_);
1894  }
1895 
1896  void set_private_not_vary_for_ie(bool x) {
1897  set_option(x, &private_not_vary_for_ie_);
1898  }
1899  bool private_not_vary_for_ie() const {
1900  return private_not_vary_for_ie_.value();
1901  }
1902 
1903  void set_combine_across_paths(bool x) {
1904  set_option(x, &combine_across_paths_);
1905  }
1906  bool combine_across_paths() const { return combine_across_paths_.value(); }
1907 
1908  void set_log_background_rewrites(bool x) {
1909  set_option(x, &log_background_rewrites_);
1910  }
1911  bool log_background_rewrites() const {
1912  return log_background_rewrites_.value();
1913  }
1914 
1915  void set_log_mobilization_samples(bool x) {
1916  set_option(x, &log_mobilization_samples_);
1917  }
1918  bool log_mobilization_samples() const {
1919  return log_mobilization_samples_.value();
1920  }
1921 
1922  void set_log_rewrite_timing(bool x) {
1923  set_option(x, &log_rewrite_timing_);
1924  }
1925  bool log_rewrite_timing() const { return log_rewrite_timing_.value(); }
1926 
1927  void set_log_url_indices(bool x) {
1928  set_option(x, &log_url_indices_);
1929  }
1930  bool log_url_indices() const { return log_url_indices_.value(); }
1931 
1932  void set_lowercase_html_names(bool x) {
1933  set_option(x, &lowercase_html_names_);
1934  }
1935  bool lowercase_html_names() const { return lowercase_html_names_.value(); }
1936 
1937  void set_always_rewrite_css(bool x) {
1938  set_option(x, &always_rewrite_css_);
1939  }
1940  bool always_rewrite_css() const { return always_rewrite_css_.value(); }
1941 
1942  void set_respect_vary(bool x) {
1943  set_option(x, &respect_vary_);
1944  }
1945  bool respect_vary() const { return respect_vary_.value(); }
1946 
1947  void set_respect_x_forwarded_proto(bool x) {
1948  set_option(x, &respect_x_forwarded_proto_);
1949  }
1950  bool respect_x_forwarded_proto() const {
1951  return respect_x_forwarded_proto_.value();
1952  }
1953 
1954  void set_flush_html(bool x) { set_option(x, &flush_html_); }
1955  bool flush_html() const { return flush_html_.value(); }
1956 
1957  void set_serve_stale_if_fetch_error(bool x) {
1958  set_option(x, &serve_stale_if_fetch_error_);
1959  }
1960  bool serve_stale_if_fetch_error() const {
1961  return serve_stale_if_fetch_error_.value();
1962  }
1963 
1964  void set_serve_xhr_access_control_headers(bool x) {
1965  set_option(x, &serve_xhr_access_control_headers_);
1966  }
1967  bool serve_xhr_access_control_headers() const {
1968  return serve_xhr_access_control_headers_.value();
1969  }
1970 
1971  void set_proactively_freshen_user_facing_request(bool x) {
1972  set_option(x, &proactively_freshen_user_facing_request_);
1973  }
1974  bool proactively_freshen_user_facing_request() const {
1975  return proactively_freshen_user_facing_request_.value();
1976  }
1977 
1978  void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
1979  set_option(x, &serve_stale_while_revalidate_threshold_sec_);
1980  }
1981  int64 serve_stale_while_revalidate_threshold_sec() const {
1982  return serve_stale_while_revalidate_threshold_sec_.value();
1983  }
1984 
1985  void set_enable_flush_early_critical_css(bool x) {
1986  set_option(x, &enable_flush_early_critical_css_);
1987  }
1988  bool enable_flush_early_critical_css() const {
1989  return enable_flush_early_critical_css_.value();
1990  }
1991 
1992  void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); }
1993  bool default_cache_html() const { return default_cache_html_.value(); }
1994 
1995  void set_modify_caching_headers(bool x) {
1996  set_option(x, &modify_caching_headers_);
1997  }
1998  bool modify_caching_headers() const {
1999  return modify_caching_headers_.value();
2000  }
2001 
2002  void set_inline_only_critical_images(bool x) {
2003  set_option(x, &inline_only_critical_images_);
2004  }
2005  bool inline_only_critical_images() const {
2006  return inline_only_critical_images_.value();
2007  }
2008 
2009  void set_critical_images_beacon_enabled(bool x) {
2010  set_option(x, &critical_images_beacon_enabled_);
2011  }
2012  bool critical_images_beacon_enabled() const {
2013  return critical_images_beacon_enabled_.value();
2014  }
2015 
2016  void set_beacon_reinstrument_time_sec(int x) {
2017  set_option(x, &beacon_reinstrument_time_sec_);
2018  }
2019  int beacon_reinstrument_time_sec() const {
2020  return beacon_reinstrument_time_sec_.value();
2021  }
2022 
2023  void set_accept_invalid_signatures(bool x) {
2024  set_option(x, &accept_invalid_signatures_);
2025  }
2026  bool accept_invalid_signatures() const {
2027  return accept_invalid_signatures_.value();
2028  }
2029 
2030  void set_remote_configuration_timeout_ms(int64 x) {
2031  set_option(x, &remote_configuration_timeout_ms_);
2032  }
2033  int64 remote_configuration_timeout_ms() const {
2034  return remote_configuration_timeout_ms_.value();
2035  }
2036 
2037  void set_remote_configuration_url(StringPiece p) {
2038  set_option(GoogleString(p.data(), p.size()), &remote_configuration_url_);
2039  }
2040  const GoogleString& remote_configuration_url() const {
2041  return remote_configuration_url_.value();
2042  }
2043 
2044  void set_http_cache_compression_level(int x) {
2045  set_option(x, &http_cache_compression_level_);
2046  }
2047  int http_cache_compression_level() const {
2048  return http_cache_compression_level_.value();
2049  }
2050 
2051  void set_request_option_override(StringPiece p) {
2052  set_option(GoogleString(p.data(), p.size()), &request_option_override_);
2053  }
2054  const GoogleString& request_option_override() const {
2055  return request_option_override_.value();
2056  }
2057 
2058  void set_url_signing_key(StringPiece p) {
2059  set_option(GoogleString(p.data(), p.size()), &url_signing_key_);
2060  }
2061  const GoogleString& url_signing_key() const {
2062  return url_signing_key_.value();
2063  }
2064 
2065  void set_lazyload_images_after_onload(bool x) {
2066  set_option(x, &lazyload_images_after_onload_);
2067  }
2068  bool lazyload_images_after_onload() const {
2069  return lazyload_images_after_onload_.value();
2070  }
2071 
2072  void set_lazyload_images_blank_url(StringPiece p) {
2073  set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_);
2074  }
2075  const GoogleString& lazyload_images_blank_url() const {
2076  return lazyload_images_blank_url_.value();
2077  }
2078 
2079  void set_max_inlined_preview_images_index(int x) {
2080  set_option(x, &max_inlined_preview_images_index_);
2081  }
2082  int max_inlined_preview_images_index() const {
2083  return max_inlined_preview_images_index_.value();
2084  }
2085 
2086  void set_use_blank_image_for_inline_preview(bool x) {
2087  set_option(x, &use_blank_image_for_inline_preview_);
2088  }
2089  bool use_blank_image_for_inline_preview() const {
2090  return use_blank_image_for_inline_preview_.value();
2091  }
2092 
2093  void set_min_image_size_low_resolution_bytes(int64 x) {
2094  set_option(x, &min_image_size_low_resolution_bytes_);
2095  }
2096  int64 min_image_size_low_resolution_bytes() const {
2097  return min_image_size_low_resolution_bytes_.value();
2098  }
2099 
2100  void set_max_image_size_low_resolution_bytes(int64 x) {
2101  set_option(x, &max_image_size_low_resolution_bytes_);
2102  }
2103  int64 max_image_size_low_resolution_bytes() const {
2104  return max_image_size_low_resolution_bytes_.value();
2105  }
2106 
2107  void set_experiment_cookie_duration_ms(int64 x) {
2108  set_option(x, &experiment_cookie_duration_ms_);
2109  }
2110  int64 experiment_cookie_duration_ms() const {
2111  return experiment_cookie_duration_ms_.value();
2112  }
2113 
2114  void set_finder_properties_cache_expiration_time_ms(int64 x) {
2115  set_option(x, &finder_properties_cache_expiration_time_ms_);
2116  }
2117  int64 finder_properties_cache_expiration_time_ms() const {
2118  return finder_properties_cache_expiration_time_ms_.value();
2119  }
2120 
2121  void set_finder_properties_cache_refresh_time_ms(int64 x) {
2122  set_option(x, &finder_properties_cache_refresh_time_ms_);
2123  }
2124  int64 finder_properties_cache_refresh_time_ms() const {
2125  return finder_properties_cache_refresh_time_ms_.value();
2126  }
2127 
2128  void set_rewrite_random_drop_percentage(int x) {
2129  set_option(x, &rewrite_random_drop_percentage_);
2130  }
2131  int rewrite_random_drop_percentage() const {
2132  return rewrite_random_drop_percentage_.value();
2133  }
2134 
2141  bool css_preserve_urls() const {
2142  return (CheckBandwidthOption(css_preserve_urls_) ||
2143  CheckMobilizeFiltersOption(css_preserve_urls_));
2144  }
2145  void set_css_preserve_urls(bool x) {
2146  set_option(x, &css_preserve_urls_);
2147  }
2148 
2149  bool image_preserve_urls() const {
2150  return CheckBandwidthOption(image_preserve_urls_);
2151  }
2152  void set_image_preserve_urls(bool x) {
2153  set_option(x, &image_preserve_urls_);
2154  }
2155 
2156  bool js_preserve_urls() const {
2157  return CheckBandwidthOption(js_preserve_urls_);
2158  }
2159  void set_js_preserve_urls(bool x) {
2160  set_option(x, &js_preserve_urls_);
2161  }
2162 
2163  void set_metadata_cache_staleness_threshold_ms(int64 x) {
2164  set_option(x, &metadata_cache_staleness_threshold_ms_);
2165  }
2166  int64 metadata_cache_staleness_threshold_ms() const {
2167  return metadata_cache_staleness_threshold_ms_.value();
2168  }
2169 
2170  void set_metadata_input_errors_cache_ttl_ms(int64 x) {
2171  set_option(x, &metadata_input_errors_cache_ttl_ms_);
2172  }
2173  int64 metadata_input_errors_cache_ttl_ms() const {
2174  return metadata_input_errors_cache_ttl_ms_.value();
2175  }
2176 
2177  const GoogleString& downstream_cache_purge_method() const {
2178  return downstream_cache_purge_method_.value();
2179  }
2180  void set_downstream_cache_purge_method(StringPiece p) {
2181  set_option(p.as_string(), &downstream_cache_purge_method_);
2182  }
2183 
2184  const GoogleString& downstream_cache_purge_location_prefix() const {
2185  return downstream_cache_purge_location_prefix_.value();
2186  }
2190  while (p.ends_with("/")) {
2191  p.remove_suffix(1);
2192  }
2193  set_option(p.as_string(), &downstream_cache_purge_location_prefix_);
2194  }
2195  bool IsDownstreamCacheIntegrationEnabled() const {
2196  return !downstream_cache_purge_location_prefix().empty();
2197  }
2198 
2199  void set_downstream_cache_rebeaconing_key(StringPiece p) {
2200  set_option(p.as_string(), &downstream_cache_rebeaconing_key_);
2201  }
2202  const GoogleString& downstream_cache_rebeaconing_key() const {
2203  return downstream_cache_rebeaconing_key_.value();
2204  }
2205  bool IsDownstreamCacheRebeaconingKeyConfigured() const {
2206  return !downstream_cache_rebeaconing_key().empty();
2207  }
2210  bool MatchesDownstreamCacheRebeaconingKey(StringPiece key) const {
2211  if (!IsDownstreamCacheRebeaconingKeyConfigured()) {
2212  return false;
2213  }
2214  return StringCaseEqual(key, downstream_cache_rebeaconing_key());
2215  }
2216 
2217  void set_downstream_cache_rewritten_percentage_threshold(int64 x) {
2218  set_option(x, &downstream_cache_rewritten_percentage_threshold_);
2219  }
2220  int64 downstream_cache_rewritten_percentage_threshold() const {
2221  return downstream_cache_rewritten_percentage_threshold_.value();
2222  }
2223 
2224  const BeaconUrl& beacon_url() const { return beacon_url_.value(); }
2225  void set_beacon_url(const GoogleString& beacon_url) {
2226  GoogleString ignored_error_detail;
2227  beacon_url_.SetFromString(beacon_url, &ignored_error_detail);
2228  }
2229 
2231  virtual bool trim_urls_in_css() const { return true; }
2232 
2233  void set_image_jpeg_recompress_quality(int64 x) {
2234  set_option(x, &image_jpeg_recompress_quality_);
2235  }
2236 
2237  void set_image_jpeg_recompress_quality_for_small_screens(int64 x) {
2238  set_option(x, &image_jpeg_recompress_quality_for_small_screens_);
2239  }
2240 
2241  void set_image_jpeg_quality_for_save_data(int64 x) {
2242  set_option(x, &image_jpeg_quality_for_save_data_);
2243  }
2244 
2245  int64 image_recompress_quality() const {
2246  return image_recompress_quality_.value();
2247  }
2248  void set_image_recompress_quality(int64 x) {
2249  set_option(x, &image_recompress_quality_);
2250  }
2251 
2252  int image_limit_optimized_percent() const {
2253  return image_limit_optimized_percent_.value();
2254  }
2255  void set_image_limit_optimized_percent(int x) {
2256  set_option(x, &image_limit_optimized_percent_);
2257  }
2258  int image_limit_resize_area_percent() const {
2259  return image_limit_resize_area_percent_.value();
2260  }
2261  void set_image_limit_resize_area_percent(int x) {
2262  set_option(x, &image_limit_resize_area_percent_);
2263  }
2264 
2265  int image_limit_rendered_area_percent() const {
2266  return image_limit_rendered_area_percent_.value();
2267  }
2268  void set_image_limit_rendered_area_percent(int x) {
2269  set_option(x, &image_limit_rendered_area_percent_);
2270  }
2271 
2272  int64 image_jpeg_num_progressive_scans() const {
2273  return image_jpeg_num_progressive_scans_.value();
2274  }
2275  void set_image_jpeg_num_progressive_scans(int64 x) {
2276  set_option(x, &image_jpeg_num_progressive_scans_);
2277  }
2278 
2279  void set_image_jpeg_num_progressive_scans_for_small_screens(int64 x) {
2280  set_option(x, &image_jpeg_num_progressive_scans_for_small_screens_);
2281  }
2282 
2283  void set_image_webp_recompress_quality(int64 x) {
2284  set_option(x, &image_webp_recompress_quality_);
2285  }
2286 
2287  void set_image_webp_recompress_quality_for_small_screens(int64 x) {
2288  set_option(x, &image_webp_recompress_quality_for_small_screens_);
2289  }
2290 
2291  void set_image_webp_animated_recompress_quality(int64 x) {
2292  set_option(x, &image_webp_animated_recompress_quality_);
2293  }
2294 
2295  void set_image_webp_quality_for_save_data(int64 x) {
2296  set_option(x, &image_webp_quality_for_save_data_);
2297  }
2298 
2299  int64 image_webp_timeout_ms() const {
2300  return image_webp_timeout_ms_.value();
2301  }
2302  void set_image_webp_timeout_ms(int64 x) {
2303  set_option(x, &image_webp_timeout_ms_);
2304  }
2305 
2306  bool domain_rewrite_hyperlinks() const {
2307  return CheckMobilizeFiltersOption(domain_rewrite_hyperlinks_);
2308  }
2309  void set_domain_rewrite_hyperlinks(bool x) {
2310  set_option(x, &domain_rewrite_hyperlinks_);
2311  }
2312 
2313  bool domain_rewrite_cookies() const {
2314  return CheckMobilizeFiltersOption(domain_rewrite_cookies_);
2315  }
2316  void set_domain_rewrite_cookies(bool x) {
2317  set_option(x, &domain_rewrite_cookies_);
2318  }
2319 
2320  bool client_domain_rewrite() const {
2321  return client_domain_rewrite_.value();
2322  }
2323  void set_client_domain_rewrite(bool x) {
2324  set_option(x, &client_domain_rewrite_);
2325  }
2326 
2327  void set_flush_more_resources_early_if_time_permits(bool x) {
2328  set_option(x, &flush_more_resources_early_if_time_permits_);
2329  }
2330  bool flush_more_resources_early_if_time_permits() const {
2331  return flush_more_resources_early_if_time_permits_.value();
2332  }
2333 
2334  void set_flush_more_resources_in_ie_and_firefox(bool x) {
2335  set_option(x, &flush_more_resources_in_ie_and_firefox_);
2336  }
2337  bool flush_more_resources_in_ie_and_firefox() const {
2338  return flush_more_resources_in_ie_and_firefox_.value();
2339  }
2340 
2341  void set_max_prefetch_js_elements(int x) {
2342  set_option(x, &max_prefetch_js_elements_);
2343  }
2344  int max_prefetch_js_elements() const {
2345  return max_prefetch_js_elements_.value();
2346  }
2347 
2348  void set_enable_defer_js_experimental(bool x) {
2349  set_option(x, &enable_defer_js_experimental_);
2350  }
2351  bool enable_defer_js_experimental() const {
2352  return enable_defer_js_experimental_.value();
2353  }
2354 
2355  void set_disable_rewrite_on_no_transform(bool x) {
2356  set_option(x, &disable_rewrite_on_no_transform_);
2357  }
2358  bool disable_rewrite_on_no_transform() const {
2359  return disable_rewrite_on_no_transform_.value();
2360  }
2361 
2362  void set_disable_background_fetches_for_bots(bool x) {
2363  set_option(x, &disable_background_fetches_for_bots_);
2364  }
2365  bool disable_background_fetches_for_bots() const {
2366  return disable_background_fetches_for_bots_.value();
2367  }
2368 
2369  void set_enable_cache_purge(bool x) {
2370  set_option(x, &enable_cache_purge_);
2371  }
2372  bool enable_cache_purge() const {
2373  return enable_cache_purge_.value();
2374  }
2375 
2376  void set_proactive_resource_freshening(bool x) {
2377  set_option(x, &proactive_resource_freshening_);
2378  }
2379  bool proactive_resource_freshening() const {
2380  return proactive_resource_freshening_.value();
2381  }
2382 
2383  void set_lazyload_highres_images(bool x) {
2384  set_option(x, &lazyload_highres_images_);
2385  }
2386  bool lazyload_highres_images() const {
2387  return lazyload_highres_images_.value();
2388  }
2389 
2390  void set_use_fallback_property_cache_values(bool x) {
2391  set_option(x, &use_fallback_property_cache_values_);
2392  }
2393  bool use_fallback_property_cache_values() const {
2394  return use_fallback_property_cache_values_.value();
2395  }
2396 
2397  void set_await_pcache_lookup(bool x) {
2398  set_option(x, &await_pcache_lookup_);
2399  }
2400  bool await_pcache_lookup() const {
2401  return await_pcache_lookup_.value();
2402  }
2403 
2404  void set_enable_prioritizing_scripts(bool x) {
2405  set_option(x, &enable_prioritizing_scripts_);
2406  }
2407  bool enable_prioritizing_scripts() const {
2408  return enable_prioritizing_scripts_.value();
2409  }
2410 
2411  const GoogleString& blocking_rewrite_key() const {
2412  return blocking_rewrite_key_.value();
2413  }
2414  void set_blocking_rewrite_key(StringPiece p) {
2415  set_option(p.as_string(), &blocking_rewrite_key_);
2416  }
2417 
2418  void EnableBlockingRewriteForRefererUrlPattern(
2419  StringPiece url_pattern) {
2420  Modify();
2421  blocking_rewrite_referer_urls_.MakeWriteable()->Allow(url_pattern);
2422  }
2423 
2424  bool IsBlockingRewriteEnabledForReferer(StringPiece url) const {
2425  return blocking_rewrite_referer_urls_->Match(url, false);
2426  }
2427 
2428  bool IsBlockingRewriteRefererUrlPatternPresent() const {
2429  return blocking_rewrite_referer_urls_->num_wildcards() > 0;
2430  }
2431 
2432  bool rewrite_uncacheable_resources() const {
2433  return rewrite_uncacheable_resources_.value();
2434  }
2435 
2436  void set_rewrite_uncacheable_resources(bool x) {
2437  set_option(x, &rewrite_uncacheable_resources_);
2438  }
2439 
2440  void set_running_experiment(bool x) {
2441  set_option(x, &running_experiment_);
2442  }
2443  bool running_experiment() const {
2444  return running_experiment_.value();
2445  }
2446 
2449  set_option(x, &experiment_ga_slot_);
2450  }
2451  int experiment_ga_slot() const { return experiment_ga_slot_.value(); }
2452 
2453  void set_enroll_experiment_id(int x) {
2454  set_option(x, &enroll_experiment_id_);
2455  }
2456  int enroll_experiment_id() const { return enroll_experiment_id_.value(); }
2457 
2458  void set_report_unload_time(bool x) {
2459  set_option(x, &report_unload_time_);
2460  }
2461  bool report_unload_time() const {
2462  return report_unload_time_.value();
2463  }
2464 
2465  void set_implicit_cache_ttl_ms(int64 x) {
2466  set_option(x, &implicit_cache_ttl_ms_);
2467  }
2468  int64 implicit_cache_ttl_ms() const {
2469  return implicit_cache_ttl_ms_.value();
2470  }
2471 
2472  void set_load_from_file_cache_ttl_ms(int64 x) {
2473  set_option(x, &load_from_file_cache_ttl_ms_);
2474  }
2475  int64 load_from_file_cache_ttl_ms() const {
2476  return load_from_file_cache_ttl_ms_.value();
2477  }
2478  bool load_from_file_cache_ttl_ms_was_set() const {
2479  return load_from_file_cache_ttl_ms_.was_set();
2480  }
2481 
2482  void set_x_header_value(StringPiece p) {
2483  set_option(p.as_string(), &x_header_value_);
2484  }
2485  const GoogleString& x_header_value() const {
2486  return x_header_value_.value();
2487  }
2488 
2489  void set_distributed_rewrite_key(StringPiece p) {
2490  set_option(p.as_string(), &distributed_rewrite_key_);
2491  }
2492  const GoogleString& distributed_rewrite_key() const {
2493  return distributed_rewrite_key_.value();
2494  }
2495 
2496  void set_distribute_fetches(bool x) {
2497  set_option(x, &distribute_fetches_);
2498  }
2499  bool distribute_fetches() const {
2500  return distribute_fetches_.value();
2501  }
2502 
2503  void set_distributed_rewrite_servers(StringPiece p) {
2504  set_option(p.as_string(), &distributed_rewrite_servers_);
2505  }
2506  const GoogleString& distributed_rewrite_servers() const {
2507  return distributed_rewrite_servers_.value();
2508  }
2509 
2510  void set_distributed_rewrite_timeout_ms(const int64 x) {
2511  set_option(x, &distributed_rewrite_timeout_ms_);
2512  }
2513  int64 distributed_rewrite_timeout_ms() const {
2514  return distributed_rewrite_timeout_ms_.value();
2515  }
2516 
2517  void set_avoid_renaming_introspective_javascript(bool x) {
2518  set_option(x, &avoid_renaming_introspective_javascript_);
2519  }
2520  bool avoid_renaming_introspective_javascript() const {
2521  return avoid_renaming_introspective_javascript_.value();
2522  }
2523 
2524  void set_forbid_all_disabled_filters(bool x) {
2525  set_option(x, &forbid_all_disabled_filters_);
2526  }
2527  bool forbid_all_disabled_filters() const {
2528  return forbid_all_disabled_filters_.value();
2529  }
2530 
2531  bool reject_blacklisted() const { return reject_blacklisted_.value(); }
2532  void set_reject_blacklisted(bool x) {
2533  set_option(x, &reject_blacklisted_);
2534  }
2535 
2536  HttpStatus::Code reject_blacklisted_status_code() const {
2537  return static_cast<HttpStatus::Code>(
2538  reject_blacklisted_status_code_.value());
2539  }
2540  void set_reject_blacklisted_status_code(HttpStatus::Code x) {
2541  set_option(static_cast<int>(x), &reject_blacklisted_status_code_);
2542  }
2543 
2544  bool support_noscript_enabled() const {
2545  return support_noscript_enabled_.value();
2546  }
2547  void set_support_noscript_enabled(bool x) {
2548  set_option(x, &support_noscript_enabled_);
2549  }
2550 
2551  bool enable_extended_instrumentation() const {
2552  return enable_extended_instrumentation_.value();
2553  }
2554  void set_enable_extended_instrumentation(bool x) {
2555  set_option(x, &enable_extended_instrumentation_);
2556  }
2557 
2558  bool use_experimental_js_minifier() const {
2559  return use_experimental_js_minifier_.value();
2560  }
2561  void set_use_experimental_js_minifier(bool x) {
2562  set_option(x, &use_experimental_js_minifier_);
2563  }
2564 
2565  void set_max_combined_css_bytes(int64 x) {
2566  set_option(x, &max_combined_css_bytes_);
2567  }
2568  int64 max_combined_css_bytes() const {
2569  return max_combined_css_bytes_.value();
2570  }
2571 
2572  void set_max_combined_js_bytes(int64 x) {
2573  set_option(x, &max_combined_js_bytes_);
2574  }
2575  int64 max_combined_js_bytes() const {
2576  return max_combined_js_bytes_.value();
2577  }
2578 
2579  void set_pre_connect_url(StringPiece p) {
2580  set_option(GoogleString(p.data(), p.size()), &pre_connect_url_);
2581  }
2582  const GoogleString& pre_connect_url() const {
2583  return pre_connect_url_.value();
2584  }
2585  void set_property_cache_http_status_stability_threshold(int x) {
2586  set_option(x, &property_cache_http_status_stability_threshold_);
2587  }
2588  int property_cache_http_status_stability_threshold() const {
2589  return property_cache_http_status_stability_threshold_.value();
2590  }
2591 
2592  void set_max_rewrite_info_log_size(int x) {
2593  set_option(x, &max_rewrite_info_log_size_);
2594  }
2595  int max_rewrite_info_log_size() const {
2596  return max_rewrite_info_log_size_.value();
2597  }
2598 
2599  void set_enable_aggressive_rewriters_for_mobile(bool x) {
2600  set_option(x, &enable_aggressive_rewriters_for_mobile_);
2601  }
2602  bool enable_aggressive_rewriters_for_mobile() const {
2603  return enable_aggressive_rewriters_for_mobile_.value();
2604  }
2605 
2606  void set_allow_logging_urls_in_log_record(bool x) {
2607  set_option(x, &allow_logging_urls_in_log_record_);
2608  }
2609  bool allow_logging_urls_in_log_record() const {
2610  return allow_logging_urls_in_log_record_.value();
2611  }
2612 
2613  void set_allow_options_to_be_set_by_cookies(bool x) {
2614  set_option(x, &allow_options_to_be_set_by_cookies_);
2615  }
2616  bool allow_options_to_be_set_by_cookies() const {
2617  return allow_options_to_be_set_by_cookies_.value();
2618  }
2619 
2620  void set_non_cacheables_for_cache_partial_html(StringPiece p) {
2621  set_option(p.as_string(), &non_cacheables_for_cache_partial_html_);
2622  }
2623  const GoogleString& non_cacheables_for_cache_partial_html() const {
2624  return non_cacheables_for_cache_partial_html_.value();
2625  }
2626 
2627  void set_no_transform_optimized_images(bool x) {
2628  set_option(x, &no_transform_optimized_images_);
2629  }
2630  bool no_transform_optimized_images() const {
2631  return no_transform_optimized_images_.value();
2632  }
2633 
2634  void set_access_control_allow_origins(StringPiece p) {
2635  set_option(p.as_string(), &access_control_allow_origins_);
2636  }
2637  const GoogleString& access_control_allow_origins() const {
2638  return access_control_allow_origins_.value();
2639  }
2640 
2641  void set_hide_referer_using_meta(bool x) {
2642  set_option(x, &hide_referer_using_meta_);
2643  }
2644  bool hide_referer_using_meta() const {
2645  return hide_referer_using_meta_.value();
2646  }
2647 
2648  void set_max_low_res_image_size_bytes(int64 x) {
2649  set_option(x, &max_low_res_image_size_bytes_);
2650  }
2651  int64 max_low_res_image_size_bytes() const {
2652  return max_low_res_image_size_bytes_.value();
2653  }
2654 
2655  void set_max_low_res_to_full_res_image_size_percentage(int x) {
2656  set_option(x, &max_low_res_to_full_res_image_size_percentage_);
2657  }
2658  int max_low_res_to_full_res_image_size_percentage() const {
2659  return max_low_res_to_full_res_image_size_percentage_.value();
2660  }
2661 
2662  void set_serve_rewritten_webp_urls_to_any_agent(bool x) {
2663  set_option(x, &serve_rewritten_webp_urls_to_any_agent_);
2664  }
2665  bool serve_rewritten_webp_urls_to_any_agent() const {
2666  return serve_rewritten_webp_urls_to_any_agent_.value();
2667  }
2668 
2669  void set_cache_fragment(StringPiece p) {
2670  set_option(p.as_string(), &cache_fragment_);
2671  }
2672  const GoogleString& cache_fragment() const {
2673  return cache_fragment_.value();
2674  }
2675 
2676  void set_sticky_query_parameters(StringPiece p) {
2677  set_option(p.as_string(), &sticky_query_parameters_);
2678  }
2679  const GoogleString& sticky_query_parameters() const {
2680  return sticky_query_parameters_.value();
2681  }
2682 
2683  void set_option_cookies_duration_ms(int64 x) {
2684  set_option(x, &option_cookies_duration_ms_);
2685  }
2686  int64 option_cookies_duration_ms() const {
2687  return option_cookies_duration_ms_.value();
2688  }
2689 
2690  void set_responsive_image_densities(const ResponsiveDensities& x) {
2691  set_option(x, &responsive_image_densities_);
2692  }
2693  const ResponsiveDensities& responsive_image_densities() const {
2694  return responsive_image_densities_.value();
2695  }
2696 
2697  const GoogleString& amp_link_pattern() const {
2698  return amp_link_pattern_.value();
2699  }
2700  void set_amp_link_pattern(const GoogleString& id) {
2701  set_option(id, &amp_link_pattern_);
2702  }
2703 
2704  bool mob_always() const { return mob_always_.value(); }
2705  void set_mob_always(bool x) { set_option(x, &mob_always_); }
2706  bool mob_iframe() const { return mob_iframe_.value(); }
2707  const GoogleString& mob_iframe_viewport() const {
2708  return mob_iframe_viewport_.value();
2709  }
2710  bool mob_iframe_disable() const { return mob_iframe_disable_.value(); }
2711  void set_mob_beacon_url(StringPiece x) {
2712  set_option(x.as_string(), &mob_beacon_url_);
2713  }
2714  const GoogleString& mob_beacon_url() const { return mob_beacon_url_.value(); }
2715  void set_mob_beacon_category(StringPiece x) {
2716  set_option(x.as_string(), &mob_beacon_category_);
2717  }
2718  const GoogleString& mob_beacon_category() const {
2719  return mob_beacon_category_.value();
2720  }
2721  void set_mob_phone_number(StringPiece x) {
2722  set_option(x.as_string(), &mob_phone_number_);
2723  }
2724  const GoogleString& mob_phone_number() const {
2725  return mob_phone_number_.value();
2726  }
2727  void set_mob_map_location(StringPiece x) {
2728  set_option(x.as_string(), &mob_map_location_);
2729  }
2730  const GoogleString& mob_map_location() const {
2731  return mob_map_location_.value();
2732  }
2733  void set_mob_iframe(bool x) { set_option(x, &mob_iframe_); }
2734  void set_mob_iframe_disable(bool x) { set_option(x, &mob_iframe_disable_); }
2735  void set_mob_iframe_viewport(StringPiece x) {
2736  set_option(x.as_string(), &mob_iframe_viewport_);
2737  }
2738  const MobTheme& mob_theme() const { return mob_theme_.value(); }
2739  void set_mob_theme(const MobTheme& x) {
2740  set_option(x, &mob_theme_);
2741  }
2742  bool has_mob_theme() const { return mob_theme_.was_set(); }
2743  int64 mob_conversion_id() const { return mob_conversion_id_.value(); }
2744  void set_mob_conversion_id(int64 x) { set_option(x, &mob_conversion_id_); }
2745  const GoogleString& mob_map_conversion_label() const {
2746  return mob_map_conversion_label_.value();
2747  }
2748  void set_mob_map_conversion_label(StringPiece x) {
2749  set_option(x.as_string(), &mob_map_conversion_label_);
2750  }
2751  const GoogleString& mob_phone_conversion_label() const {
2752  return mob_phone_conversion_label_.value();
2753  }
2754  void set_mob_phone_conversion_label(StringPiece x) {
2755  set_option(x.as_string(), &mob_phone_conversion_label_);
2756  }
2757 
2773  virtual void Merge(const RewriteOptions& src);
2774 
2777  void Allow(StringPiece wildcard_pattern) {
2778  Modify();
2779  allow_resources_.MakeWriteable()->Allow(wildcard_pattern);
2780  }
2781 
2784  void Disallow(StringPiece wildcard_pattern) {
2785  Modify();
2786  allow_resources_.MakeWriteable()->Disallow(wildcard_pattern);
2787  }
2788 
2790  void AllowWhenInlining(StringPiece wildcard_pattern) {
2791  Modify();
2792  allow_when_inlining_resources_.MakeWriteable()->Allow(wildcard_pattern);
2793  }
2794 
2798  void AllowOnlyWhenInlining(StringPiece wildcard_pattern) {
2799  Disallow(wildcard_pattern);
2800  AllowWhenInlining(wildcard_pattern);
2801  }
2802 
2804  void DisallowWhenInlining(StringPiece wildcard_pattern) {
2805  Modify();
2806  allow_when_inlining_resources_.MakeWriteable()->Disallow(wildcard_pattern);
2807  }
2808 
2812  virtual void DisallowTroublesomeResources();
2813 
2818  virtual void DisallowResourcesForProxy();
2819 
2840  const DomainLawyer* domain_lawyer() const { return domain_lawyer_.get(); }
2841  DomainLawyer* WriteableDomainLawyer();
2842 
2843  FileLoadPolicy* file_load_policy() { return &file_load_policy_; }
2844  const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; }
2845 
2848  bool IsAllowed(StringPiece url) const {
2849  return allow_resources_->Match(url, true );
2850  }
2851 
2859  bool IsAllowedWhenInlining(StringPiece url) const {
2860  return allow_when_inlining_resources_->Match(
2861  url, false );
2862  }
2863 
2865  void RetainComment(StringPiece comment) {
2866  Modify();
2867  retain_comments_.MakeWriteable()->Allow(comment);
2868  }
2869 
2873  bool IsRetainedComment(StringPiece comment) const {
2874  return retain_comments_->Match(comment, false);
2875  }
2876 
2878  void DisableLazyloadForClassName(StringPiece class_name) {
2879  Modify();
2880  lazyload_enabled_classes_.MakeWriteable()->Disallow(class_name);
2881  }
2882 
2884  bool IsLazyloadEnabledForClassName(StringPiece class_name) const {
2885  return lazyload_enabled_classes_->Match(class_name, true);
2886  }
2887 
2888  void set_override_caching_ttl_ms(int64 x) {
2889  set_option(x, &override_caching_ttl_ms_);
2890  }
2891  int64 override_caching_ttl_ms() const {
2892  return override_caching_ttl_ms_.value();
2893  }
2894 
2897  void AddOverrideCacheTtl(StringPiece wildcard) {
2898  Modify();
2899  override_caching_wildcard_.MakeWriteable()->Allow(wildcard);
2900  }
2901 
2903  bool IsCacheTtlOverridden(StringPiece url) const {
2904  return override_caching_wildcard_->Match(url, false);
2905  }
2906 
2907  void AddRejectedUrlWildcard(const GoogleString& wildcard) {
2908  AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard);
2909  }
2910 
2911  void AddRejectedHeaderWildcard(StringPiece header_name,
2912  const GoogleString& wildcard) {
2913  Modify();
2914  std::pair<FastWildcardGroupMap::iterator, bool> insert_result =
2915  rejected_request_map_.insert(std::make_pair(
2916  header_name, static_cast<FastWildcardGroup*>(NULL)));
2917 
2918  if (insert_result.second) {
2919  insert_result.first->second = new FastWildcardGroup;
2920  }
2921  insert_result.first->second->Allow(wildcard);
2922  }
2923 
2924  void set_min_cache_ttl_ms(int64 x) {
2925  set_option(x, &min_cache_ttl_ms_);
2926  }
2927  int64 min_cache_ttl_ms() const {
2928  return min_cache_ttl_ms_.value();
2929  }
2930 
2933  bool IsRequestDeclined(const GoogleString& url,
2934  const RequestHeaders* request_headers) const;
2935 
2939  virtual RewriteOptions* Clone() const;
2940 
2942  virtual RewriteOptions* NewOptions() const;
2943 
2949  void ComputeSignature() LOCKS_EXCLUDED(cache_purge_mutex_.get());
2950  void ComputeSignatureLockHeld() SHARED_LOCKS_REQUIRED(cache_purge_mutex_);
2951 
2954  virtual GoogleString SubclassSignatureLockHeld() { return ""; }
2955 
2960  void Freeze();
2961 
2972 
2973  bool frozen() const { return frozen_; }
2974 
2979  bool frozen = frozen_;
2981  return frozen;
2982  }
2983 
2985  const GoogleString& signature() const {
2993  ThreadSystem::ScopedReader lock(cache_purge_mutex_.get());
2994  DCHECK(frozen_);
2995  DCHECK(!signature_.empty());
2996  return signature_;
2997  }
2998 
2999  virtual GoogleString OptionsToString() const;
3000  GoogleString FilterSetToString(const FilterSet& filter_set) const;
3001  GoogleString EnabledFiltersToString() const;
3004  GoogleString SafeEnabledOptionsToString() const;
3005 
3008  virtual GoogleString ToExperimentString() const;
3009 
3013  virtual GoogleString ToExperimentDebugString() const;
3014 
3017  static Filter LookupFilterById(const StringPiece& filter_id);
3018 
3020  static Filter LookupFilter(const StringPiece& filter_name);
3021 
3024  static const PropertyBase* LookupOptionById(StringPiece option_id);
3025  static const PropertyBase* LookupOptionByName(StringPiece option_name);
3026 
3029  static const StringPiece LookupOptionNameById(StringPiece option_id);
3030 
3032  static bool IsValidOptionName(StringPiece name);
3033 
3037  return all_options_;
3038  }
3039 
3043  bool IsEqual(const RewriteOptions& that) const;
3044 
3046  const Hasher* hasher() const { return &hasher_; }
3047 
3048  const SHA1Signature* sha1signature() const { return &sha1signature_; }
3049 
3050  ThreadSystem* thread_system() const { return thread_system_; }
3051 
3055  HttpOptions ComputeHttpOptions() const;
3056 
3060  return Enabled(kExperimentHttp2);
3061  }
3062 
3063  protected:
3073  template<class T> class OptionTemplateBase : public OptionBase {
3074  public:
3075  typedef T ValueType;
3076 
3077  OptionTemplateBase() : was_set_(false), property_(NULL) {}
3078 
3079  virtual bool was_set() const { return was_set_; }
3080 
3081  void set(const T& val) {
3082  was_set_ = true;
3083  value_ = val;
3084  }
3085 
3086  void set_default(const T& val) {
3087  if (!was_set_) {
3088  value_ = val;
3089  }
3090  }
3091 
3092  const T& value() const { return value_; }
3093  T& mutable_value() { was_set_ = true; return value_; }
3094 
3100  virtual void Merge(const OptionBase* src) {
3101  DCHECK(option_name() == src->option_name());
3102  MergeHelper(static_cast<const OptionTemplateBase*>(src));
3103  }
3104 
3105  void MergeHelper(const OptionTemplateBase* src) {
3108  if (src->was_set_ || !was_set_) {
3109  value_ = src->value_;
3110  was_set_ = src->was_set_;
3111  }
3112  }
3113 
3115  void set_property(const Property<T>* property) {
3116  property_ = property;
3117 
3122  value_ = property->default_value();
3123  }
3124  virtual const PropertyBase* property() const { return property_; }
3125 
3134  void set_global_default(const T& val) {
3135  Property<T>* property = const_cast<Property<T>*>(property_);
3136  property->set_default(val);
3137  }
3138 
3148  Property<T>* property = const_cast<Property<T>*>(property_);
3149  property->set_do_not_use_for_signature_computation(true);
3150  }
3151 
3152  private:
3153  bool was_set_;
3154  T value_;
3155  const Property<T>* property_;
3156 
3157 
3158  };
3159 
3164  template<class T> class Option : public OptionTemplateBase<T> {
3165  public:
3166  Option() {}
3167 
3169  virtual bool SetFromString(StringPiece value_string,
3170  GoogleString* error_detail) {
3171  T value;
3172  bool success = RewriteOptions::ParseFromString(value_string, &value);
3173  if (success) {
3174  this->set(value);
3175  }
3176  return success;
3177  }
3178 
3179  virtual GoogleString Signature(const Hasher* hasher) const {
3180  return RewriteOptions::OptionSignature(this->value(), hasher);
3181  }
3182 
3183  virtual GoogleString ToString() const {
3184  return RewriteOptions::ToString(this->value());
3185  }
3186 
3187  private:
3188 
3189  };
3190 
3191  protected:
3193  template<class RewriteOptionsSubclass, class OptionClass>
3194  static void AddProperty(
3195  typename OptionClass::ValueType default_value,
3196  OptionClass RewriteOptionsSubclass::*offset,
3197  const char* id,
3198  StringPiece option_name,
3199  OptionScope scope,
3200  const char* help_text,
3201  bool safe_to_print,
3202  Properties* properties) {
3203  PropertyBase* property =
3205  default_value, offset, id, option_name);
3206  property->set_scope(scope);
3207  property->set_help_text(help_text);
3208  property->set_safe_to_print(safe_to_print);
3209  properties->push_back(property);
3210  }
3211 
3225  static void MergeSubclassProperties(Properties* properties);
3226 
3232  void set_option_at(int index, OptionBase* option) {
3233  all_options_[index] = option;
3234  }
3235 
3239  template<class T>
3240  void set_option(const T& new_value, OptionTemplateBase<T>* option) {
3241  option->set(new_value);
3242  Modify();
3243  }
3244 
3246  void Modify();
3247 
3255  void set_default_x_header_value(StringPiece x_header_value) {
3256  x_header_value_.set_global_default(x_header_value.as_string());
3257  }
3258 
3262  bool SetupExperimentRewriters();
3263 
3265  virtual void SetRequiredExperimentFilters();
3266 
3270  bool InsertExperimentSpecInVector(ExperimentSpec* spec);
3271 
3274 
3277 
3278  protected:
3282  public:
3283  PropertyBase(const char* id, StringPiece option_name)
3284  : id_(id),
3285  help_text_(NULL),
3286  option_name_(option_name),
3287  scope_(kDirectoryScope),
3288  do_not_use_for_signature_computation_(false),
3289  index_(-1) {
3290  }
3291  virtual ~PropertyBase();
3292 
3295  virtual void InitializeOption(RewriteOptions* options) const = 0;
3296 
3297  void set_do_not_use_for_signature_computation(bool x) {
3298  do_not_use_for_signature_computation_ = x;
3299  }
3300  bool is_used_for_signature_computation() const {
3301  return !do_not_use_for_signature_computation_;
3302  }
3303 
3304  void set_scope(OptionScope x) { scope_ = x; }
3305  OptionScope scope() const { return scope_; }
3306 
3307  void set_help_text(const char* x) { help_text_ = x; }
3308  const char* help_text() const { return help_text_; }
3309 
3310  void set_index(int index) { index_ = index; }
3311  const char* id() const { return id_; }
3312  StringPiece option_name() const { return option_name_; }
3313  int index() const { return index_; }
3314 
3315  bool safe_to_print() const { return safe_to_print_; }
3316  void set_safe_to_print(bool safe_to_print) {
3317  safe_to_print_ = safe_to_print;
3318  }
3319 
3320  private:
3321  const char* id_;
3322  const char* help_text_;
3323  StringPiece option_name_;
3324  OptionScope scope_;
3325  bool do_not_use_for_signature_computation_;
3326  bool safe_to_print_;
3327  int index_;
3328 
3329 
3330  };
3331 
3335  template<class ValueType>
3336  class Property : public PropertyBase {
3337  public:
3342  Property(ValueType default_value,
3343  const char* id,
3344  StringPiece option_name)
3345  : PropertyBase(id, option_name),
3346  default_value_(default_value) {
3347  }
3348 
3349  void set_default(ValueType value) { default_value_ = value; }
3350  const ValueType& default_value() const { return default_value_; }
3351 
3352  private:
3353  ValueType default_value_;
3354 
3355 
3356  };
3357 
3372  template<class RewriteOptionsSubclass, class OptionClass>
3373  class PropertyLeaf : public Property<typename OptionClass::ValueType> {
3374  public:
3378  typedef OptionClass RewriteOptionsSubclass::*OptionOffset;
3379  typedef typename OptionClass::ValueType ValueType;
3380 
3381  PropertyLeaf(ValueType default_value,
3382  OptionOffset offset,
3383  const char* id,
3384  StringPiece option_name)
3385  : Property<ValueType>(default_value, id, option_name),
3386  offset_(offset) {
3387  }
3388 
3389  virtual void InitializeOption(RewriteOptions* options) const {
3390  RewriteOptionsSubclass* options_subclass =
3391  static_cast<RewriteOptionsSubclass*>(options);
3392  OptionClass& option = options_subclass->*offset_;
3393  option.set_property(this);
3394  DCHECK_NE(-1, this->index()) << "Call Property::set_index first.";
3395  options->set_option_at(this->index(), &option);
3396  }
3397 
3398  private:
3399  OptionOffset offset_;
3400 
3401 
3402  };
3403 
3404  private:
3406  class CacheFragmentOption : public Option<GoogleString> {
3407  public:
3408  virtual bool SetFromString(StringPiece value_string,
3409  GoogleString* error_detail);
3410  };
3411 
3412  struct OptionIdCompare;
3413 
3418  enum MergeOverride { kNoAction, kDisablePreserve, kDisableFilter };
3419 
3420  static Properties* properties_;
3421  static Properties* all_properties_;
3422 
3423  FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
3424  FRIEND_TEST(RewriteOptionsTest, LookupOptionByNameTest);
3425  FRIEND_TEST(RewriteOptionsTest, ColorUtilTest);
3426  FRIEND_TEST(RewriteOptionsTest, ParseFloats);
3427 
3429  bool HasRejectedHeader(const StringPiece& header_name,
3430  const RequestHeaders* request_headers) const;
3431 
3432  bool IsRejectedUrl(const GoogleString& url) const {
3433  return IsRejectedRequest(kRejectedRequestUrlKeyName, url);
3434  }
3435 
3436  bool IsRejectedRequest(StringPiece header_name,
3437  StringPiece value) const {
3438  FastWildcardGroupMap::const_iterator it = rejected_request_map_.find(
3439  header_name);
3440  if (it != rejected_request_map_.end()) {
3441  return it->second->Match(value, false);
3442  }
3443  return false;
3444  }
3445 
3448  JavascriptLibraryIdentification* WriteableJavascriptLibraryIdentification();
3449 
3456  struct PrioritizeVisibleContentFamily {
3457  PrioritizeVisibleContentFamily(StringPiece url_pattern_string,
3458  int64 cache_time_ms_in,
3459  StringPiece non_cacheable_elements_in)
3460  : url_pattern(url_pattern_string),
3461  cache_time_ms(cache_time_ms_in),
3462  non_cacheable_elements(non_cacheable_elements_in.data(),
3463  non_cacheable_elements_in.size()) {}
3464 
3465  PrioritizeVisibleContentFamily* Clone() const {
3466  return new PrioritizeVisibleContentFamily(
3467  url_pattern.spec(), cache_time_ms, non_cacheable_elements);
3468  }
3469 
3470  GoogleString ComputeSignature() const {
3471  return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms),
3472  ";", non_cacheable_elements);
3473  }
3474 
3475  GoogleString ToString() const {
3476  return StrCat("URL pattern: ", url_pattern.spec(), ", Cache time (ms): ",
3477  Integer64ToString(cache_time_ms), ", Non-cacheable: ",
3478  non_cacheable_elements);
3479  }
3480 
3481  Wildcard url_pattern;
3482  int64 cache_time_ms;
3483  GoogleString non_cacheable_elements;
3484  };
3485 
3488  struct UrlCacheInvalidationEntry {
3489  UrlCacheInvalidationEntry(StringPiece url_pattern_in,
3490  int64 timestamp_ms_in,
3491  bool ignores_metadata_and_pcache_in)
3492  : url_pattern(url_pattern_in),
3493  timestamp_ms(timestamp_ms_in),
3494  ignores_metadata_and_pcache(ignores_metadata_and_pcache_in) {}
3495 
3496  UrlCacheInvalidationEntry* Clone() const {
3497  return new UrlCacheInvalidationEntry(
3498  url_pattern.spec(), timestamp_ms, ignores_metadata_and_pcache);
3499  }
3500 
3501  GoogleString ComputeSignature() const {
3502  if (ignores_metadata_and_pcache) {
3503  return "";
3504  }
3505  return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms));
3506  }
3507 
3508  GoogleString ToString() const {
3509  return StrCat(
3510  url_pattern.spec(), ", ",
3511  (ignores_metadata_and_pcache ? "STRICT" : "REFERENCE"), " @ ",
3512  Integer64ToString(timestamp_ms));
3513  }
3514 
3515  Wildcard url_pattern;
3516  int64 timestamp_ms;
3517  bool ignores_metadata_and_pcache;
3518  };
3519 
3520  typedef std::vector<UrlCacheInvalidationEntry*>
3521  UrlCacheInvalidationEntryVector;
3522  typedef dense_hash_map<GoogleString, int64> UrlCacheInvalidationMap;
3523 
3527  typedef rde::hash_map<StringPiece, const PropertyBase*,
3528  CaseFoldStringPieceHash, 6,
3529  CaseFoldStringPieceEqual> PropertyNameMap;
3530 
3543  template<class OptionClass>
3544  static void AddRequestProperty(typename OptionClass::ValueType default_value,
3545  OptionClass RewriteOptions::*offset,
3546  const char* id, bool safe_to_print) {
3547  AddProperty(default_value, offset, id, kNullOption, kProcessScope,
3548  NULL, safe_to_print, properties_);
3549  }
3550 
3553  template<class OptionClass>
3554  static void AddBaseProperty(typename OptionClass::ValueType default_value,
3555  OptionClass RewriteOptions::*offset,
3556  const char* id,
3557  StringPiece option_name,
3558  OptionScope scope,
3559  const char* help,
3560  bool safe_to_print) {
3561  AddProperty(default_value, offset, id, option_name, scope, help,
3562  safe_to_print, properties_);
3563  }
3564 
3565  static void AddProperties();
3566  bool AddCommaSeparatedListToFilterSetState(
3567  const StringPiece& filters, FilterSet* set, MessageHandler* handler);
3568  static bool AddCommaSeparatedListToFilterSet(
3569  const StringPiece& filters, FilterSet* set, MessageHandler* handler);
3571  static void InitFilterIdToEnumArray();
3572  static void InitOptionIdToPropertyArray();
3573  static void InitOptionNameToPropertyArray();
3576  static void InitFixedResourceHeaders();
3577 
3581  OptionSettingResult FormatSetOptionMessage(
3582  OptionSettingResult result, StringPiece name, StringPiece value,
3583  StringPiece error_detail, GoogleString* msg);
3584 
3587  OptionSettingResult SetOptionFromNameInternal(
3588  StringPiece name, StringPiece value, OptionScope max_scope,
3589  GoogleString* error_detail);
3590 
3593  static GoogleString OptionSignature(bool x, const Hasher* hasher) {
3594  return x ? "T" : "F";
3595  }
3596  static GoogleString OptionSignature(int x, const Hasher* hasher) {
3597  return IntegerToString(x);
3598  }
3599  static GoogleString OptionSignature(int64 x, const Hasher* hasher) {
3600  return Integer64ToString(x);
3601  }
3602  static GoogleString OptionSignature(const GoogleString& x,
3603  const Hasher* hasher);
3604  static GoogleString OptionSignature(RewriteLevel x,
3605  const Hasher* hasher);
3606  static GoogleString OptionSignature(ResourceCategorySet x,
3607  const Hasher* hasher);
3608  static GoogleString OptionSignature(const BeaconUrl& beacon_url,
3609  const Hasher* hasher);
3610  static GoogleString OptionSignature(const MobTheme& mob_theme,
3611  const Hasher* hasher);
3612  static GoogleString OptionSignature(const ResponsiveDensities& densities,
3613  const Hasher* hasher);
3614  static GoogleString OptionSignature(const AllowVaryOn& allow_vary_on,
3615  const Hasher* hasher);
3616  static GoogleString OptionSignature(
3617  const protobuf::MessageLite& proto,
3618  const Hasher* hasher);
3619 
3622  static GoogleString ToString(bool x) {
3623  return x ? "True" : "False";
3624  }
3625  static GoogleString ToString(int x) {
3626  return IntegerToString(x);
3627  }
3628  static GoogleString ToString(int64 x) {
3629  return Integer64ToString(x);
3630  }
3631  static GoogleString ToString(const GoogleString& x) {
3632  return x;
3633  }
3634  static GoogleString ToString(RewriteLevel x);
3635  static GoogleString ToString(const ResourceCategorySet &x);
3636  static GoogleString ToString(const BeaconUrl& beacon_url);
3637  static GoogleString ToString(const MobTheme& mob_theme);
3638  static GoogleString ToString(const Color& color);
3639  static GoogleString ToString(const ResponsiveDensities& densities);
3640  static GoogleString ToString(const protobuf::MessageLite& proto);
3641  static GoogleString ToString(const AllowVaryOn& allow_vary_on);
3642 
3645  static bool PropertyLessThanByOptionName(PropertyBase* p1, PropertyBase* p2) {
3646  return StringCaseCompare(p1->option_name(), p2->option_name()) < 0;
3647  }
3648 
3650  static bool OptionNameLessThanArg(OptionBase* option, StringPiece arg) {
3651  return StringCaseCompare(option->option_name(), arg) < 0;
3652  }
3653 
3655  static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1,
3656  UrlCacheInvalidationEntry* e2) {
3657  return e1->timestamp_ms < e2->timestamp_ms;
3658  }
3659 
3661  static bool FilterEnumToIdAndNameEntryLessThanById(
3662  const FilterEnumToIdAndNameEntry* e1,
3663  const FilterEnumToIdAndNameEntry* e2) {
3664  return strcmp(e1->filter_id, e2->filter_id) < 0;
3665  }
3666 
3669  static StringPiece GetEffectiveOptionName(StringPiece name);
3670 
3674  bool CheckLevelSpecificOption(RewriteLevel rewrite_level,
3675  const Option<bool>& option) const;
3676 
3679  bool CheckBandwidthOption(const Option<bool>& option) const {
3680  return CheckLevelSpecificOption(kOptimizeForBandwidth, option);
3681  }
3682 
3685  bool CheckMobilizeFiltersOption(const Option<bool>& option) const {
3686  return CheckLevelSpecificOption(kMobilizeFilters, option);
3687  }
3688 
3695  MergeOverride ComputeMergeOverride(
3696  Filter filter,
3697  const Option<bool>& src_preserve_option,
3698  const Option<bool>& preserve_option,
3699  const RewriteOptions& src);
3700 
3702  void ApplyMergeOverride(
3703  MergeOverride merge_override,
3704  Filter filter,
3705  Option<bool>* preserve_option);
3706 
3707  bool modified_;
3708  bool frozen_;
3709  FilterSet enabled_filters_;
3710  FilterSet disabled_filters_;
3711  FilterSet forbidden_filters_;
3712 
3715  FilterIdSet distributable_filters_;
3716 
3722  Option<RewriteLevel> level_;
3723 
3726  UrlCacheInvalidationEntryVector url_cache_invalidation_entries_;
3727 
3734  CopyOnWrite<PurgeSet> purge_set_ GUARDED_BY(cache_purge_mutex_);
3735 
3736  scoped_ptr<ThreadSystem::RWLock> cache_purge_mutex_;
3737  Option<int64> css_flatten_max_bytes_;
3738  Option<bool> cache_small_images_unrewritten_;
3739  Option<bool> no_transform_optimized_images_;
3740 
3742  Option<int64> image_resolution_limit_bytes_;
3743  Option<int64> css_image_inline_max_bytes_;
3744  Option<int64> css_inline_max_bytes_;
3745  Option<int64> css_outline_min_bytes_;
3746  Option<int64> google_font_css_inline_max_bytes_;
3747 
3749  Option<bool> css_preserve_urls_;
3750  Option<bool> js_preserve_urls_;
3751  Option<bool> image_preserve_urls_;
3752 
3753  Option<int64> image_inline_max_bytes_;
3754  Option<int64> js_inline_max_bytes_;
3755  Option<int64> js_outline_min_bytes_;
3756  Option<int64> progressive_jpeg_min_bytes_;
3758  Option<int64> max_html_cache_time_ms_;
3761  Option<int64> max_html_parse_bytes_;
3763  Option<int64> min_resource_cache_time_to_rewrite_ms_;
3764  Option<int64> idle_flush_time_ms_;
3765  Option<int64> flush_buffer_limit_bytes_;
3766 
3770  Option<int64> blocking_fetch_timeout_ms_;
3771 
3774  Option<int64> image_recompress_quality_;
3775 
3777  Option<int64> image_jpeg_recompress_quality_;
3778  Option<int64> image_jpeg_recompress_quality_for_small_screens_;
3779  Option<int64> image_jpeg_quality_for_save_data_;
3780  Option<int64> image_jpeg_num_progressive_scans_;
3781  Option<int64> image_jpeg_num_progressive_scans_for_small_screens_;
3782 
3784  Option<int> image_limit_optimized_percent_;
3785  Option<int> image_limit_resize_area_percent_;
3786  Option<int> image_limit_rendered_area_percent_;
3787 
3789  Option<int64> image_webp_recompress_quality_;
3790  Option<int64> image_webp_recompress_quality_for_small_screens_;
3791  Option<int64> image_webp_animated_recompress_quality_;
3792  Option<int64> image_webp_quality_for_save_data_;
3793  Option<int64> image_webp_timeout_ms_;
3794 
3795  Option<int> image_max_rewrites_at_once_;
3796  Option<int> max_url_segment_size_;
3797  Option<int> max_url_size_;
3798  Option<int> rewrite_deadline_ms_;
3802  Option<int> domain_shard_count_;
3803 
3804  Option<EnabledEnum> enabled_;
3805 
3806  Option<bool> distributable_;
3807 
3810  Option<bool> add_options_to_urls_;
3811 
3817  Option<bool> publicly_cache_mismatched_hashes_experimental_;
3818 
3820  Option<bool> in_place_rewriting_enabled_;
3822  Option<bool> in_place_wait_for_optimized_;
3825  Option<int> in_place_rewrite_deadline_ms_;
3830  Option<int> in_place_s_maxage_sec_;
3833  Option<bool> in_place_preemptive_rewrite_css_;
3835  Option<bool> in_place_preemptive_rewrite_css_images_;
3838  Option<bool> in_place_preemptive_rewrite_images_;
3841  Option<bool> in_place_preemptive_rewrite_javascript_;
3847  Option<bool> private_not_vary_for_ie_;
3848  Option<bool> combine_across_paths_;
3849  Option<bool> log_background_rewrites_;
3850  Option<bool> log_mobilization_samples_;
3851  Option<bool> log_rewrite_timing_;
3852  Option<bool> log_url_indices_;
3853  Option<bool> lowercase_html_names_;
3854  Option<bool> always_rewrite_css_;
3855  Option<bool> respect_vary_;
3856  Option<bool> respect_x_forwarded_proto_;
3857  Option<bool> flush_html_;
3860  Option<bool> serve_stale_if_fetch_error_;
3862  Option<bool> serve_xhr_access_control_headers_;
3865  Option<bool> proactively_freshen_user_facing_request_;
3868  Option<int64> serve_stale_while_revalidate_threshold_sec_;
3870  Option<bool> enable_flush_early_critical_css_;
3871 
3876  Option<bool> default_cache_html_;
3881  Option<bool> modify_caching_headers_;
3885  Option<bool> lazyload_images_after_onload_;
3888  Option<GoogleString> lazyload_images_blank_url_;
3891  Option<bool> use_blank_image_for_inline_preview_;
3895  Option<bool> inline_only_critical_images_;
3898  Option<bool> critical_images_beacon_enabled_;
3901  Option<bool> client_domain_rewrite_;
3904  Option<bool> domain_rewrite_cookies_;
3907  Option<bool> domain_rewrite_hyperlinks_;
3910  Option<bool> running_experiment_;
3913  Option<int> experiment_ga_slot_;
3916  Option<int> enroll_experiment_id_;
3917 
3920  Option<GoogleString> content_experiment_id_;
3921  Option<GoogleString> content_experiment_variant_id_;
3922 
3924  Option<bool> use_analytics_js_;
3925 
3928  Option<bool> increase_speed_tracking_;
3929 
3933  Option<bool> report_unload_time_;
3934 
3935  Option<bool> serve_rewritten_webp_urls_to_any_agent_;
3936 
3938  Option<bool> flush_more_resources_early_if_time_permits_;
3939 
3941  Option<bool> flush_more_resources_in_ie_and_firefox_;
3942 
3945  Option<int> max_prefetch_js_elements_;
3946 
3948  Option<bool> enable_defer_js_experimental_;
3949 
3951  Option<bool> disable_rewrite_on_no_transform_;
3952 
3954  Option<bool> disable_background_fetches_for_bots_;
3955 
3965  Option<bool> enable_cache_purge_;
3966 
3970  Option<bool> proactive_resource_freshening_;
3971 
3973  Option<bool> lazyload_highres_images_;
3974 
3977  Option<bool> avoid_renaming_introspective_javascript_;
3978 
3980  Option<bool> override_ie_document_mode_;
3981 
3983  Option<bool> test_instant_fetch_rewrite_deadline_;
3984 
3988  Option<bool> test_only_prioritize_critical_css_dont_apply_original_css_;
3989 
3995  Option<GoogleString> blocking_rewrite_key_;
3996 
4000  Option<int> beacon_reinstrument_time_sec_;
4001 
4004  Option<int> max_inlined_preview_images_index_;
4006  Option<int64> min_image_size_low_resolution_bytes_;
4008  Option<int64> max_image_size_low_resolution_bytes_;
4011  Option<int> rewrite_random_drop_percentage_;
4012 
4015  Option<bool> oblivious_pagespeed_urls_;
4016 
4018  Option<int64> finder_properties_cache_expiration_time_ms_;
4019 
4023  Option<int64> finder_properties_cache_refresh_time_ms_;
4026  Option<int64> experiment_cookie_duration_ms_;
4027 
4030  Option<int64> metadata_cache_staleness_threshold_ms_;
4031 
4033  Option<int64> metadata_input_errors_cache_ttl_ms_;
4034 
4037  Option<GoogleString> downstream_cache_purge_method_;
4038 
4040  Option<GoogleString> downstream_cache_purge_location_prefix_;
4041 
4044  Option<GoogleString> downstream_cache_rebeaconing_key_;
4045 
4051  Option<int64> downstream_cache_rewritten_percentage_threshold_;
4052 
4056  Option<int64> implicit_cache_ttl_ms_;
4057 
4062  Option<int64> load_from_file_cache_ttl_ms_;
4063 
4065  Option<int64> max_cacheable_response_content_length_;
4066 
4068  Option<bool> preserve_subresource_hints_;
4069 
4072  Option<bool> preserve_url_relativity_;
4073 
4074  Option<GoogleString> ga_id_;
4075 
4077  Option<bool> use_fallback_property_cache_values_;
4079  Option<bool> await_pcache_lookup_;
4081  Option<bool> enable_prioritizing_scripts_;
4083  Option<bool> rewrite_uncacheable_resources_;
4086  Option<GoogleString> distributed_rewrite_key_;
4088  Option<GoogleString> distributed_rewrite_servers_;
4093  Option<bool> distribute_fetches_;
4096  Option<int64> distributed_rewrite_timeout_ms_;
4102  Option<bool> forbid_all_disabled_filters_;
4104  Option<bool> enable_aggressive_rewriters_for_mobile_;
4105 
4111  Option<bool> reject_blacklisted_;
4112  Option<int> reject_blacklisted_status_code_;
4113 
4117  Option<bool> support_noscript_enabled_;
4118 
4121  Option<bool> enable_extended_instrumentation_;
4122 
4123  Option<bool> use_experimental_js_minifier_;
4124 
4127  Option<int64> max_combined_css_bytes_;
4128 
4131  Option<int64> max_combined_js_bytes_;
4132 
4134  Option<GoogleString> pre_connect_url_;
4137  Option<int> property_cache_http_status_stability_threshold_;
4139  Option<int> max_rewrite_info_log_size_;
4140 
4145  Option<int64> override_caching_ttl_ms_;
4146  CopyOnWrite<FastWildcardGroup> override_caching_wildcard_;
4147 
4151  Option<int64> min_cache_ttl_ms_;
4152 
4154  Option<bool> allow_logging_urls_in_log_record_;
4155 
4157  Option<bool> allow_options_to_be_set_by_cookies_;
4158 
4160  Option<GoogleString> non_cacheables_for_cache_partial_html_;
4161 
4165  Option<GoogleString> access_control_allow_origins_;
4166 
4168  Option<bool> hide_referer_using_meta_;
4169 
4174  Option<int64> max_low_res_image_size_bytes_;
4175  Option<int> max_low_res_to_full_res_image_size_percentage_;
4176 
4178  Option<GoogleString> remote_configuration_url_;
4180  Option<int64> remote_configuration_timeout_ms_;
4181 
4183  Option<int> http_cache_compression_level_;
4184 
4186  Option<GoogleString> request_option_override_;
4187 
4189  Option<GoogleString> url_signing_key_;
4190 
4192  Option<bool> accept_invalid_signatures_;
4193 
4198  Option<GoogleString> sticky_query_parameters_;
4199  Option<int64> option_cookies_duration_ms_;
4200 
4202  Option<ResponsiveDensities> responsive_image_densities_;
4203 
4208  Option<GoogleString> amp_link_pattern_;
4209 
4212  CacheFragmentOption cache_fragment_;
4213 
4216  OptionBaseVector all_options_;
4217  size_t initialized_options_;
4218 
4221  static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[
4222  kEndOfFilters];
4223 
4225  static PropertyNameMap* option_name_to_property_map_;
4226 
4228  static const PropertyBase** option_id_to_property_array_;
4229 
4236  bool options_uniqueness_checked_;
4237 
4238  bool need_to_store_experiment_data_;
4239  int experiment_id_;
4240  int experiment_percent_;
4241  std::vector<ExperimentSpec*> experiment_specs_;
4242 
4247  std::vector<NameValue*> resource_headers_;
4248 
4250  std::vector<NameValue*> custom_fetch_headers_;
4251 
4254  scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_;
4255 
4256  Option<ResourceCategorySet> inline_unauthorized_resource_types_;
4257 
4258  Option<bool> mob_always_;
4259  Option<bool> mob_iframe_;
4260  Option<bool> mob_iframe_disable_;
4261  Option<GoogleString> mob_iframe_viewport_;
4262  Option<bool> mob_nav_;
4263  Option<bool> mob_labeled_mode_;
4264  Option<GoogleString> mob_nav_classes_;
4265  Option<bool> mob_static_;
4266 
4267  Option<GoogleString> mob_beacon_url_;
4268  Option<GoogleString> mob_beacon_category_;
4269  Option<GoogleString> mob_map_location_;
4270  Option<GoogleString> mob_phone_number_;
4271  Option<int64> mob_conversion_id_;
4272  Option<GoogleString> mob_map_conversion_label_;
4273  Option<GoogleString> mob_phone_conversion_label_;
4274  Option<MobTheme> mob_theme_;
4275 
4276  Option<int64> noop_;
4277 
4279  Option<AllowVaryOn> allow_vary_on_;
4280 
4281  CopyOnWrite<JavascriptLibraryIdentification>
4282  javascript_library_identification_;
4283 
4284  CopyOnWrite<DomainLawyer> domain_lawyer_;
4285  FileLoadPolicy file_load_policy_;
4286 
4287  CopyOnWrite<FastWildcardGroup> allow_resources_;
4288  CopyOnWrite<FastWildcardGroup> allow_when_inlining_resources_;
4289  CopyOnWrite<FastWildcardGroup> retain_comments_;
4290  CopyOnWrite<FastWildcardGroup> lazyload_enabled_classes_;
4291 
4294  CopyOnWrite<FastWildcardGroup> blocking_rewrite_referer_urls_;
4295 
4298  typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap;
4299  FastWildcardGroupMap rejected_request_map_;
4300 
4301  GoogleString signature_;
4302  MD5Hasher hasher_;
4303  SHA1Signature sha1signature_;
4304 
4305  ThreadSystem* thread_system_;
4306 
4319  scoped_ptr<ThreadSystem::ThreadId> last_thread_id_;
4320 
4321 
4322 };
4323 
4324 }
4325 
4326 #endif
void set_experiment_ga_slot(int x)
x should be between 1 and 5 inclusive.
Definition: rewrite_options.h:2448
int64 CssImageInlineMaxBytes() const
Retrieve the css image inlining threshold, but return 0 if it's disabled.
void AddUrlValuedAttribute(const StringPiece &element, const StringPiece &attribute, semantic_type::Category category)
bool SupportSaveData() const
Definition: rewrite_options.h:571
EnabledEnum
Definition: rewrite_options.h:203
bool AdjustFiltersByCommaSeparatedList(const StringPiece &filters, MessageHandler *handler)
static const int64 kDefaultMaxCombinedCssBytes
Default maximum size of the combined CSS resource.
Definition: rewrite_options.h:845
static const PropertyBase * LookupOptionById(StringPiece option_id)
OptionSettingResult ParseAndSetOptionFromNameWithScope(StringPiece name, StringPiece arg, OptionScope max_scope, GoogleString *msg, MessageHandler *handler)
static void AddProperty(typename OptionClass::ValueType default_value, OptionClass RewriteOptionsSubclass::*offset, const char *id, StringPiece option_name, OptionScope scope, const char *help_text, bool safe_to_print, Properties *properties)
Adds a new Property to 'properties' (the last argument).
Definition: rewrite_options.h:3194
bool ClearSignatureForTesting()
Definition: rewrite_options.h:2978
bool IsRetainedComment(StringPiece comment) const
Definition: rewrite_options.h:2873
int64 idle_flush_time_ms() const
Definition: rewrite_options.h:1734
static bool Initialize(Properties **properties)
bool MatchesDownstreamCacheRebeaconingKey(StringPiece key) const
Definition: rewrite_options.h:2210
customized at directory level (.htaccess, <Directory>)
Definition: rewrite_options.h:628
Definition: rewrite_options.h:626
void AddUrlCacheInvalidationEntry(StringPiece url_pattern, int64 timestamp_ms, bool ignores_metadata_and_pcache)
static bool IsValidOptionName(StringPiece name)
Determine if the given option name is valid/known.
virtual GoogleString SubclassSignatureLockHeld()
Definition: rewrite_options.h:2954
static const int kDefaultMaxUrlSize
Definition: rewrite_options.h:806
static const int64 kDefaultExperimentCookieDurationMs
Definition: rewrite_options.h:838
void set_downstream_cache_purge_location_prefix(StringPiece p)
Definition: rewrite_options.h:2187
Definition: rewrite_options.h:489
Maps a filter's enum (kAddHead) to its id ("ah") and name ("Add Head").
Definition: rewrite_options.h:1060
void AddResourceHeader(const StringPiece &name, const StringPiece &value)
Definition: rewrite_options.h:689
bool OptionValue(StringPiece option_name, const char **id, bool *was_set, GoogleString *value) const
Definition: rewrite_options.h:211
static bool Terminate(Properties **properties_handle)
void AddOverrideCacheTtl(StringPiece wildcard)
Definition: rewrite_options.h:2897
int max_url_segment_size() const
Definition: rewrite_options.h:1752
bool InsertExperimentSpecInVector(ExperimentSpec *spec)
bool ImageOptimizationEnabled() const
static bool LooksLikeValidHost(const StringPiece &s)
std::pair< GoogleString, GoogleString > OptionStringPair
Definition: rewrite_options.h:682
Definition: rewrite_options.h:3164
Definition: rewrite_options.h:3073
virtual void InitializeOption(RewriteOptions *options) const
Definition: rewrite_options.h:3389
virtual void DisallowTroublesomeResources()
static const char kAcceptInvalidSignatures[]
Definition: rewrite_options.h:220
static const char kCacheFlushFilename[]
Definition: rewrite_options.h:427
static const char kNoneString[]
Strings for display.
Definition: rewrite_options.h:506
void Allow(StringPiece wildcard_pattern)
Definition: rewrite_options.h:2777
OptionClass RewriteOptionsSubclass::* OptionOffset
Definition: rewrite_options.h:3378
void DistributeFiltersByCommaSeparatedList(const StringPiece &filter_ids, MessageHandler *handler)
virtual bool trim_urls_in_css() const
Return false in a subclass if you want to disallow all URL trimming in CSS.
Definition: rewrite_options.h:2231
Option< BeaconUrl > beacon_url_
Protected option values so that derived class can modify.
Definition: rewrite_options.h:3273
void DisableAllFilters()
Set rewrite level to kPassThrough and explicitly disable all filters.
static Filter LookupFilter(const StringPiece &filter_name)
Convert the filter name to a Filter.
bool EnableFiltersByCommaSeparatedList(const StringPiece &filters, MessageHandler *handler)
static const char * FilterName(Filter filter)
ExperimentSpec * GetExperimentSpec(int id) const
bool HasValidSmallScreenQualities() const
static bool AddByNameToFilterSet(const StringPiece &option, FilterSet *set, MessageHandler *handler)
GoogleString PurgeSetString() const
Update kFirstFilter if you add something before this.
Definition: rewrite_options.h:108
static const int kDefaultExperimentSlot
Default Custom Variable slot in which to put Experiment information.
Definition: rewrite_options.h:852
Definition: rewrite_options.h:3281
void Modify()
Marks the config as modified.
virtual RewriteOptions * Clone() const
Definition: rewrite_options.h:500
int64 flush_buffer_limit_bytes() const
How much accumulated HTML will result in PSA introducing a flush.
Definition: rewrite_options.h:1742
static bool ParseBeaconUrl(const StringPiece &in, BeaconUrl *out)
static bool ParseAlternateOriginDomain(const StringPiece &in, AlternateOriginDomainSpec *out, MessageHandler *handler)
int64 cache_invalidation_timestamp() const
const DomainLawyer * domain_lawyer() const
Definition: rewrite_options.h:2840
Definition: rewrite_options.h:470
Definition: rewrite_options.h:503
void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock *lock)
Definition: rewrite_options.h:1696
static void MergeSubclassProperties(Properties *properties)
void set_domain_shard_count(int64 x)
Definition: rewrite_options.h:1792
int64 css_outline_min_bytes() const
Definition: rewrite_options.h:1493
void DisableFiltersRequiringScriptExecution()
Disables all filters that depend on executing custom javascript.
bool IsAllowedWhenInlining(StringPiece url) const
Definition: rewrite_options.h:2859
void set_global_default(const T &val)
Definition: rewrite_options.h:3134
static const char kImageJpegNumProgressiveScans[]
Definition: rewrite_options.h:284
bool IsUrlCacheInvalidationEntriesSorted() const
static const int64 kDefaultMetadataCacheStalenessThresholdMs
Definition: rewrite_options.h:842
virtual GoogleString ToExperimentString() const
static const int kOptionsVersion
Definition: rewrite_options.h:611
void MergeHelper(const OptionTemplateBase *src)
Definition: rewrite_options.h:3105
bool ValidateAndAddResourceHeader(const StringPiece &name, const StringPiece &value, GoogleString *error_message)
int64 ImageInlineMaxBytes() const
Retrieve the image inlining threshold, but return 0 if it's disabled.
void EnableFilter(Filter filter)
void GetEnabledFiltersRequiringScriptExecution(FilterVector *filters) const
Returns the set of enabled filters that require JavaScript for execution.
virtual void DisallowResourcesForProxy()
virtual GoogleString ToExperimentDebugString() const
void AllowOnlyWhenInlining(StringPiece wildcard_pattern)
Definition: rewrite_options.h:2798
std::vector< OptionBase * > OptionBaseVector
Convenience name for a set of rewrite options.
Definition: rewrite_options.h:714
OptionScope
Definition: rewrite_options.h:625
Definition: rewrite_options.h:483
void set_default_x_header_value(StringPiece x_header_value)
Definition: rewrite_options.h:3255
Definition: javascript_library_identification.h:34
OptionSettingResult SetOptionFromName(StringPiece name, StringPiece value, GoogleString *msg)
static const int64 kDefaultFinderPropertiesCacheExpirationTimeMs
Default cache expiration value for finder properties in pcache.
Definition: rewrite_options.h:832
bool RegisterLibrary(SizeInBytes bytes, StringPiece md5_hash, StringPiece canonical_url)
Represents the content type of user-defined url-valued attributes.
Definition: rewrite_options.h:989
Option< GoogleString > x_header_value_
The value we put for the X-Mod-Pagespeed header. Default is our version.
Definition: rewrite_options.h:3276
void set_option(const T &new_value, OptionTemplateBase< T > *option)
Definition: rewrite_options.h:3240
static bool AddCommaSeparatedListToOptionSet(const StringPiece &options, OptionSet *set, MessageHandler *handler)
bool Distributable(const StringPiece &filter_id) const
int max_url_size() const
The maximum size of the entire URL. If '0', this is left unlimited.
Definition: rewrite_options.h:1765
virtual OptionSettingResult ParseAndSetOptionFromName1(StringPiece name, StringPiece arg, GoogleString *msg, MessageHandler *handler)
Definition: rewrite_options.h:1001
static GoogleString QuoteHostPort(const GoogleString &in)
Definition: rewrite_options.h:868
void DoNotUseForSignatureComputation()
Definition: rewrite_options.h:3147
used while developing proper HTTP2 features.
Definition: rewrite_options.h:140
void ApplyAlternateOriginsToDomainLawyer(DomainLawyer *domain_lawyer, MessageHandler *handler) const
Mutate the origin domains in DomainLawyer with alternate_origin_domains_.
void AddCustomFetchHeader(const StringPiece &name, const StringPiece &value)
Specify a header to insert when fetching subresources.
virtual bool SetFromString(StringPiece value_string, GoogleString *error_detail)=0
static const int kDefaultMaxInlinedPreviewImagesIndex
Definition: rewrite_options.h:824
void DisallowWhenInlining(StringPiece wildcard_pattern)
Like Disallow(). See IsAllowedWhenInlining().
Definition: rewrite_options.h:2804
static const char kAllow[]
Options that require special handling, e.g. non-scalar values.
Definition: rewrite_options.h:398
void set_property(const Property< T > *property)
The static properties of an Option are held in a Property<T>*.
Definition: rewrite_options.h:3115
static const char kAddResourceHeader[]
2-argument ones:
Definition: rewrite_options.h:412
int64 ImageJpegQuality() const
Image qualities and parameters, after applying the inheritance rules.
static const char * FilterId(Filter filter)
Definition: file_load_policy.h:41
HttpOptions ComputeHttpOptions() const
bool RegisterLibrary(uint64 bytes, StringPiece md5_hash, StringPiece canonical_url)
Store size, md5 hash and canonical url for library recognition.
Definition: rewrite_options.h:1258
virtual ExperimentSpec * AddExperimentSpec(const StringPiece &spec, MessageHandler *handler)
const Hasher * hasher() const
Returns the hasher used for signatures and URLs to purge.
Definition: rewrite_options.h:3046
static const int64 kDefaultMaxCombinedJsBytes
Default maximum size of the combined js resource generated by JsCombiner.
Definition: rewrite_options.h:848
std::set< GoogleString > FilterIdSet
Convenience name for a set of rewrite filter ids.
Definition: rewrite_options.h:670
customized at server level (e.g. VirtualHost)
Definition: rewrite_options.h:629
bool SetOptionFromNameAndLog(StringPiece name, StringPiece value, MessageHandler *handler)
customized at process level only (command-line flags)
Definition: rewrite_options.h:630
static void CombineQuotedHostPort(StringPieceVector *vec, size_t first_pos, GoogleString *combined_container)
static const char kLibrary[]
3-argument ones:
Definition: rewrite_options.h:423
virtual void Merge(const RewriteOptions &src)
void SetDefaultRewriteLevel(RewriteLevel level)
Definition: rewrite_options.h:1124
void PurgeUrl(StringPiece url, int64 timestamp_ms)
Purge a cache entry for an exact URL, not a wildcard.
static const int64 kDefaultDistributedTimeoutMs
Default time to wait for a distributed rewrite to return.
Definition: rewrite_options.h:820
GoogleString SafeEnabledOptionsToString() const
bool IsLazyloadEnabledForClassName(StringPiece class_name) const
Checks if lazyload images is enabled for the specified class.
Definition: rewrite_options.h:2884
virtual bool SetExperimentState(int id)
void SoftEnableFilterForTesting(Filter filter)
Definition: domain_lawyer.h:47
void Merge(Properties *properties)
void AllowWhenInlining(StringPiece wildcard_pattern)
Like Allow(). See IsAllowedWhenInlining().
Definition: rewrite_options.h:2790
const OptionBaseVector & all_options() const
Definition: rewrite_options.h:3036
Filter
Definition: rewrite_options.h:107
virtual RewriteOptions * NewOptions() const
Make an empty options object of the same type as this.
OptionSettingResult SetOptionFromQuery(StringPiece name, StringPiece value)
bool IsUrlCacheValid(StringPiece url, int64 time_ms, bool search_wildcards) const
Pagespeed runs normally. Can be overridden via query param.
Definition: rewrite_options.h:208
Definition: rewrite_options.h:92
static const int kDefaultMaxUrlSegmentSize
Definition: rewrite_options.h:814
void DisableLazyloadForClassName(StringPiece class_name)
Adds a new class name for which lazyload should be disabled.
Definition: rewrite_options.h:2878
virtual void SetRequiredExperimentFilters()
Enables filters needed by Experiment regardless of experiment.
bool DisableFiltersByCommaSeparatedList(const StringPiece &filters, MessageHandler *handler)
void SetExperimentStateStr(const StringPiece &experiment_index)
Property(ValueType default_value, const char *id, StringPiece option_name)
Definition: rewrite_options.h:3342
static const int kDefaultRewriteDeadlineMs
Default time to wait for rewrite before returning original resource.
Definition: rewrite_options.h:817
bool NeedsDependenciesCohort() const
Definition: rewrite_options.h:3059
void InitializeOptions(const Properties *properties)
Definition: rewrite_options.h:91
bool IsCacheTtlOverridden(StringPiece url) const
Is the cache TTL overridden for the given url?
Definition: rewrite_options.h:2903
static const int64 kDefaultMaxImageSizeLowResolutionBytes
Definition: rewrite_options.h:830
static const StringPiece LookupOptionNameById(StringPiece option_id)
bool UpdateCachePurgeSet(const CopyOnWrite< PurgeSet > &purge_set) LOCKS_EXCLUDED(cache_purge_mutex_.get())
virtual bool SetFromString(StringPiece value_string, GoogleString *error_detail)
Sets value_ from value_string.
Definition: rewrite_options.h:3169
OptionSettingResult
Used for return value of SetOptionFromName.
Definition: rewrite_options.h:752
static const char kDistributableFilters[]
For experimentation.
Definition: rewrite_options.h:402
void DistributeFilter(const StringPiece &filter_id)
static const int64 kDefaultMinImageSizeLowResolutionBytes
Definition: rewrite_options.h:827
as above, but fail startup if included in vhost
Definition: rewrite_options.h:631
static Filter LookupFilterById(const StringPiece &filter_id)
Definition: rewrite_options.h:477
GoogleString GetExperimentStateStr() const
bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms) LOCKS_EXCLUDED(cache_purge_mutex_.get())
static const char kNullOption[]
The option name you have when you don't have an option name.
Definition: rewrite_options.h:461
Definition: rewrite_options.h:206
void ForceEnableFilter(Filter filter)
ExperimentSpec(const StringPiece &spec, const RewriteOptions *options, MessageHandler *handler)
bool SetOptionsFromName(const OptionSet &option_set, MessageHandler *handler)
Definition: rewrite_options.h:723
void Disallow(StringPiece wildcard_pattern)
Definition: rewrite_options.h:2784
OptionSettingResult SetOptionFromRemoteConfig(StringPiece name, StringPiece value)
bool IsAllowed(StringPiece url) const
Definition: rewrite_options.h:2848
const JavascriptLibraryIdentification * javascript_library_identification() const
Definition: rewrite_options.h:1266
bool ForbidFiltersByCommaSeparatedList(const StringPiece &filters, MessageHandler *handler)
Definition: rewrite_options.h:735
void UrlValuedAttribute(int index, StringPiece *element, StringPiece *attribute, semantic_type::Category *category) const
virtual void InitializeOption(RewriteOptions *options) const =0
int id() const
Accessors.
Definition: rewrite_options.h:890
void Merge(const ExperimentSpec &spec)
bool ValidateConfiguredHttpHeader(const GoogleString &name, const GoogleString &value, GoogleString *error_message)
bool AvailableExperimentId(int id)
Definition: rewrite_options.h:84
bool IsRequestDeclined(const GoogleString &url, const RequestHeaders *request_headers) const
bool IsEqual(const RewriteOptions &that) const
Definition: rewrite_options.h:170
RewriteLevel
Definition: rewrite_options.h:718
Definition: rewrite_options.h:744
const GoogleString & signature() const
Returns the computed signature.
Definition: rewrite_options.h:2985
bool UsePerOriginPropertyCachePage() const
int size() const
Returns the number of properties.
Definition: rewrite_options.h:1024
Definition: rewrite_options.h:739
void set_option_at(int index, OptionBase *option)
Definition: rewrite_options.h:3232
bool has_cache_invalidation_timestamp_ms() const
static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs
Default cache refresh value for finder properties in pcache.
Definition: rewrite_options.h:834
virtual ExperimentSpec * Clone()
Return a ExperimentSpec with all the same information as this one.
static const int kHashBytes
Number of bytes used for signature hashing.
Definition: rewrite_options.h:614
static bool ParseFromString(StringPiece value_string, bool *value)
static const int kCachePurgeBytes
Number of bytes capacity in the URL invalidation set.
Definition: rewrite_options.h:617
virtual void Merge(const OptionBase *src)
Definition: rewrite_options.h:3100
bool HasValidSaveDataQualities() const
Definition: rewrite_options.h:748
static const Filter kFirstFilter
Used for enumerating over all entries in the Filter enum.
Definition: rewrite_options.h:664
void ComputeSignature() LOCKS_EXCLUDED(cache_purge_mutex_.get())
int64 MaxImageInlineMaxBytes() const
The larger of ImageInlineMaxBytes and CssImageInlineMaxBytes.
bool css_preserve_urls() const
Definition: rewrite_options.h:2141
void RetainComment(StringPiece comment)
Adds a new comment wildcard pattern to be retained.
Definition: rewrite_options.h:2865