Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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"
48 #include "pagespeed/kernel/base/thread_annotations.h"
53 #include "pagespeed/kernel/http/user_agent_matcher.h"
55 
56 namespace net_instaweb {
57 
58 class MessageHandler;
59 class PurgeSet;
60 class RequestHeaders;
61 
62 struct HttpOptions;
63 
85  protected:
90  template<class ValueType> class Property;
91  template<class RewriteOptionsSubclass, class OptionClass> class PropertyLeaf;
92 
93  public:
106  enum Filter {
108  kAddHead,
109  kAddIds,
110  kAddInstrumentation,
111  kComputeStatistics,
112  kCachePartialHtmlDeprecated,
113  kCanonicalizeJavascriptLibraries,
114  kCollapseWhitespace,
115  kCombineCss,
116  kCombineHeads,
117  kCombineJavascript,
118  kComputeCriticalCss,
119  kComputeVisibleTextDeprecated,
120  kConvertGifToPng,
121  kConvertJpegToProgressive,
122  kConvertJpegToWebp,
123  kConvertMetaTags,
124  kConvertPngToJpeg,
125  kConvertToWebpAnimated,
126  kConvertToWebpLossless,
127  kDebug,
128  kDecodeRewrittenUrls,
129  kDedupInlinedImages,
130  kDeferIframe,
131  kDeferJavascript,
132  kDelayImages,
133  kDeterministicJs,
134  kDisableJavascript,
135  kDivStructure,
136  kElideAttributes,
137  kExperimentCollectMobImageInfo,
139  kExplicitCloseTags,
140  kExtendCacheCss,
141  kExtendCacheImages,
142  kExtendCachePdfs,
143  kExtendCacheScripts,
144  kFallbackRewriteCssUrls,
145  kFixReflows,
146  kFlattenCssImports,
147  kFlushSubresources,
148  kHandleNoscriptRedirect,
149  kHintPreloadSubresources,
150  kHtmlWriterFilter,
151  kIncludeJsSourceMaps,
152  kInlineCss,
153  kInlineGoogleFontCss,
154  kInlineImages,
155  kInlineImportToLink,
156  kInlineJavascript,
157  kInPlaceOptimizeForBrowser,
158  kInsertAmpLink,
159  kInsertDnsPrefetch,
160  kInsertGA,
161  kInsertImageDimensions,
162  kJpegSubsampling,
163  kLazyloadImages,
164  kLeftTrimUrls,
165  kLocalStorageCache,
166  kMakeGoogleAnalyticsAsync,
167  kMakeShowAdsAsync,
168  kMobilize,
170  kMoveCssAboveScripts,
171  kMoveCssToHead,
172  kOutlineCss,
173  kOutlineJavascript,
174  kPedantic,
175  kPrioritizeCriticalCss,
176  kRecompressJpeg,
177  kRecompressPng,
178  kRecompressWebp,
179  kRemoveComments,
180  kRemoveQuotes,
181  kResizeImages,
182  kResizeMobileImages,
183  kResizeToRenderedImageDimensions,
184  kResponsiveImages,
185  kResponsiveImagesZoom,
186  kRewriteCss,
187  kRewriteDomains,
188  kRewriteJavascriptExternal,
189  kRewriteJavascriptInline,
190  kRewriteStyleAttributes,
191  kRewriteStyleAttributesWithUrl,
192  kServeDeprecationNotice,
193  kSplitHtml,
194  kSplitHtmlHelper,
195  kSpriteImages,
196  kStripImageColorProfile,
197  kStripImageMetaData,
198  kStripScripts,
199  kEndOfFilters
200  };
201 
226  enum EnabledEnum {
239  };
240 
247  static const char kAcceptInvalidSignatures[];
248  static const char kAccessControlAllowOrigins[];
249  static const char kAddOptionsToUrls[];
250  static const char kAllowLoggingUrlsInLogRecord[];
251  static const char kAllowOptionsToBeSetByCookies[];
252  static const char kAllowVaryOn[];
253  static const char kAlwaysRewriteCss[];
254  static const char kAmpLinkPattern[];
255  static const char kAnalyticsID[];
256  static const char kAvoidRenamingIntrospectiveJavascript[];
257  static const char kAwaitPcacheLookup[];
258  static const char kBeaconReinstrumentTimeSec[];
259  static const char kBeaconUrl[];
260  static const char kCacheFragment[];
261  static const char kCacheSmallImagesUnrewritten[];
262  static const char kClientDomainRewrite[];
263  static const char kCombineAcrossPaths[];
264  static const char kContentExperimentID[];
265  static const char kContentExperimentVariantID[];
266  static const char kCriticalImagesBeaconEnabled[];
267  static const char kCssFlattenMaxBytes[];
268  static const char kCssImageInlineMaxBytes[];
269  static const char kCssInlineMaxBytes[];
270  static const char kCssOutlineMinBytes[];
271  static const char kCssPreserveURLs[];
272  static const char kDefaultCacheHtml[];
273  static const char kDisableBackgroundFetchesForBots[];
274  static const char kDisableRewriteOnNoTransform[];
275  static const char kDomainRewriteCookies[];
276  static const char kDomainRewriteHyperlinks[];
277  static const char kDomainShardCount[];
278  static const char kDownstreamCachePurgeMethod[];
279  static const char kDownstreamCacheRebeaconingKey[];
280  static const char kDownstreamCacheRewrittenPercentageThreshold[];
281  static const char kEnableAggressiveRewritersForMobile[];
282  static const char kEnableCachePurge[];
283  static const char kEnableDeferJsExperimental[];
284  static const char kEnableExtendedInstrumentation[];
285  static const char kEnableLazyLoadHighResImages[];
286  static const char kEnablePrioritizingScripts[];
287  static const char kEnabled[];
288  static const char kEnrollExperiment[];
289  static const char kExperimentCookieDurationMs[];
290  static const char kExperimentSlot[];
291  static const char kFetcherTimeOutMs[];
292  static const char kFinderPropertiesCacheExpirationTimeMs[];
293  static const char kFinderPropertiesCacheRefreshTimeMs[];
294  static const char kFlushBufferLimitBytes[];
295  static const char kFlushHtml[];
296  static const char kFollowFlushes[];
297  static const char kGoogleFontCssInlineMaxBytes[];
298  static const char kForbidAllDisabledFilters[];
299  static const char kHideRefererUsingMeta[];
300  static const char kHttpCacheCompressionLevel[];
301  static const char kHonorCsp[];
302  static const char kIdleFlushTimeMs[];
303  static const char kImageInlineMaxBytes[];
306  static const char kImageJpegNumProgressiveScans[];
307  static const char kImageJpegNumProgressiveScansForSmallScreens[];
308  static const char kImageJpegQualityForSaveData[];
309  static const char kImageJpegRecompressionQuality[];
310  static const char kImageJpegRecompressionQualityForSmallScreens[];
311  static const char kImageLimitOptimizedPercent[];
312  static const char kImageLimitRenderedAreaPercent[];
313  static const char kImageLimitResizeAreaPercent[];
314  static const char kImageMaxRewritesAtOnce[];
315  static const char kImagePreserveURLs[];
316  static const char kImageRecompressionQuality[];
317  static const char kImageResolutionLimitBytes[];
318  static const char kImageWebpQualityForSaveData[];
319  static const char kImageWebpRecompressionQuality[];
320  static const char kImageWebpRecompressionQualityForSmallScreens[];
321  static const char kImageWebpAnimatedRecompressionQuality[];
322  static const char kImageWebpTimeoutMs[];
323  static const char kImplicitCacheTtlMs[];
324  static const char kIncreaseSpeedTracking[];
325  static const char kInlineOnlyCriticalImages[];
326  static const char kInPlacePreemptiveRewriteCss[];
327  static const char kInPlacePreemptiveRewriteCssImages[];
328  static const char kInPlacePreemptiveRewriteImages[];
329  static const char kInPlacePreemptiveRewriteJavascript[];
330  static const char kInPlaceResourceOptimization[];
331  static const char kInPlaceRewriteDeadlineMs[];
332  static const char kInPlaceSMaxAgeSec[];
333  static const char kInPlaceWaitForOptimized[];
334  static const char kJsInlineMaxBytes[];
335  static const char kJsOutlineMinBytes[];
336  static const char kJsPreserveURLs[];
337  static const char kLazyloadImagesAfterOnload[];
338  static const char kLazyloadImagesBlankUrl[];
339  static const char kLoadFromFileCacheTtlMs[];
340  static const char kLogBackgroundRewrite[];
341  static const char kLogMobilizationSamples[];
342  static const char kLogRewriteTiming[];
343  static const char kLogUrlIndices[];
344  static const char kLowercaseHtmlNames[];
345  static const char kMaxCacheableResponseContentLength[];
346  static const char kMaxCombinedCssBytes[];
347  static const char kMaxCombinedJsBytes[];
348  static const char kMaxHtmlCacheTimeMs[];
349  static const char kMaxHtmlParseBytes[];
350  static const char kMaxImageSizeLowResolutionBytes[];
351  static const char kMaxInlinedPreviewImagesIndex[];
352  static const char kMaxLowResImageSizeBytes[];
353  static const char kMaxLowResToHighResImageSizePercentage[];
354  static const char kMaxRewriteInfoLogSize[];
355  static const char kMaxUrlSegmentSize[];
356  static const char kMaxUrlSize[];
357  static const char kMetadataCacheStalenessThresholdMs[];
358  static const char kMinImageSizeLowResolutionBytes[];
359  static const char kMinResourceCacheTimeToRewriteMs[];
360  static const char kModifyCachingHeaders[];
361  static const char kNoop[];
362  static const char kNoTransformOptimizedImages[];
363  static const char kNonCacheablesForCachePartialHtml[];
364  static const char kObliviousPagespeedUrls[];
365  static const char kOptionCookiesDurationMs[];
366  static const char kOverrideCachingTtlMs[];
367  static const char kPreserveSubresourceHints[];
368  static const char kPreserveUrlRelativity[];
369  static const char kPrivateNotVaryForIE[];
370  static const char kProactiveResourceFreshening[];
371  static const char kProactivelyFreshenUserFacingRequest[];
372  static const char kProgressiveJpegMinBytes[];
373  static const char kPubliclyCacheMismatchedHashesExperimental[];
374  static const char kRejectBlacklistedStatusCode[];
375  static const char kRejectBlacklisted[];
376  static const char kRemoteConfigurationTimeoutMs[];
377  static const char kRemoteConfigurationUrl[];
378  static const char kReportUnloadTime[];
379  static const char kRequestOptionOverride[];
380  static const char kRespectVary[];
381  static const char kRespectXForwardedProto[];
382  static const char kResponsiveImageDensities[];
383  static const char kRewriteDeadlineMs[];
384  static const char kRewriteLevel[];
385  static const char kRewriteRandomDropPercentage[];
386  static const char kRewriteUncacheableResources[];
387  static const char kRunningExperiment[];
388  static const char kServeStaleIfFetchError[];
389  static const char kServeStaleWhileRevalidateThresholdSec[];
390  static const char kServeXhrAccessControlHeaders[];
391  static const char kStickyQueryParameters[];
392  static const char kSupportNoScriptEnabled[];
393  static const char kTestOnlyPrioritizeCriticalCssDontApplyOriginalCss[];
394  static const char kUrlSigningKey[];
395  static const char kUseAnalyticsJs[];
396  static const char kUseBlankImageForInlinePreview[];
397  static const char kUseExperimentalJsMinifier[];
398  static const char kUseFallbackPropertyCacheValues[];
399  static const char kUseImageScanlineApi[];
400  static const char kXModPagespeedHeaderValue[];
401  static const char kXPsaBlockingRewrite[];
403  static const char kAllow[];
404  static const char kBlockingRewriteRefererUrls[];
405  static const char kDisableFilters[];
406  static const char kDisallow[];
407  static const char kDomain[];
408  static const char kDownstreamCachePurgeLocationPrefix[];
409  static const char kEnableFilters[];
410  static const char kExperimentVariable[];
411  static const char kExperimentSpec[];
412  static const char kForbidFilters[];
413  static const char kInlineResourcesWithoutExplicitAuthorization[];
414  static const char kRetainComment[];
415  static const char kPermitIdsForCssCombining[];
417  static const char kAddResourceHeader[];
418  static const char kCustomFetchHeader[];
419  static const char kLoadFromFile[];
420  static const char kLoadFromFileMatch[];
421  static const char kLoadFromFileRule[];
422  static const char kLoadFromFileRuleMatch[];
423  static const char kMapOriginDomain[];
424  static const char kMapProxyDomain[];
425  static const char kMapRewriteDomain[];
426  static const char kShardDomain[];
428  static const char kLibrary[];
429  static const char kUrlValuedAttribute[];
432  static const char kCacheFlushFilename[];
433  static const char kCacheFlushPollIntervalSec[];
434  static const char kCompressMetadataCache[];
435  static const char kFetcherProxy[];
436  static const char kFetchHttps[];
437  static const char kFileCacheCleanInodeLimit[];
438  static const char kFileCacheCleanIntervalMs[];
439  static const char kFileCacheCleanSizeKb[];
440  static const char kFileCachePath[];
441  static const char kLogDir[];
442  static const char kLruCacheByteLimit[];
443  static const char kLruCacheKbPerProcess[];
444  static const char kMemcachedServers[];
445  static const char kMemcachedThreads[];
446  static const char kMemcachedTimeoutUs[];
447  static const char kProxySuffix[];
448  static const char kRateLimitBackgroundFetches[];
449  static const char kServeWebpToAnyAgent[];
450  static const char kSlurpDirectory[];
451  static const char kSlurpFlushLimit[];
452  static const char kSlurpReadOnly[];
453  static const char kSslCertDirectory[];
454  static const char kSslCertFile[];
455  static const char kStatisticsEnabled[];
456  static const char kStatisticsLoggingChartsCSS[];
457  static const char kStatisticsLoggingChartsJS[];
458  static const char kStatisticsLoggingEnabled[];
459  static const char kStatisticsLoggingIntervalMs[];
460  static const char kStatisticsLoggingMaxFileSizeKb[];
461  static const char kTestProxy[];
462  static const char kTestProxySlurp[];
463  static const char kUseSharedMemLocking[];
465  static const char kNullOption[];
466 
474  struct BeaconUrl {
475  GoogleString http;
476  GoogleString https;
477  GoogleString http_in;
478  GoogleString https_in;
479  };
480 
481  struct Color {
482  unsigned char r;
483  unsigned char g;
484  unsigned char b;
485  };
486 
487  struct MobTheme {
488  Color background_color;
489  Color foreground_color;
490  GoogleString logo_url;
491  };
492 
493  struct NameValue {
494  NameValue(StringPiece name_in, StringPiece value_in) {
495  name_in.CopyToString(&name);
496  value_in.CopyToString(&value);
497  }
498  GoogleString name;
499  GoogleString value;
500  };
501 
504  class ResponsiveDensities : public std::vector<double> {
505  };
506 
507  class AllowVaryOn {
508  public:
510  static const char kNoneString[];
511  static const char kAutoString[];
512 
513  AllowVaryOn() :
514  allow_auto_(false),
515  allow_accept_(false),
516  allow_save_data_(false),
517  allow_user_agent_(false) {
518  }
519 
520  GoogleString ToString() const;
521 
522  bool allow_auto() const {
523  return allow_auto_;
524  }
525  void set_allow_auto(bool v) {
526  allow_auto_ = v;
527  }
528  bool allow_accept() const {
529  return allow_accept_;
530  }
531  void set_allow_accept(bool v) {
532  allow_accept_ = v;
533  }
534  bool allow_save_data() const {
535  return allow_save_data_ || allow_auto_;
536  }
537  void set_allow_save_data(bool v) {
538  allow_save_data_ = v;
539  }
540  bool allow_user_agent() const {
541  return allow_user_agent_;
542  }
543  void set_allow_user_agent(bool v) {
544  allow_user_agent_ = v;
545  }
546 
547  private:
550  bool allow_auto_;
551  bool allow_accept_;
552  bool allow_save_data_;
553  bool allow_user_agent_;
554  };
555 
556  bool AllowVaryOnAuto() const {
557  return allow_vary_on_.value().allow_auto();
558  }
559  bool AllowVaryOnAccept() const {
560  return allow_vary_on_.value().allow_accept();
561  }
562  bool AllowVaryOnSaveData() const {
563  return allow_vary_on_.value().allow_save_data();
564  }
565  bool AllowVaryOnUserAgent() const {
566  return allow_vary_on_.value().allow_user_agent();
567  }
568  GoogleString AllowVaryOnToString() const {
569  return ToString(allow_vary_on_.value());
570  }
571 
575  bool SupportSaveData() const {
576  return (HasValidSaveDataQualities() && AllowVaryOnSaveData());
577  }
578 
579  void set_allow_vary_on(const AllowVaryOn& x) {
580  set_option(x, &allow_vary_on_);
581  }
582 
584  int64 ImageJpegQuality() const;
585  int64 ImageJpegQualityForSmallScreen() const;
586  int64 ImageJpegQualityForSaveData() const;
587  int64 ImageWebpQuality() const;
588  int64 ImageWebpQualityForSmallScreen() const;
589  int64 ImageWebpQualityForSaveData() const;
590  int64 ImageWebpAnimatedQuality() const;
591  int64 ImageJpegNumProgressiveScansForSmallScreen() const;
594  bool HasValidSmallScreenQualities() const;
597  bool HasValidSaveDataQualities() const;
598 
615  static const int kOptionsVersion = 14;
616 
618  static const int kHashBytes = 20;
619 
621  static const int kCachePurgeBytes = 25000;
622 
629  enum OptionScope {
638 
641  };
642 
643  static const char kCacheExtenderId[];
644  static const char kCssCombinerId[];
645  static const char kCssFilterId[];
646  static const char kCssImportFlattenerId[];
647  static const char kCssInlineId[];
648  static const char kGoogleFontCssInlineId[];
649  static const char kImageCombineId[];
650  static const char kImageCompressionId[];
651  static const char kInPlaceRewriteId[];
652  static const char kJavascriptCombinerId[];
653  static const char kJavascriptInlineId[];
654  static const char kJavascriptMinId[];
655  static const char kJavascriptMinSourceMapId[];
656  static const char kLocalStorageCacheId[];
657  static const char kPrioritizeCriticalCssId[];
658 
661  static const char* FilterName(Filter filter);
662 
665  static const char* FilterId(Filter filter);
666 
669  static int NumFilterIds();
670 
673 
675  typedef std::vector<Filter> FilterVector;
676 
678  typedef std::set<GoogleString> FilterIdSet;
679 
685  static bool AddByNameToFilterSet(const StringPiece& option, FilterSet* set,
686  MessageHandler* handler);
687 
690  typedef std::pair<GoogleString, GoogleString> OptionStringPair;
691  typedef std::set<OptionStringPair> OptionSet;
692 
695  class PropertyBase {
696  public:
697  PropertyBase(const char* id, StringPiece option_name)
698  : id_(id),
699  help_text_(nullptr),
700  option_name_(option_name),
701  scope_(kDirectoryScope),
702  do_not_use_for_signature_computation_(false),
703  index_(-1) {
704  }
705  virtual ~PropertyBase();
706 
709  virtual void InitializeOption(RewriteOptions* options) const = 0;
710 
711  void set_do_not_use_for_signature_computation(bool x) {
712  do_not_use_for_signature_computation_ = x;
713  }
714  bool is_used_for_signature_computation() const {
715  return !do_not_use_for_signature_computation_;
716  }
717 
718  void set_scope(OptionScope x) { scope_ = x; }
719  OptionScope scope() const { return scope_; }
720 
721  void set_help_text(const char* x) { help_text_ = x; }
722  const char* help_text() const { return help_text_; }
723 
724  void set_index(int index) { index_ = index; }
725  const char* id() const { return id_; }
726  StringPiece option_name() const { return option_name_; }
727  int index() const { return index_; }
728 
729  bool safe_to_print() const { return safe_to_print_; }
730  void set_safe_to_print(bool safe_to_print) {
731  safe_to_print_ = safe_to_print;
732  }
733 
734  private:
735  const char* id_;
736  const char* help_text_;
737  StringPiece option_name_;
738  OptionScope scope_;
739  bool do_not_use_for_signature_computation_;
740  bool safe_to_print_;
741  int index_;
742 
743 
744  };
745 
746  typedef std::vector<PropertyBase*> PropertyVector;
747 
750  class OptionBase {
751  public:
752  OptionBase() {}
753  virtual ~OptionBase();
754 
758  virtual bool SetFromString(StringPiece value_string,
759  GoogleString* error_detail) = 0;
760  virtual void Merge(const OptionBase* src) = 0;
761  virtual bool was_set() const = 0;
762  virtual GoogleString Signature(const Hasher* hasher) const = 0;
763  virtual GoogleString ToString() const = 0;
764  const char* id() const { return property()->id(); }
765  const char* help_text() const { return property()->help_text(); }
766  OptionScope scope() const { return property()->scope(); }
767  StringPiece option_name() const { return property()->option_name(); }
768  bool is_used_for_signature_computation() const {
769  return property()->is_used_for_signature_computation();
770  }
771  virtual const PropertyBase* property() const = 0;
772  };
773 
775  typedef std::vector<OptionBase*> OptionBaseVector;
776 
785 
790 
797 
801 
806 
810  };
811 
814  kOptionOk,
815  kOptionNameUnknown,
816  kOptionValueInvalid
817  };
818 
819  static const char kDefaultAllowVaryOn[];
820  static const int kDefaultBeaconReinstrumentTimeSec;
821  static const int64 kDefaultCssFlattenMaxBytes;
822  static const int64 kDefaultCssImageInlineMaxBytes;
823  static const int64 kDefaultCssInlineMaxBytes;
824  static const int64 kDefaultCssOutlineMinBytes;
825  static const int64 kDefaultGoogleFontCssInlineMaxBytes;
826  static const int64 kDefaultImageInlineMaxBytes;
827  static const int64 kDefaultJsInlineMaxBytes;
828  static const int64 kDefaultJsOutlineMinBytes;
829  static const int64 kDefaultProgressiveJpegMinBytes;
830  static const int64 kDefaultMaxCacheableResponseContentLength;
831  static const int64 kDefaultMaxHtmlCacheTimeMs;
832  static const int64 kDefaultMaxHtmlParseBytes;
833  static const int64 kDefaultMaxLowResImageSizeBytes;
834  static const int kDefaultMaxLowResToFullResImageSizePercentage;
835  static const int64 kDefaultMetadataInputErrorsCacheTtlMs;
836  static const int64 kDefaultMinResourceCacheTimeToRewriteMs;
837  static const char kDefaultDownstreamCachePurgeMethod[];
838  static const int64 kDefaultDownstreamCacheRewrittenPercentageThreshold;
839  static const int64 kDefaultIdleFlushTimeMs;
840  static const int64 kDefaultFlushBufferLimitBytes;
841  static const int64 kDefaultImplicitCacheTtlMs;
842  static const int64 kDefaultPrioritizeVisibleContentCacheTimeMs;
843  static const char kDefaultBeaconUrl[];
844  static const int64 kDefaultImageRecompressQuality;
845  static const int64 kDefaultImageJpegQualityForSaveData;
846  static const int64 kDefaultImageJpegRecompressQuality;
847  static const int64 kDefaultImageJpegRecompressQualityForSmallScreens;
848  static const int kDefaultImageLimitOptimizedPercent;
849  static const int kDefaultImageLimitRenderedAreaPercent;
850  static const int kDefaultImageLimitResizeAreaPercent;
851  static const int64 kDefaultImageResolutionLimitBytes;
852  static const int64 kDefaultImageJpegNumProgressiveScans;
853  static const int64 kDefaultImageWebpQualityForSaveData;
854  static const int64 kDefaultImageWebpRecompressQuality;
855  static const int64 kDefaultImageWebpAnimatedRecompressQuality;
856  static const int64 kDefaultImageWebpRecompressQualityForSmallScreens;
857  static const int64 kDefaultImageWebpTimeoutMs;
858  static const int kDefaultDomainShardCount;
859  static const int64 kDefaultOptionCookiesDurationMs;
860  static const int64 kDefaultLoadFromFileCacheTtlMs;
861  static const double kDefaultResponsiveImageDensities[];
862 
865  static const int kDefaultMaxUrlSize;
866 
867  static const int kDefaultImageMaxRewritesAtOnce;
868 
873  static const int kDefaultMaxUrlSegmentSize;
874 
876  static const int kDefaultRewriteDeadlineMs;
877 
891 
895 
899 
901  static const int64 kDefaultMaxCombinedCssBytes;
902 
904  static const int64 kDefaultMaxCombinedJsBytes;
905 
906  static const int kDefaultExperimentTrafficPercent;
908  static const int kDefaultExperimentSlot;
909 
910  static const char kDefaultBlockingRewriteKey[];
911 
912  static const char kRejectedRequestUrlKeyName[];
913 
914  static const int kDefaultPropertyCacheHttpStatusStabilityThreshold;
915 
916  static const int kDefaultMaxRewriteInfoLogSize;
917 
925  public:
930  ExperimentSpec(const StringPiece& spec, const RewriteOptions* options,
931  MessageHandler* handler);
932 
936  explicit ExperimentSpec(int id);
937 
938  virtual ~ExperimentSpec();
939 
941  virtual ExperimentSpec* Clone();
942 
943  bool is_valid() const { return id_ >= 0; }
944 
946  int id() const { return id_; }
947  int percent() const { return percent_; }
948  const GoogleString& ga_id() const { return ga_id_; }
949  int slot() const { return ga_variable_slot_; }
950  RewriteLevel rewrite_level() const { return rewrite_level_; }
951  FilterSet enabled_filters() const { return enabled_filters_; }
952  FilterSet disabled_filters() const { return disabled_filters_; }
953  OptionSet filter_options() const { return filter_options_; }
954  bool matches_device_type(UserAgentMatcher::DeviceType type) const;
955  bool use_default() const { return use_default_; }
956  GoogleString ToString() const;
957 
960  MessageHandler* handler) const;
961 
962  protected:
967  void Merge(const ExperimentSpec& spec);
968 
969  typedef std::bitset<net_instaweb::UserAgentMatcher::kEndOfDeviceType>
970  DeviceTypeBitSet;
971 
972  static bool ParseDeviceTypeBitSet(const StringPiece& in,
973  DeviceTypeBitSet* out,
974  MessageHandler* handler);
975 
977  StringVector serving_domains;
978  GoogleString origin_domain;
979  GoogleString host_header;
980  };
981 
984  static bool LooksLikeValidHost(const StringPiece& s);
985 
989  static bool ParseAlternateOriginDomain(const StringPiece& in,
991  MessageHandler* handler);
992 
1000  static void CombineQuotedHostPort(StringPieceVector* vec, size_t first_pos,
1001  GoogleString* combined_container);
1002 
1006  static GoogleString QuoteHostPort(const GoogleString& in);
1007 
1008  private:
1009  FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
1010  FRIEND_TEST(RewriteOptionsTest, DeviceTypeMergeTest);
1011  FRIEND_TEST(RewriteOptionsTest, AlternateOriginDomainMergeTest);
1012 
1015  void Initialize(const StringPiece& spec, MessageHandler* handler);
1016 
1021  int id_;
1022  GoogleString ga_id_;
1023  int ga_variable_slot_;
1024  int percent_;
1025  RewriteLevel rewrite_level_;
1026  FilterSet enabled_filters_;
1027  FilterSet disabled_filters_;
1028  OptionSet filter_options_;
1032  scoped_ptr<DeviceTypeBitSet> matches_device_types_;
1035  bool use_default_;
1038  typedef std::vector<AlternateOriginDomainSpec> AlternateOriginDomains;
1039  AlternateOriginDomains alternate_origin_domains_;
1040 
1041 
1042  };
1043 
1046  GoogleString element;
1047  GoogleString attribute;
1048  semantic_type::Category category;
1049  };
1050 
1057  class Properties {
1058  public:
1067  static bool Initialize(Properties** properties);
1068 
1077  static bool Terminate(Properties** properties_handle);
1078 
1080  int size() const { return property_vector_.size(); }
1081 
1082  const PropertyBase* property(int index) const {
1083  return property_vector_[index];
1084  }
1085  PropertyBase* property(int index) { return property_vector_[index]; }
1086 
1092  void Merge(Properties* properties);
1093 
1094  void push_back(PropertyBase* p) { property_vector_.push_back(p); }
1095 
1096  private:
1099  Properties();
1100  ~Properties();
1101 
1105  int initialization_count_;
1106 
1111  bool owns_properties_;
1112  PropertyVector property_vector_;
1113  };
1114 
1117  RewriteOptions::Filter filter_enum;
1118  const char* filter_id;
1119  const char* filter_name;
1120  };
1121 
1122  static bool ParseRewriteLevel(const StringPiece& in, RewriteLevel* out);
1123 
1124  typedef std::set<semantic_type::Category> ResourceCategorySet;
1125 
1126  static bool ParseInlineUnauthorizedResourceType(
1127  const StringPiece& in,
1128  ResourceCategorySet* resource_types);
1129 
1133  static bool ParseBeaconUrl(const StringPiece& in, BeaconUrl* out);
1134 
1138  bool ImageOptimizationEnabled() const;
1139 
1140  explicit RewriteOptions(ThreadSystem* thread_system);
1141  virtual ~RewriteOptions();
1142 
1146  static bool Initialize();
1147  static bool Terminate();
1148 
1149 #ifndef NDEBUG
1150  bool ModificationOK() const;
1157 
1164  bool MergeOK() const;
1165 #endif
1166 
1171  void InitializeOptions(const Properties* properties);
1172 
1173  bool modified() const { return modified_; }
1174 
1182  level_.set_default(level);
1183  }
1184  void SetRewriteLevel(RewriteLevel level) {
1185  set_option(level, &level_);
1186  }
1187 
1191  bool ValidateConfiguredHttpHeader(const GoogleString& name,
1192  const GoogleString& value,
1193  GoogleString* error_message);
1194 
1200  bool ValidateAndAddResourceHeader(const StringPiece& name,
1201  const StringPiece& value,
1202  GoogleString* error_message);
1203 
1206  void AddResourceHeader(const StringPiece& name, const StringPiece& value);
1207 
1208  const NameValue* resource_header(int i) const {
1209  return resource_headers_[i];
1210  }
1211 
1212  int num_resource_headers() const {
1213  return resource_headers_.size();
1214  }
1215 
1217  void AddCustomFetchHeader(const StringPiece& name, const StringPiece& value);
1218 
1219  const NameValue* custom_fetch_header(int i) const {
1220  return custom_fetch_headers_[i];
1221  }
1222 
1223  int num_custom_fetch_headers() const {
1224  return custom_fetch_headers_.size();
1225  }
1226 
1229  ExperimentSpec* GetExperimentSpec(int id) const;
1230 
1234  bool AvailableExperimentId(int id);
1235 
1238  virtual ExperimentSpec* AddExperimentSpec(const StringPiece& spec,
1239  MessageHandler* handler);
1240 
1248  virtual bool SetExperimentState(int id);
1249 
1253  void SetExperimentStateStr(const StringPiece& experiment_index);
1254 
1255  int experiment_id() const { return experiment_id_; }
1256 
1257  int experiment_spec_id(int i) const {
1258  return experiment_specs_[i]->id();
1259  }
1260 
1266 
1267  ExperimentSpec* experiment_spec(int i) const {
1268  return experiment_specs_[i];
1269  }
1270 
1271  int num_experiments() const { return experiment_specs_.size(); }
1272 
1273  bool enroll_experiment() const {
1274  return enroll_experiment_id() != experiment::kForceNoExperiment;
1275  }
1276 
1288  void AddUrlValuedAttribute(const StringPiece& element,
1289  const StringPiece& attribute,
1290  semantic_type::Category category);
1291 
1294  void UrlValuedAttribute(int index,
1295  StringPiece* element,
1296  StringPiece* attribute,
1297  semantic_type::Category* category) const;
1298 
1299  int num_url_valued_attributes() const {
1300  if (url_valued_attributes_ == NULL) {
1301  return 0;
1302  } else {
1303  return url_valued_attributes_->size();
1304  }
1305  }
1306 
1307  void AddInlineUnauthorizedResourceType(semantic_type::Category category);
1308  bool HasInlineUnauthorizedResourceType(
1309  semantic_type::Category category) const;
1310  void ClearInlineUnauthorizedResourceTypes();
1311  void set_inline_unauthorized_resource_types(ResourceCategorySet x);
1312 
1315  uint64 bytes, StringPiece md5_hash, StringPiece canonical_url) {
1316  return WriteableJavascriptLibraryIdentification()->RegisterLibrary(
1317  bytes, md5_hash, canonical_url);
1318  }
1319 
1323  const {
1324  if (Enabled(kCanonicalizeJavascriptLibraries)) {
1325  return javascript_library_identification_.get();
1326  } else {
1327  return NULL;
1328  }
1329  }
1330 
1331  RewriteLevel level() const { return level_.value(); }
1332 
1337  bool AdjustFiltersByCommaSeparatedList(const StringPiece& filters,
1338  MessageHandler* handler);
1339 
1343  bool EnableFiltersByCommaSeparatedList(const StringPiece& filters,
1344  MessageHandler* handler);
1345 
1349  bool DisableFiltersByCommaSeparatedList(const StringPiece& filters,
1350  MessageHandler* handler);
1351 
1355  bool ForbidFiltersByCommaSeparatedList(const StringPiece& filters,
1356  MessageHandler* handler);
1357 
1359  void DisableAllFilters();
1360 
1369 
1373  void EnableFilter(Filter filter);
1376  void ForceEnableFilter(Filter filter);
1377  void DisableFilter(Filter filter);
1378  void DisableIfNotExplictlyEnabled(Filter filter);
1379  void ForbidFilter(Filter filter);
1380  void EnableFilters(const FilterSet& filter_set);
1381  void DisableFilters(const FilterSet& filter_set);
1382  void ForbidFilters(const FilterSet& filter_set);
1385  void ClearFilters();
1386 
1404  void SoftEnableFilterForTesting(Filter filter);
1405 
1408  void EnableExtendCacheFilters();
1409 
1410  bool Enabled(Filter filter) const;
1411  bool Forbidden(Filter filter) const;
1412  bool Forbidden(StringPiece filter_id) const;
1413 
1415  void GetEnabledFiltersRequiringScriptExecution(FilterVector* filters) const;
1416 
1419 
1422 
1425  bool RequiresAddHead() const;
1426 
1429  bool UsePerOriginPropertyCachePage() const;
1430 
1436  const StringPiece& options, OptionSet* set, MessageHandler* handler);
1437 
1443  StringPiece name, StringPiece value, GoogleString* msg);
1444 
1447  StringPiece name, StringPiece value);
1448 
1452  OptionSettingResult SetOptionFromQuery(StringPiece name, StringPiece value);
1453 
1458  StringPiece value);
1459 
1460  GoogleString ScopeEnumToString(OptionScope scope);
1461 
1470  StringPiece name, StringPiece arg,
1471  GoogleString* msg, MessageHandler* handler);
1477  StringPiece name, StringPiece arg, OptionScope max_scope,
1478  GoogleString* msg, MessageHandler* handler);
1479 
1480  virtual OptionSettingResult ParseAndSetOptionFromName2(
1481  StringPiece name, StringPiece arg1, StringPiece arg2,
1482  GoogleString* msg, MessageHandler* handler);
1483 
1484  virtual OptionSettingResult ParseAndSetOptionFromName3(
1485  StringPiece name, StringPiece arg1, StringPiece arg2, StringPiece arg3,
1486  GoogleString* msg, MessageHandler* handler);
1487 
1493  bool OptionValue(StringPiece option_name, const char** id,
1494  bool* was_set, GoogleString* value) const;
1495 
1498  bool SetOptionsFromName(const OptionSet& option_set, MessageHandler* handler);
1499 
1502  bool SetOptionFromNameAndLog(StringPiece name,
1503  StringPiece value,
1504  MessageHandler* handler);
1505 
1508  static bool ParseFromString(StringPiece value_string, bool* value);
1509  static bool ParseFromString(StringPiece value_string, EnabledEnum* value);
1510  static bool ParseFromString(StringPiece value_string, int* value) {
1511  return StringToInt(value_string, value);
1512  }
1513  static bool ParseFromString(StringPiece value_string, int64* value) {
1514  return StringToInt64(value_string, value);
1515  }
1516  static bool ParseFromString(StringPiece value_string, double* value) {
1517  return StringToDouble(value_string, value);
1518  }
1519  static bool ParseFromString(StringPiece value_string, GoogleString* value) {
1520  value_string.CopyToString(value);
1521  return true;
1522  }
1523  static bool ParseFromString(StringPiece value_string, RewriteLevel* value) {
1524  return ParseRewriteLevel(value_string, value);
1525  }
1526  static bool ParseFromString(StringPiece value_string,
1527  ResourceCategorySet* value) {
1528  return ParseInlineUnauthorizedResourceType(value_string, value);
1529  }
1530  static bool ParseFromString(StringPiece value_string, BeaconUrl* value) {
1531  return ParseBeaconUrl(value_string, value);
1532  }
1533  static bool ParseFromString(StringPiece value_string, Color* color);
1534  static bool ParseFromString(StringPiece value_string, MobTheme* theme);
1535  static bool ParseFromString(StringPiece value_string,
1536  ResponsiveDensities* value);
1537  static bool ParseFromString(StringPiece value_string,
1538  protobuf::MessageLite* proto);
1539  static bool ParseFromString(StringPiece value_string,
1540  AllowVaryOn* allow_vary_on);
1541 
1544  int64 css_outline_min_bytes() const { return css_outline_min_bytes_.value(); }
1545  void set_css_outline_min_bytes(int64 x) {
1546  set_option(x, &css_outline_min_bytes_);
1547  }
1548 
1549  const GoogleString& ga_id() const { return ga_id_.value(); }
1550  void set_ga_id(const GoogleString& id) {
1551  set_option(id, &ga_id_);
1552  }
1553 
1554  void set_content_experiment_id(const GoogleString& s) {
1555  set_option(s, &content_experiment_id_);
1556  }
1557  const GoogleString& content_experiment_id() const {
1558  return content_experiment_id_.value();
1559  }
1560 
1561  void set_content_experiment_variant_id(const GoogleString& s) {
1562  set_option(s, &content_experiment_variant_id_);
1563  }
1564  const GoogleString& content_experiment_variant_id() const {
1565  return content_experiment_variant_id_.value();
1566  }
1567 
1568  bool is_content_experiment() const {
1569  return !content_experiment_id().empty() &&
1570  !content_experiment_variant_id().empty();
1571  }
1572 
1573  bool use_analytics_js() const {
1574  return use_analytics_js_.value();
1575  }
1576  void set_use_analytics_js(bool x) {
1577  set_option(x, &use_analytics_js_);
1578  }
1579 
1580  bool increase_speed_tracking() const {
1581  return increase_speed_tracking_.value();
1582  }
1583  void set_increase_speed_tracking(bool x) {
1584  set_option(x, &increase_speed_tracking_);
1585  }
1586 
1587  int64 js_outline_min_bytes() const { return js_outline_min_bytes_.value(); }
1588  void set_js_outline_min_bytes(int64 x) {
1589  set_option(x, &js_outline_min_bytes_);
1590  }
1591 
1592  int64 progressive_jpeg_min_bytes() const {
1593  return progressive_jpeg_min_bytes_.value();
1594  }
1595  void set_progressive_jpeg_min_bytes(int64 x) {
1596  set_option(x, &progressive_jpeg_min_bytes_);
1597  }
1598 
1599  int64 css_flatten_max_bytes() const { return css_flatten_max_bytes_.value(); }
1600  void set_css_flatten_max_bytes(int64 x) {
1601  set_option(x, &css_flatten_max_bytes_);
1602  }
1603  bool cache_small_images_unrewritten() const {
1604  return cache_small_images_unrewritten_.value();
1605  }
1606  void set_cache_small_images_unrewritten(bool x) {
1607  set_option(x, &cache_small_images_unrewritten_);
1608  }
1609  int64 image_resolution_limit_bytes() const {
1610  return image_resolution_limit_bytes_.value();
1611  }
1612  void set_image_resolution_limit_bytes(int64 x) {
1613  set_option(x, &image_resolution_limit_bytes_);
1614  }
1615 
1617  int64 ImageInlineMaxBytes() const;
1618  void set_image_inline_max_bytes(int64 x);
1620  int64 CssImageInlineMaxBytes() const;
1621  void set_css_image_inline_max_bytes(int64 x) {
1622  set_option(x, &css_image_inline_max_bytes_);
1623  }
1625  int64 MaxImageInlineMaxBytes() const;
1626  int64 css_inline_max_bytes() const { return css_inline_max_bytes_.value(); }
1627  void set_css_inline_max_bytes(int64 x) {
1628  set_option(x, &css_inline_max_bytes_);
1629  }
1630  int64 google_font_css_inline_max_bytes() const {
1631  return google_font_css_inline_max_bytes_.value();
1632  }
1633  void set_google_font_css_inline_max_bytes(int64 x) {
1634  set_option(x, &google_font_css_inline_max_bytes_);
1635  }
1636  int64 js_inline_max_bytes() const { return js_inline_max_bytes_.value(); }
1637  void set_js_inline_max_bytes(int64 x) {
1638  set_option(x, &js_inline_max_bytes_);
1639  }
1640  int64 max_html_cache_time_ms() const {
1641  return max_html_cache_time_ms_.value();
1642  }
1643  void set_max_html_cache_time_ms(int64 x) {
1644  set_option(x, &max_html_cache_time_ms_);
1645  }
1646  int64 max_html_parse_bytes() const {
1647  return max_html_parse_bytes_.value();
1648  }
1649  void set_max_html_parse_bytes(int64 x) {
1650  set_option(x, &max_html_parse_bytes_);
1651  }
1652  int64 max_cacheable_response_content_length() const {
1653  return max_cacheable_response_content_length_.value();
1654  }
1655  void set_max_cacheable_response_content_length(int64 x) {
1656  set_option(x, &max_cacheable_response_content_length_);
1657  }
1658  int64 min_resource_cache_time_to_rewrite_ms() const {
1659  return min_resource_cache_time_to_rewrite_ms_.value();
1660  }
1661  void set_min_resource_cache_time_to_rewrite_ms(int64 x) {
1662  set_option(x, &min_resource_cache_time_to_rewrite_ms_);
1663  }
1664  bool need_to_store_experiment_data() const {
1665  return need_to_store_experiment_data_;
1666  }
1667  void set_need_to_store_experiment_data(bool x) {
1668  need_to_store_experiment_data_ = x;
1669  }
1670 
1671  int64 blocking_fetch_timeout_ms() const {
1672  return blocking_fetch_timeout_ms_.value();
1673  }
1674  void set_blocking_fetch_timeout_ms(int64 x) {
1675  set_option(x, &blocking_fetch_timeout_ms_);
1676  }
1677  bool override_ie_document_mode() const {
1678  return override_ie_document_mode_.value();
1679  }
1680  void set_override_ie_document_mode(bool x) {
1681  set_option(x, &override_ie_document_mode_);
1682  }
1683 
1684  bool preserve_subresource_hints() const {
1685  return preserve_subresource_hints_.value();
1686  }
1687  void set_preserve_subresource_hints(bool x) {
1688  set_option(x, &preserve_subresource_hints_);
1689  }
1690 
1691 
1692  bool preserve_url_relativity() const {
1693  return preserve_url_relativity_.value();
1694  }
1695  void set_preserve_url_relativity(bool x) {
1696  set_option(x, &preserve_url_relativity_);
1697  }
1698 
1715  bool IsUrlCacheValid(StringPiece url, int64 time_ms,
1716  bool search_wildcards) const;
1717 
1734  void AddUrlCacheInvalidationEntry(StringPiece url_pattern,
1735  int64 timestamp_ms,
1736  bool ignores_metadata_and_pcache);
1737 
1739  void PurgeUrl(StringPiece url, int64 timestamp_ms);
1740 
1744 
1748  cache_purge_mutex_.reset(lock);
1749  }
1750 
1755  int64 cache_invalidation_timestamp() const;
1756 
1761 
1770  bool UpdateCacheInvalidationTimestampMs(int64 timestamp_ms)
1771  LOCKS_EXCLUDED(cache_purge_mutex_.get());
1772 
1776  bool UpdateCachePurgeSet(const CopyOnWrite<PurgeSet>& purge_set)
1777  LOCKS_EXCLUDED(cache_purge_mutex_.get());
1778 
1781  GoogleString PurgeSetString() const;
1782 
1785  int64 idle_flush_time_ms() const {
1786  return idle_flush_time_ms_.value();
1787  }
1788  void set_idle_flush_time_ms(int64 x) {
1789  set_option(x, &idle_flush_time_ms_);
1790  }
1791 
1794  return flush_buffer_limit_bytes_.value();
1795  }
1796 
1797  void set_flush_buffer_limit_bytes(int64 x) {
1798  set_option(x, &flush_buffer_limit_bytes_);
1799  }
1800 
1803  int max_url_segment_size() const { return max_url_segment_size_.value(); }
1804  void set_max_url_segment_size(int x) {
1805  set_option(x, &max_url_segment_size_);
1806  }
1807 
1808  int image_max_rewrites_at_once() const {
1809  return image_max_rewrites_at_once_.value();
1810  }
1811  void set_image_max_rewrites_at_once(int x) {
1812  set_option(x, &image_max_rewrites_at_once_);
1813  }
1814 
1816  int max_url_size() const { return max_url_size_.value(); }
1817  void set_max_url_size(int x) {
1818  set_option(x, &max_url_size_);
1819  }
1820 
1821  int rewrite_deadline_ms() const { return rewrite_deadline_ms_.value(); }
1822  void set_rewrite_deadline_ms(int x) {
1823  set_option(x, &rewrite_deadline_ms_);
1824  }
1825 
1826  bool test_instant_fetch_rewrite_deadline() const {
1827  return test_instant_fetch_rewrite_deadline_.value();
1828  }
1829  void set_test_instant_fetch_rewrite_deadline(bool x) {
1830  set_option(x, &test_instant_fetch_rewrite_deadline_);
1831  }
1832 
1833  void set_test_only_prioritize_critical_css_dont_apply_original_css(bool x) {
1834  set_option(x, &test_only_prioritize_critical_css_dont_apply_original_css_);
1835  }
1836  bool test_only_prioritize_critical_css_dont_apply_original_css() const {
1837  return test_only_prioritize_critical_css_dont_apply_original_css_.value();
1838  }
1839 
1840  int domain_shard_count() const { return domain_shard_count_.value(); }
1843  void set_domain_shard_count(int64 x) {
1844  int value = x;
1845  set_option(value, &domain_shard_count_);
1846  }
1847 
1848  void set_enabled(EnabledEnum x) {
1849  set_option(x, &enabled_);
1850  }
1851  bool enabled() const {
1852  return enabled_.value() == kEnabledOn;
1853  }
1854  bool unplugged() const {
1855  return enabled_.value() == kEnabledUnplugged;
1856  }
1857  bool standby() const {
1858  return !enabled() && !unplugged();
1859  }
1860 
1861  void set_add_options_to_urls(bool x) {
1862  set_option(x, &add_options_to_urls_);
1863  }
1864 
1865  bool add_options_to_urls() const {
1866  return add_options_to_urls_.value();
1867  }
1868 
1869  void set_publicly_cache_mismatched_hashes_experimental(bool x) {
1870  set_option(x, &publicly_cache_mismatched_hashes_experimental_);
1871  }
1872 
1873  bool publicly_cache_mismatched_hashes_experimental() const {
1874  return publicly_cache_mismatched_hashes_experimental_.value();
1875  }
1876 
1877  void set_oblivious_pagespeed_urls(bool x) {
1878  set_option(x, &oblivious_pagespeed_urls_);
1879  }
1880 
1881  bool oblivious_pagespeed_urls() const {
1882  return oblivious_pagespeed_urls_.value();
1883  }
1884 
1885  void set_in_place_rewriting_enabled(bool x) {
1886  set_option(x, &in_place_rewriting_enabled_);
1887  }
1888 
1889  bool in_place_rewriting_enabled() const {
1890  return CheckBandwidthOption(in_place_rewriting_enabled_);
1891  }
1892 
1893  void set_in_place_wait_for_optimized(bool x) {
1894  set_option(x, &in_place_wait_for_optimized_);
1895  }
1896 
1897  bool in_place_wait_for_optimized() const {
1898  return (in_place_wait_for_optimized_.value() ||
1899  (in_place_rewrite_deadline_ms() < 0));
1900  }
1901 
1902  void set_in_place_rewrite_deadline_ms(int x) {
1903  set_option(x, &in_place_rewrite_deadline_ms_);
1904  }
1905 
1906  int in_place_rewrite_deadline_ms() const {
1907  return in_place_rewrite_deadline_ms_.value();
1908  }
1909 
1910  void set_in_place_s_maxage_sec(int x) {
1911  set_option(x, &in_place_s_maxage_sec_);
1912  }
1913 
1914  int in_place_s_maxage_sec() const {
1915  return in_place_s_maxage_sec_.value();
1916  }
1917 
1918  int EffectiveInPlaceSMaxAgeSec() const {
1919  return modify_caching_headers() ? in_place_s_maxage_sec() : -1;
1920  }
1921 
1922  void set_in_place_preemptive_rewrite_css(bool x) {
1923  set_option(x, &in_place_preemptive_rewrite_css_);
1924  }
1925  bool in_place_preemptive_rewrite_css() const {
1926  return CheckBandwidthOption(in_place_preemptive_rewrite_css_);
1927  }
1928 
1929  void set_in_place_preemptive_rewrite_css_images(bool x) {
1930  set_option(x, &in_place_preemptive_rewrite_css_images_);
1931  }
1932  bool in_place_preemptive_rewrite_css_images() const {
1933  return CheckBandwidthOption(in_place_preemptive_rewrite_css_images_);
1934  }
1935 
1936  void set_in_place_preemptive_rewrite_images(bool x) {
1937  set_option(x, &in_place_preemptive_rewrite_images_);
1938  }
1939  bool in_place_preemptive_rewrite_images() const {
1940  return CheckBandwidthOption(in_place_preemptive_rewrite_images_);
1941  }
1942 
1943  void set_in_place_preemptive_rewrite_javascript(bool x) {
1944  set_option(x, &in_place_preemptive_rewrite_javascript_);
1945  }
1946  bool in_place_preemptive_rewrite_javascript() const {
1947  return CheckBandwidthOption(in_place_preemptive_rewrite_javascript_);
1948  }
1949 
1950  void set_private_not_vary_for_ie(bool x) {
1951  set_option(x, &private_not_vary_for_ie_);
1952  }
1953  bool private_not_vary_for_ie() const {
1954  return private_not_vary_for_ie_.value();
1955  }
1956 
1957  void set_combine_across_paths(bool x) {
1958  set_option(x, &combine_across_paths_);
1959  }
1960  bool combine_across_paths() const { return combine_across_paths_.value(); }
1961 
1962  void set_log_background_rewrites(bool x) {
1963  set_option(x, &log_background_rewrites_);
1964  }
1965  bool log_background_rewrites() const {
1966  return log_background_rewrites_.value();
1967  }
1968 
1969  void set_log_mobilization_samples(bool x) {
1970  set_option(x, &log_mobilization_samples_);
1971  }
1972  bool log_mobilization_samples() const {
1973  return log_mobilization_samples_.value();
1974  }
1975 
1976  void set_log_rewrite_timing(bool x) {
1977  set_option(x, &log_rewrite_timing_);
1978  }
1979  bool log_rewrite_timing() const { return log_rewrite_timing_.value(); }
1980 
1981  void set_log_url_indices(bool x) {
1982  set_option(x, &log_url_indices_);
1983  }
1984  bool log_url_indices() const { return log_url_indices_.value(); }
1985 
1986  void set_lowercase_html_names(bool x) {
1987  set_option(x, &lowercase_html_names_);
1988  }
1989  bool lowercase_html_names() const { return lowercase_html_names_.value(); }
1990 
1991  void set_always_rewrite_css(bool x) {
1992  set_option(x, &always_rewrite_css_);
1993  }
1994  bool always_rewrite_css() const { return always_rewrite_css_.value(); }
1995 
1996  void set_respect_vary(bool x) {
1997  set_option(x, &respect_vary_);
1998  }
1999  bool respect_vary() const { return respect_vary_.value(); }
2000 
2001  void set_respect_x_forwarded_proto(bool x) {
2002  set_option(x, &respect_x_forwarded_proto_);
2003  }
2004  bool respect_x_forwarded_proto() const {
2005  return respect_x_forwarded_proto_.value();
2006  }
2007 
2008  void set_flush_html(bool x) { set_option(x, &flush_html_); }
2009  bool flush_html() const { return flush_html_.value(); }
2010 
2011  void set_serve_stale_if_fetch_error(bool x) {
2012  set_option(x, &serve_stale_if_fetch_error_);
2013  }
2014  bool serve_stale_if_fetch_error() const {
2015  return serve_stale_if_fetch_error_.value();
2016  }
2017 
2018  void set_serve_xhr_access_control_headers(bool x) {
2019  set_option(x, &serve_xhr_access_control_headers_);
2020  }
2021  bool serve_xhr_access_control_headers() const {
2022  return serve_xhr_access_control_headers_.value();
2023  }
2024 
2025  void set_proactively_freshen_user_facing_request(bool x) {
2026  set_option(x, &proactively_freshen_user_facing_request_);
2027  }
2028  bool proactively_freshen_user_facing_request() const {
2029  return proactively_freshen_user_facing_request_.value();
2030  }
2031 
2032  void set_serve_stale_while_revalidate_threshold_sec(int64 x) {
2033  set_option(x, &serve_stale_while_revalidate_threshold_sec_);
2034  }
2035  int64 serve_stale_while_revalidate_threshold_sec() const {
2036  return serve_stale_while_revalidate_threshold_sec_.value();
2037  }
2038 
2039  void set_default_cache_html(bool x) { set_option(x, &default_cache_html_); }
2040  bool default_cache_html() const { return default_cache_html_.value(); }
2041 
2042  void set_modify_caching_headers(bool x) {
2043  set_option(x, &modify_caching_headers_);
2044  }
2045  bool modify_caching_headers() const {
2046  return modify_caching_headers_.value();
2047  }
2048 
2049  void set_inline_only_critical_images(bool x) {
2050  set_option(x, &inline_only_critical_images_);
2051  }
2052  bool inline_only_critical_images() const {
2053  return inline_only_critical_images_.value();
2054  }
2055 
2056  void set_critical_images_beacon_enabled(bool x) {
2057  set_option(x, &critical_images_beacon_enabled_);
2058  }
2059  bool critical_images_beacon_enabled() const {
2060  return critical_images_beacon_enabled_.value();
2061  }
2062 
2063  void set_beacon_reinstrument_time_sec(int x) {
2064  set_option(x, &beacon_reinstrument_time_sec_);
2065  }
2066  int beacon_reinstrument_time_sec() const {
2067  return beacon_reinstrument_time_sec_.value();
2068  }
2069 
2070  void set_accept_invalid_signatures(bool x) {
2071  set_option(x, &accept_invalid_signatures_);
2072  }
2073  bool accept_invalid_signatures() const {
2074  return accept_invalid_signatures_.value();
2075  }
2076 
2077  void set_remote_configuration_timeout_ms(int64 x) {
2078  set_option(x, &remote_configuration_timeout_ms_);
2079  }
2080  int64 remote_configuration_timeout_ms() const {
2081  return remote_configuration_timeout_ms_.value();
2082  }
2083 
2084  void set_remote_configuration_url(StringPiece p) {
2085  set_option(GoogleString(p.data(), p.size()), &remote_configuration_url_);
2086  }
2087  const GoogleString& remote_configuration_url() const {
2088  return remote_configuration_url_.value();
2089  }
2090 
2091  void set_http_cache_compression_level(int x) {
2092  set_option(x, &http_cache_compression_level_);
2093  }
2094  int http_cache_compression_level() const {
2095  return http_cache_compression_level_.value();
2096  }
2097 
2098  void set_request_option_override(StringPiece p) {
2099  set_option(GoogleString(p.data(), p.size()), &request_option_override_);
2100  }
2101  const GoogleString& request_option_override() const {
2102  return request_option_override_.value();
2103  }
2104 
2105  void set_url_signing_key(StringPiece p) {
2106  set_option(GoogleString(p.data(), p.size()), &url_signing_key_);
2107  }
2108  const GoogleString& url_signing_key() const {
2109  return url_signing_key_.value();
2110  }
2111 
2112  void set_lazyload_images_after_onload(bool x) {
2113  set_option(x, &lazyload_images_after_onload_);
2114  }
2115  bool lazyload_images_after_onload() const {
2116  return lazyload_images_after_onload_.value();
2117  }
2118 
2119  void set_lazyload_images_blank_url(StringPiece p) {
2120  set_option(GoogleString(p.data(), p.size()), &lazyload_images_blank_url_);
2121  }
2122  const GoogleString& lazyload_images_blank_url() const {
2123  return lazyload_images_blank_url_.value();
2124  }
2125 
2126  void set_max_inlined_preview_images_index(int x) {
2127  set_option(x, &max_inlined_preview_images_index_);
2128  }
2129  int max_inlined_preview_images_index() const {
2130  return max_inlined_preview_images_index_.value();
2131  }
2132 
2133  void set_use_blank_image_for_inline_preview(bool x) {
2134  set_option(x, &use_blank_image_for_inline_preview_);
2135  }
2136  bool use_blank_image_for_inline_preview() const {
2137  return use_blank_image_for_inline_preview_.value();
2138  }
2139 
2140  void set_min_image_size_low_resolution_bytes(int64 x) {
2141  set_option(x, &min_image_size_low_resolution_bytes_);
2142  }
2143  int64 min_image_size_low_resolution_bytes() const {
2144  return min_image_size_low_resolution_bytes_.value();
2145  }
2146 
2147  void set_max_image_size_low_resolution_bytes(int64 x) {
2148  set_option(x, &max_image_size_low_resolution_bytes_);
2149  }
2150  int64 max_image_size_low_resolution_bytes() const {
2151  return max_image_size_low_resolution_bytes_.value();
2152  }
2153 
2154  void set_experiment_cookie_duration_ms(int64 x) {
2155  set_option(x, &experiment_cookie_duration_ms_);
2156  }
2157  int64 experiment_cookie_duration_ms() const {
2158  return experiment_cookie_duration_ms_.value();
2159  }
2160 
2161  void set_finder_properties_cache_expiration_time_ms(int64 x) {
2162  set_option(x, &finder_properties_cache_expiration_time_ms_);
2163  }
2164  int64 finder_properties_cache_expiration_time_ms() const {
2165  return finder_properties_cache_expiration_time_ms_.value();
2166  }
2167 
2168  void set_finder_properties_cache_refresh_time_ms(int64 x) {
2169  set_option(x, &finder_properties_cache_refresh_time_ms_);
2170  }
2171  int64 finder_properties_cache_refresh_time_ms() const {
2172  return finder_properties_cache_refresh_time_ms_.value();
2173  }
2174 
2175  void set_rewrite_random_drop_percentage(int x) {
2176  set_option(x, &rewrite_random_drop_percentage_);
2177  }
2178  int rewrite_random_drop_percentage() const {
2179  return rewrite_random_drop_percentage_.value();
2180  }
2181 
2188  bool css_preserve_urls() const {
2189  return (CheckBandwidthOption(css_preserve_urls_) ||
2190  CheckMobilizeFiltersOption(css_preserve_urls_));
2191  }
2192  void set_css_preserve_urls(bool x) {
2193  set_option(x, &css_preserve_urls_);
2194  }
2195 
2196  bool image_preserve_urls() const {
2197  return CheckBandwidthOption(image_preserve_urls_);
2198  }
2199  void set_image_preserve_urls(bool x) {
2200  set_option(x, &image_preserve_urls_);
2201  }
2202 
2203  bool js_preserve_urls() const {
2204  return CheckBandwidthOption(js_preserve_urls_);
2205  }
2206  void set_js_preserve_urls(bool x) {
2207  set_option(x, &js_preserve_urls_);
2208  }
2209 
2210  void set_metadata_cache_staleness_threshold_ms(int64 x) {
2211  set_option(x, &metadata_cache_staleness_threshold_ms_);
2212  }
2213  int64 metadata_cache_staleness_threshold_ms() const {
2214  return metadata_cache_staleness_threshold_ms_.value();
2215  }
2216 
2217  void set_metadata_input_errors_cache_ttl_ms(int64 x) {
2218  set_option(x, &metadata_input_errors_cache_ttl_ms_);
2219  }
2220  int64 metadata_input_errors_cache_ttl_ms() const {
2221  return metadata_input_errors_cache_ttl_ms_.value();
2222  }
2223 
2224  const GoogleString& downstream_cache_purge_method() const {
2225  return downstream_cache_purge_method_.value();
2226  }
2227  void set_downstream_cache_purge_method(StringPiece p) {
2228  set_option(p.as_string(), &downstream_cache_purge_method_);
2229  }
2230 
2231  const GoogleString& downstream_cache_purge_location_prefix() const {
2232  return downstream_cache_purge_location_prefix_.value();
2233  }
2237  while (p.ends_with("/")) {
2238  p.remove_suffix(1);
2239  }
2240  set_option(p.as_string(), &downstream_cache_purge_location_prefix_);
2241  }
2242  bool IsDownstreamCacheIntegrationEnabled() const {
2243  return !downstream_cache_purge_location_prefix().empty();
2244  }
2245 
2246  void set_downstream_cache_rebeaconing_key(StringPiece p) {
2247  set_option(p.as_string(), &downstream_cache_rebeaconing_key_);
2248  }
2249  const GoogleString& downstream_cache_rebeaconing_key() const {
2250  return downstream_cache_rebeaconing_key_.value();
2251  }
2252  bool IsDownstreamCacheRebeaconingKeyConfigured() const {
2253  return !downstream_cache_rebeaconing_key().empty();
2254  }
2257  bool MatchesDownstreamCacheRebeaconingKey(StringPiece key) const {
2258  if (!IsDownstreamCacheRebeaconingKeyConfigured()) {
2259  return false;
2260  }
2261  return StringCaseEqual(key, downstream_cache_rebeaconing_key());
2262  }
2263 
2264  void set_downstream_cache_rewritten_percentage_threshold(int64 x) {
2265  set_option(x, &downstream_cache_rewritten_percentage_threshold_);
2266  }
2267  int64 downstream_cache_rewritten_percentage_threshold() const {
2268  return downstream_cache_rewritten_percentage_threshold_.value();
2269  }
2270 
2271  const BeaconUrl& beacon_url() const { return beacon_url_.value(); }
2272  void set_beacon_url(const GoogleString& beacon_url) {
2273  GoogleString ignored_error_detail;
2274  beacon_url_.SetFromString(beacon_url, &ignored_error_detail);
2275  }
2276 
2278  virtual bool trim_urls_in_css() const { return true; }
2279 
2280  void set_image_jpeg_recompress_quality(int64 x) {
2281  set_option(x, &image_jpeg_recompress_quality_);
2282  }
2283 
2284  void set_image_jpeg_recompress_quality_for_small_screens(int64 x) {
2285  set_option(x, &image_jpeg_recompress_quality_for_small_screens_);
2286  }
2287 
2288  void set_image_jpeg_quality_for_save_data(int64 x) {
2289  set_option(x, &image_jpeg_quality_for_save_data_);
2290  }
2291 
2292  int64 image_recompress_quality() const {
2293  return image_recompress_quality_.value();
2294  }
2295  void set_image_recompress_quality(int64 x) {
2296  set_option(x, &image_recompress_quality_);
2297  }
2298 
2299  int image_limit_optimized_percent() const {
2300  return image_limit_optimized_percent_.value();
2301  }
2302  void set_image_limit_optimized_percent(int x) {
2303  set_option(x, &image_limit_optimized_percent_);
2304  }
2305  int image_limit_resize_area_percent() const {
2306  return image_limit_resize_area_percent_.value();
2307  }
2308  void set_image_limit_resize_area_percent(int x) {
2309  set_option(x, &image_limit_resize_area_percent_);
2310  }
2311 
2312  int image_limit_rendered_area_percent() const {
2313  return image_limit_rendered_area_percent_.value();
2314  }
2315  void set_image_limit_rendered_area_percent(int x) {
2316  set_option(x, &image_limit_rendered_area_percent_);
2317  }
2318 
2319  int64 image_jpeg_num_progressive_scans() const {
2320  return image_jpeg_num_progressive_scans_.value();
2321  }
2322  void set_image_jpeg_num_progressive_scans(int64 x) {
2323  set_option(x, &image_jpeg_num_progressive_scans_);
2324  }
2325 
2326  void set_image_jpeg_num_progressive_scans_for_small_screens(int64 x) {
2327  set_option(x, &image_jpeg_num_progressive_scans_for_small_screens_);
2328  }
2329 
2330  void set_image_webp_recompress_quality(int64 x) {
2331  set_option(x, &image_webp_recompress_quality_);
2332  }
2333 
2334  void set_image_webp_recompress_quality_for_small_screens(int64 x) {
2335  set_option(x, &image_webp_recompress_quality_for_small_screens_);
2336  }
2337 
2338  void set_image_webp_animated_recompress_quality(int64 x) {
2339  set_option(x, &image_webp_animated_recompress_quality_);
2340  }
2341 
2342  void set_image_webp_quality_for_save_data(int64 x) {
2343  set_option(x, &image_webp_quality_for_save_data_);
2344  }
2345 
2346  int64 image_webp_timeout_ms() const {
2347  return image_webp_timeout_ms_.value();
2348  }
2349  void set_image_webp_timeout_ms(int64 x) {
2350  set_option(x, &image_webp_timeout_ms_);
2351  }
2352 
2353  bool domain_rewrite_hyperlinks() const {
2354  return CheckMobilizeFiltersOption(domain_rewrite_hyperlinks_);
2355  }
2356  void set_domain_rewrite_hyperlinks(bool x) {
2357  set_option(x, &domain_rewrite_hyperlinks_);
2358  }
2359 
2360  bool domain_rewrite_cookies() const {
2361  return CheckMobilizeFiltersOption(domain_rewrite_cookies_);
2362  }
2363  void set_domain_rewrite_cookies(bool x) {
2364  set_option(x, &domain_rewrite_cookies_);
2365  }
2366 
2367  bool client_domain_rewrite() const {
2368  return client_domain_rewrite_.value();
2369  }
2370  void set_client_domain_rewrite(bool x) {
2371  set_option(x, &client_domain_rewrite_);
2372  }
2373 
2374  void set_follow_flushes(bool x) { set_option(x, &follow_flushes_); }
2375  bool follow_flushes() const { return follow_flushes_.value(); }
2376 
2377  void set_enable_defer_js_experimental(bool x) {
2378  set_option(x, &enable_defer_js_experimental_);
2379  }
2380  bool enable_defer_js_experimental() const {
2381  return enable_defer_js_experimental_.value();
2382  }
2383 
2384  void set_disable_rewrite_on_no_transform(bool x) {
2385  set_option(x, &disable_rewrite_on_no_transform_);
2386  }
2387  bool disable_rewrite_on_no_transform() const {
2388  return disable_rewrite_on_no_transform_.value();
2389  }
2390 
2391  void set_disable_background_fetches_for_bots(bool x) {
2392  set_option(x, &disable_background_fetches_for_bots_);
2393  }
2394  bool disable_background_fetches_for_bots() const {
2395  return disable_background_fetches_for_bots_.value();
2396  }
2397 
2398  void set_enable_cache_purge(bool x) {
2399  set_option(x, &enable_cache_purge_);
2400  }
2401  bool enable_cache_purge() const {
2402  return enable_cache_purge_.value();
2403  }
2404 
2405  void set_proactive_resource_freshening(bool x) {
2406  set_option(x, &proactive_resource_freshening_);
2407  }
2408  bool proactive_resource_freshening() const {
2409  return proactive_resource_freshening_.value();
2410  }
2411 
2412  void set_lazyload_highres_images(bool x) {
2413  set_option(x, &lazyload_highres_images_);
2414  }
2415  bool lazyload_highres_images() const {
2416  return lazyload_highres_images_.value();
2417  }
2418 
2419  void set_use_fallback_property_cache_values(bool x) {
2420  set_option(x, &use_fallback_property_cache_values_);
2421  }
2422  bool use_fallback_property_cache_values() const {
2423  return use_fallback_property_cache_values_.value();
2424  }
2425 
2426  void set_await_pcache_lookup(bool x) {
2427  set_option(x, &await_pcache_lookup_);
2428  }
2429  bool await_pcache_lookup() const {
2430  return await_pcache_lookup_.value();
2431  }
2432 
2433  void set_enable_prioritizing_scripts(bool x) {
2434  set_option(x, &enable_prioritizing_scripts_);
2435  }
2436  bool enable_prioritizing_scripts() const {
2437  return enable_prioritizing_scripts_.value();
2438  }
2439 
2440  const GoogleString& blocking_rewrite_key() const {
2441  return blocking_rewrite_key_.value();
2442  }
2443  void set_blocking_rewrite_key(StringPiece p) {
2444  set_option(p.as_string(), &blocking_rewrite_key_);
2445  }
2446 
2447  void EnableBlockingRewriteForRefererUrlPattern(
2448  StringPiece url_pattern) {
2449  Modify();
2450  blocking_rewrite_referer_urls_.MakeWriteable()->Allow(url_pattern);
2451  }
2452 
2453  bool IsBlockingRewriteEnabledForReferer(StringPiece url) const {
2454  return blocking_rewrite_referer_urls_->Match(url, false);
2455  }
2456 
2457  bool IsBlockingRewriteRefererUrlPatternPresent() const {
2458  return blocking_rewrite_referer_urls_->num_wildcards() > 0;
2459  }
2460 
2461  bool rewrite_uncacheable_resources() const {
2462  return rewrite_uncacheable_resources_.value();
2463  }
2464 
2465  void set_rewrite_uncacheable_resources(bool x) {
2466  set_option(x, &rewrite_uncacheable_resources_);
2467  }
2468 
2469  void set_running_experiment(bool x) {
2470  set_option(x, &running_experiment_);
2471  }
2472  bool running_experiment() const {
2473  return running_experiment_.value();
2474  }
2475 
2478  set_option(x, &experiment_ga_slot_);
2479  }
2480  int experiment_ga_slot() const { return experiment_ga_slot_.value(); }
2481 
2482  void set_enroll_experiment_id(int x) {
2483  set_option(x, &enroll_experiment_id_);
2484  }
2485  int enroll_experiment_id() const { return enroll_experiment_id_.value(); }
2486 
2487  void set_report_unload_time(bool x) {
2488  set_option(x, &report_unload_time_);
2489  }
2490  bool report_unload_time() const {
2491  return report_unload_time_.value();
2492  }
2493 
2494  void set_implicit_cache_ttl_ms(int64 x) {
2495  set_option(x, &implicit_cache_ttl_ms_);
2496  }
2497  int64 implicit_cache_ttl_ms() const {
2498  return implicit_cache_ttl_ms_.value();
2499  }
2500 
2501  void set_load_from_file_cache_ttl_ms(int64 x) {
2502  set_option(x, &load_from_file_cache_ttl_ms_);
2503  }
2504  int64 load_from_file_cache_ttl_ms() const {
2505  return load_from_file_cache_ttl_ms_.value();
2506  }
2507  bool load_from_file_cache_ttl_ms_was_set() const {
2508  return load_from_file_cache_ttl_ms_.was_set();
2509  }
2510 
2511  void set_x_header_value(StringPiece p) {
2512  set_option(p.as_string(), &x_header_value_);
2513  }
2514  const GoogleString& x_header_value() const {
2515  return x_header_value_.value();
2516  }
2517 
2518  void set_avoid_renaming_introspective_javascript(bool x) {
2519  set_option(x, &avoid_renaming_introspective_javascript_);
2520  }
2521  bool avoid_renaming_introspective_javascript() const {
2522  return avoid_renaming_introspective_javascript_.value();
2523  }
2524 
2525  void set_forbid_all_disabled_filters(bool x) {
2526  set_option(x, &forbid_all_disabled_filters_);
2527  }
2528  bool forbid_all_disabled_filters() const {
2529  return forbid_all_disabled_filters_.value();
2530  }
2531 
2532  bool reject_blacklisted() const { return reject_blacklisted_.value(); }
2533  void set_reject_blacklisted(bool x) {
2534  set_option(x, &reject_blacklisted_);
2535  }
2536 
2537  HttpStatus::Code reject_blacklisted_status_code() const {
2538  return static_cast<HttpStatus::Code>(
2539  reject_blacklisted_status_code_.value());
2540  }
2541  void set_reject_blacklisted_status_code(HttpStatus::Code x) {
2542  set_option(static_cast<int>(x), &reject_blacklisted_status_code_);
2543  }
2544 
2545  bool support_noscript_enabled() const {
2546  return support_noscript_enabled_.value();
2547  }
2548  void set_support_noscript_enabled(bool x) {
2549  set_option(x, &support_noscript_enabled_);
2550  }
2551 
2552  bool enable_extended_instrumentation() const {
2553  return enable_extended_instrumentation_.value();
2554  }
2555  void set_enable_extended_instrumentation(bool x) {
2556  set_option(x, &enable_extended_instrumentation_);
2557  }
2558 
2559  bool use_experimental_js_minifier() const {
2560  return use_experimental_js_minifier_.value();
2561  }
2562  void set_use_experimental_js_minifier(bool x) {
2563  set_option(x, &use_experimental_js_minifier_);
2564  }
2565 
2566  void set_max_combined_css_bytes(int64 x) {
2567  set_option(x, &max_combined_css_bytes_);
2568  }
2569  int64 max_combined_css_bytes() const {
2570  return max_combined_css_bytes_.value();
2571  }
2572 
2573  void set_max_combined_js_bytes(int64 x) {
2574  set_option(x, &max_combined_js_bytes_);
2575  }
2576  int64 max_combined_js_bytes() const {
2577  return max_combined_js_bytes_.value();
2578  }
2579 
2580  void set_pre_connect_url(StringPiece p) {
2581  set_option(GoogleString(p.data(), p.size()), &pre_connect_url_);
2582  }
2583  const GoogleString& pre_connect_url() const {
2584  return pre_connect_url_.value();
2585  }
2586  void set_property_cache_http_status_stability_threshold(int x) {
2587  set_option(x, &property_cache_http_status_stability_threshold_);
2588  }
2589  int property_cache_http_status_stability_threshold() const {
2590  return property_cache_http_status_stability_threshold_.value();
2591  }
2592 
2593  void set_max_rewrite_info_log_size(int x) {
2594  set_option(x, &max_rewrite_info_log_size_);
2595  }
2596  int max_rewrite_info_log_size() const {
2597  return max_rewrite_info_log_size_.value();
2598  }
2599 
2600  void set_enable_aggressive_rewriters_for_mobile(bool x) {
2601  set_option(x, &enable_aggressive_rewriters_for_mobile_);
2602  }
2603  bool enable_aggressive_rewriters_for_mobile() const {
2604  return enable_aggressive_rewriters_for_mobile_.value();
2605  }
2606 
2607  void set_allow_logging_urls_in_log_record(bool x) {
2608  set_option(x, &allow_logging_urls_in_log_record_);
2609  }
2610  bool allow_logging_urls_in_log_record() const {
2611  return allow_logging_urls_in_log_record_.value();
2612  }
2613 
2614  void set_allow_options_to_be_set_by_cookies(bool x) {
2615  set_option(x, &allow_options_to_be_set_by_cookies_);
2616  }
2617  bool allow_options_to_be_set_by_cookies() const {
2618  return allow_options_to_be_set_by_cookies_.value();
2619  }
2620 
2621  void set_non_cacheables_for_cache_partial_html(StringPiece p) {
2622  set_option(p.as_string(), &non_cacheables_for_cache_partial_html_);
2623  }
2624  const GoogleString& non_cacheables_for_cache_partial_html() const {
2625  return non_cacheables_for_cache_partial_html_.value();
2626  }
2627 
2628  void set_no_transform_optimized_images(bool x) {
2629  set_option(x, &no_transform_optimized_images_);
2630  }
2631  bool no_transform_optimized_images() const {
2632  return no_transform_optimized_images_.value();
2633  }
2634 
2635  void set_access_control_allow_origins(StringPiece p) {
2636  set_option(p.as_string(), &access_control_allow_origins_);
2637  }
2638  const GoogleString& access_control_allow_origins() const {
2639  return access_control_allow_origins_.value();
2640  }
2641 
2642  void set_hide_referer_using_meta(bool x) {
2643  set_option(x, &hide_referer_using_meta_);
2644  }
2645  bool hide_referer_using_meta() const {
2646  return hide_referer_using_meta_.value();
2647  }
2648 
2649  void set_max_low_res_image_size_bytes(int64 x) {
2650  set_option(x, &max_low_res_image_size_bytes_);
2651  }
2652  int64 max_low_res_image_size_bytes() const {
2653  return max_low_res_image_size_bytes_.value();
2654  }
2655 
2656  void set_max_low_res_to_full_res_image_size_percentage(int x) {
2657  set_option(x, &max_low_res_to_full_res_image_size_percentage_);
2658  }
2659  int max_low_res_to_full_res_image_size_percentage() const {
2660  return max_low_res_to_full_res_image_size_percentage_.value();
2661  }
2662 
2663  void set_serve_rewritten_webp_urls_to_any_agent(bool x) {
2664  set_option(x, &serve_rewritten_webp_urls_to_any_agent_);
2665  }
2666  bool serve_rewritten_webp_urls_to_any_agent() const {
2667  return serve_rewritten_webp_urls_to_any_agent_.value();
2668  }
2669 
2670  void set_cache_fragment(StringPiece p) {
2671  set_option(p.as_string(), &cache_fragment_);
2672  }
2673  const GoogleString& cache_fragment() const {
2674  return cache_fragment_.value();
2675  }
2676 
2677  void set_sticky_query_parameters(StringPiece p) {
2678  set_option(p.as_string(), &sticky_query_parameters_);
2679  }
2680  const GoogleString& sticky_query_parameters() const {
2681  return sticky_query_parameters_.value();
2682  }
2683 
2684  void set_option_cookies_duration_ms(int64 x) {
2685  set_option(x, &option_cookies_duration_ms_);
2686  }
2687  int64 option_cookies_duration_ms() const {
2688  return option_cookies_duration_ms_.value();
2689  }
2690 
2691  void set_responsive_image_densities(const ResponsiveDensities& x) {
2692  set_option(x, &responsive_image_densities_);
2693  }
2694  const ResponsiveDensities& responsive_image_densities() const {
2695  return responsive_image_densities_.value();
2696  }
2697 
2698  const GoogleString& amp_link_pattern() const {
2699  return amp_link_pattern_.value();
2700  }
2701  void set_amp_link_pattern(const GoogleString& id) {
2702  set_option(id, &amp_link_pattern_);
2703  }
2704 
2705  bool honor_csp() const {
2706  return honor_csp_.value();
2707  }
2708  void set_honor_csp(bool x) {
2709  set_option(x, &honor_csp_);
2710  }
2711 
2712  virtual bool DisableDomainRewrite() const { return false; }
2713 
2729  virtual void Merge(const RewriteOptions& src);
2730 
2733  void MergeOnlyProcessScopeOptions(const RewriteOptions& src);
2734 
2737  void Allow(StringPiece wildcard_pattern) {
2738  Modify();
2739  allow_resources_.MakeWriteable()->Allow(wildcard_pattern);
2740  }
2741 
2744  void Disallow(StringPiece wildcard_pattern) {
2745  Modify();
2746  allow_resources_.MakeWriteable()->Disallow(wildcard_pattern);
2747  }
2748 
2750  void AllowWhenInlining(StringPiece wildcard_pattern) {
2751  Modify();
2752  allow_when_inlining_resources_.MakeWriteable()->Allow(wildcard_pattern);
2753  }
2754 
2758  void AllowOnlyWhenInlining(StringPiece wildcard_pattern) {
2759  Disallow(wildcard_pattern);
2760  AllowWhenInlining(wildcard_pattern);
2761  }
2762 
2764  void DisallowWhenInlining(StringPiece wildcard_pattern) {
2765  Modify();
2766  allow_when_inlining_resources_.MakeWriteable()->Disallow(wildcard_pattern);
2767  }
2768 
2772  virtual void DisallowTroublesomeResources();
2773 
2778  virtual void DisallowResourcesForProxy();
2779 
2800  const DomainLawyer* domain_lawyer() const { return domain_lawyer_.get(); }
2801  DomainLawyer* WriteableDomainLawyer();
2802 
2803  FileLoadPolicy* file_load_policy() { return &file_load_policy_; }
2804  const FileLoadPolicy* file_load_policy() const { return &file_load_policy_; }
2805 
2808  bool IsAllowed(StringPiece url) const {
2809  return allow_resources_->Match(url, true );
2810  }
2811 
2819  bool IsAllowedWhenInlining(StringPiece url) const {
2820  return allow_when_inlining_resources_->Match(
2821  url, false );
2822  }
2823 
2825  void RetainComment(StringPiece comment) {
2826  Modify();
2827  retain_comments_.MakeWriteable()->Allow(comment);
2828  }
2829 
2833  bool IsRetainedComment(StringPiece comment) const {
2834  return retain_comments_->Match(comment, false);
2835  }
2836 
2838  void DisableLazyloadForClassName(StringPiece class_name) {
2839  Modify();
2840  lazyload_enabled_classes_.MakeWriteable()->Disallow(class_name);
2841  }
2842 
2844  bool IsLazyloadEnabledForClassName(StringPiece class_name) const {
2845  return lazyload_enabled_classes_->Match(class_name, true);
2846  }
2847 
2849  void AddCssCombiningWildcard(StringPiece id_wildcard) {
2850  Modify();
2851  css_combining_permitted_ids_.MakeWriteable()->Allow(id_wildcard);
2852  }
2853 
2854  bool IsAllowedIdForCssCombining(StringPiece id) const {
2855  return css_combining_permitted_ids_->Match(id, false);
2856  }
2857 
2858  bool CssCombiningMayPermitIds() const {
2859  return !css_combining_permitted_ids_->empty();
2860  }
2861 
2862  void set_override_caching_ttl_ms(int64 x) {
2863  set_option(x, &override_caching_ttl_ms_);
2864  }
2865  int64 override_caching_ttl_ms() const {
2866  return override_caching_ttl_ms_.value();
2867  }
2868 
2871  void AddOverrideCacheTtl(StringPiece wildcard) {
2872  Modify();
2873  override_caching_wildcard_.MakeWriteable()->Allow(wildcard);
2874  }
2875 
2877  bool IsCacheTtlOverridden(StringPiece url) const {
2878  return override_caching_wildcard_->Match(url, false);
2879  }
2880 
2881  void AddRejectedUrlWildcard(const GoogleString& wildcard) {
2882  AddRejectedHeaderWildcard(kRejectedRequestUrlKeyName, wildcard);
2883  }
2884 
2885  void AddRejectedHeaderWildcard(StringPiece header_name,
2886  const GoogleString& wildcard) {
2887  Modify();
2888  std::pair<FastWildcardGroupMap::iterator, bool> insert_result =
2889  rejected_request_map_.insert(std::make_pair(
2890  header_name, static_cast<FastWildcardGroup*>(NULL)));
2891 
2892  if (insert_result.second) {
2893  insert_result.first->second = new FastWildcardGroup;
2894  }
2895  insert_result.first->second->Allow(wildcard);
2896  }
2897 
2900  bool IsRequestDeclined(const GoogleString& url,
2901  const RequestHeaders* request_headers) const;
2902 
2906  virtual RewriteOptions* Clone() const;
2907 
2909  virtual RewriteOptions* NewOptions() const;
2910 
2916  void ComputeSignature() LOCKS_EXCLUDED(cache_purge_mutex_.get());
2917  void ComputeSignatureLockHeld() SHARED_LOCKS_REQUIRED(cache_purge_mutex_);
2918 
2921  virtual GoogleString SubclassSignatureLockHeld() { return ""; }
2922 
2927  void Freeze();
2928 
2939 
2940  bool frozen() const { return frozen_; }
2941 
2946  bool frozen = frozen_;
2948  return frozen;
2949  }
2950 
2952  const GoogleString& signature() const {
2960  ThreadSystem::ScopedReader lock(cache_purge_mutex_.get());
2961  DCHECK(frozen_);
2962  DCHECK(!signature_.empty());
2963  return signature_;
2964  }
2965 
2966  virtual GoogleString OptionsToString() const;
2967  GoogleString FilterSetToString(const FilterSet& filter_set) const;
2968  GoogleString EnabledFiltersToString() const;
2972 
2975  virtual GoogleString ToExperimentString() const;
2976 
2980  virtual GoogleString ToExperimentDebugString() const;
2981 
2984  static Filter LookupFilterById(const StringPiece& filter_id);
2985 
2987  static Filter LookupFilter(const StringPiece& filter_name);
2988 
2991  static const PropertyBase* LookupOptionById(StringPiece option_id);
2992  static const PropertyBase* LookupOptionByName(StringPiece option_name);
2993 
2996  static const StringPiece LookupOptionNameById(StringPiece option_id);
2997 
2999  static bool IsValidOptionName(StringPiece name);
3000 
3003  static bool IsDeprecatedOptionName(StringPiece option_name);
3004 
3008  return all_options_;
3009  }
3010 
3011  static const Properties* deprecated_properties() {
3012  return deprecated_properties_;
3013  }
3014 
3018  bool IsEqual(const RewriteOptions& that) const;
3019 
3021  const Hasher* hasher() const { return &hasher_; }
3022 
3023  const SHA1Signature* sha1signature() const { return &sha1signature_; }
3024 
3025  ThreadSystem* thread_system() const { return thread_system_; }
3026 
3030  HttpOptions ComputeHttpOptions() const;
3031 
3034  bool NeedsDependenciesCohort() const;
3035 
3036  protected:
3046  template<class T> class OptionTemplateBase : public OptionBase {
3047  public:
3048  typedef T ValueType;
3049 
3050  OptionTemplateBase() : was_set_(false), property_(NULL) {}
3051 
3052  virtual bool was_set() const { return was_set_; }
3053 
3054  void set(const T& val) {
3055  was_set_ = true;
3056  value_ = val;
3057  }
3058 
3059  void set_default(const T& val) {
3060  if (!was_set_) {
3061  value_ = val;
3062  }
3063  }
3064 
3065  const T& value() const { return value_; }
3066  T& mutable_value() { was_set_ = true; return value_; }
3067 
3073  virtual void Merge(const OptionBase* src) {
3074  DCHECK(option_name() == src->option_name());
3075  MergeHelper(static_cast<const OptionTemplateBase*>(src));
3076  }
3077 
3078  void MergeHelper(const OptionTemplateBase* src) {
3081  if (src->was_set_ || !was_set_) {
3082  value_ = src->value_;
3083  was_set_ = src->was_set_;
3084  }
3085  }
3086 
3088  void set_property(const Property<T>* property) {
3089  property_ = property;
3090 
3095  value_ = property->default_value();
3096  }
3097  virtual const PropertyBase* property() const { return property_; }
3098 
3107  void set_global_default(const T& val) {
3108  Property<T>* property = const_cast<Property<T>*>(property_);
3109  property->set_default(val);
3110  }
3111 
3121  Property<T>* property = const_cast<Property<T>*>(property_);
3122  property->set_do_not_use_for_signature_computation(true);
3123  }
3124 
3125  private:
3126  bool was_set_;
3127  T value_;
3128  const Property<T>* property_;
3129 
3130 
3131  };
3132 
3137  template<class T> class Option : public OptionTemplateBase<T> {
3138  public:
3139  Option() {}
3140 
3142  virtual bool SetFromString(StringPiece value_string,
3143  GoogleString* error_detail) {
3144  T value;
3145  bool success = RewriteOptions::ParseFromString(value_string, &value);
3146  if (success) {
3147  this->set(value);
3148  }
3149  return success;
3150  }
3151 
3152  virtual GoogleString Signature(const Hasher* hasher) const {
3153  return RewriteOptions::OptionSignature(this->value(), hasher);
3154  }
3155 
3156  virtual GoogleString ToString() const {
3157  return RewriteOptions::ToString(this->value());
3158  }
3159 
3160  private:
3161 
3162  };
3163 
3164  protected:
3166  template<class RewriteOptionsSubclass, class OptionClass>
3167  static void AddProperty(
3168  typename OptionClass::ValueType default_value,
3169  OptionClass RewriteOptionsSubclass::*offset,
3170  const char* id,
3171  StringPiece option_name,
3172  OptionScope scope,
3173  const char* help_text,
3174  bool safe_to_print,
3175  Properties* properties) {
3176  PropertyBase* property =
3178  default_value, offset, id, option_name);
3179  property->set_scope(scope);
3180  property->set_help_text(help_text);
3181  property->set_safe_to_print(safe_to_print);
3182  properties->push_back(property);
3183  }
3184 
3185  static void AddDeprecatedProperty(StringPiece option_name,
3186  OptionScope scope) {
3187  deprecated_properties_->push_back(
3188  new DeprecatedProperty(option_name, scope));
3189  }
3190 
3204  static void MergeSubclassProperties(Properties* properties);
3205 
3211  void set_option_at(int index, OptionBase* option) {
3212  all_options_[index] = option;
3213  }
3214 
3218  template<class T>
3219  void set_option(const T& new_value, OptionTemplateBase<T>* option) {
3220  option->set(new_value);
3221  Modify();
3222  }
3223 
3225  void Modify();
3226 
3234  void set_default_x_header_value(StringPiece x_header_value) {
3235  x_header_value_.set_global_default(x_header_value.as_string());
3236  }
3237 
3241  bool SetupExperimentRewriters();
3242 
3244  virtual void SetRequiredExperimentFilters();
3245 
3249  bool InsertExperimentSpecInVector(ExperimentSpec* spec);
3250 
3253 
3256 
3257  protected:
3261  public:
3262  explicit DeprecatedProperty(StringPiece option_name, OptionScope scope)
3263  : PropertyBase("", option_name) {
3264  set_do_not_use_for_signature_computation(true);
3265  set_help_text("Deprecated. Do not use");
3266  set_safe_to_print(false);
3267  set_scope(scope);
3268  }
3269 
3270  void InitializeOption(RewriteOptions* options) const override {
3271  CHECK(false) << "Deprecated properties shouldn't back options!";
3272  }
3273  };
3274 
3278  template<class ValueType>
3279  class Property : public PropertyBase {
3280  public:
3285  Property(ValueType default_value,
3286  const char* id,
3287  StringPiece option_name)
3288  : PropertyBase(id, option_name),
3289  default_value_(default_value) {
3290  }
3291 
3292  void set_default(ValueType value) { default_value_ = value; }
3293  const ValueType& default_value() const { return default_value_; }
3294 
3295  private:
3296  ValueType default_value_;
3297 
3298 
3299  };
3300 
3315  template<class RewriteOptionsSubclass, class OptionClass>
3316  class PropertyLeaf : public Property<typename OptionClass::ValueType> {
3317  public:
3321  typedef OptionClass RewriteOptionsSubclass::*OptionOffset;
3322  typedef typename OptionClass::ValueType ValueType;
3323 
3324  PropertyLeaf(ValueType default_value,
3325  OptionOffset offset,
3326  const char* id,
3327  StringPiece option_name)
3328  : Property<ValueType>(default_value, id, option_name),
3329  offset_(offset) {
3330  }
3331 
3332  virtual void InitializeOption(RewriteOptions* options) const {
3333  RewriteOptionsSubclass* options_subclass =
3334  static_cast<RewriteOptionsSubclass*>(options);
3335  OptionClass& option = options_subclass->*offset_;
3336  option.set_property(this);
3337  DCHECK_NE(-1, this->index()) << "Call Property::set_index first.";
3338  options->set_option_at(this->index(), &option);
3339  }
3340 
3341  private:
3342  OptionOffset offset_;
3343 
3344 
3345  };
3346 
3347  private:
3349  class CacheFragmentOption : public Option<GoogleString> {
3350  public:
3351  virtual bool SetFromString(StringPiece value_string,
3352  GoogleString* error_detail);
3353  };
3354 
3355  struct OptionIdCompare;
3356 
3361  enum MergeOverride { kNoAction, kDisablePreserve, kDisableFilter };
3362 
3363  static Properties* properties_;
3364  static Properties* all_properties_;
3365 
3366  static Properties* deprecated_properties_;
3367 
3368  FRIEND_TEST(RewriteOptionsTest, ExperimentMergeTest);
3369  FRIEND_TEST(RewriteOptionsTest, LookupOptionByNameTest);
3370  FRIEND_TEST(RewriteOptionsTest, ColorUtilTest);
3371  FRIEND_TEST(RewriteOptionsTest, ParseFloats);
3372 
3374  bool HasRejectedHeader(const StringPiece& header_name,
3375  const RequestHeaders* request_headers) const;
3376 
3377  bool IsRejectedUrl(const GoogleString& url) const {
3378  return IsRejectedRequest(kRejectedRequestUrlKeyName, url);
3379  }
3380 
3381  bool IsRejectedRequest(StringPiece header_name,
3382  StringPiece value) const {
3383  FastWildcardGroupMap::const_iterator it = rejected_request_map_.find(
3384  header_name);
3385  if (it != rejected_request_map_.end()) {
3386  return it->second->Match(value, false);
3387  }
3388  return false;
3389  }
3390 
3393  JavascriptLibraryIdentification* WriteableJavascriptLibraryIdentification();
3394 
3401  struct PrioritizeVisibleContentFamily {
3402  PrioritizeVisibleContentFamily(StringPiece url_pattern_string,
3403  int64 cache_time_ms_in,
3404  StringPiece non_cacheable_elements_in)
3405  : url_pattern(url_pattern_string),
3406  cache_time_ms(cache_time_ms_in),
3407  non_cacheable_elements(non_cacheable_elements_in.data(),
3408  non_cacheable_elements_in.size()) {}
3409 
3410  PrioritizeVisibleContentFamily* Clone() const {
3411  return new PrioritizeVisibleContentFamily(
3412  url_pattern.spec(), cache_time_ms, non_cacheable_elements);
3413  }
3414 
3415  GoogleString ComputeSignature() const {
3416  return StrCat(url_pattern.spec(), ";", Integer64ToString(cache_time_ms),
3417  ";", non_cacheable_elements);
3418  }
3419 
3420  GoogleString ToString() const {
3421  return StrCat("URL pattern: ", url_pattern.spec(), ", Cache time (ms): ",
3422  Integer64ToString(cache_time_ms), ", Non-cacheable: ",
3423  non_cacheable_elements);
3424  }
3425 
3426  Wildcard url_pattern;
3427  int64 cache_time_ms;
3428  GoogleString non_cacheable_elements;
3429  };
3430 
3433  struct UrlCacheInvalidationEntry {
3434  UrlCacheInvalidationEntry(StringPiece url_pattern_in,
3435  int64 timestamp_ms_in,
3436  bool ignores_metadata_and_pcache_in)
3437  : url_pattern(url_pattern_in),
3438  timestamp_ms(timestamp_ms_in),
3439  ignores_metadata_and_pcache(ignores_metadata_and_pcache_in) {}
3440 
3441  UrlCacheInvalidationEntry* Clone() const {
3442  return new UrlCacheInvalidationEntry(
3443  url_pattern.spec(), timestamp_ms, ignores_metadata_and_pcache);
3444  }
3445 
3446  GoogleString ComputeSignature() const {
3447  if (ignores_metadata_and_pcache) {
3448  return "";
3449  }
3450  return StrCat(url_pattern.spec(), "@", Integer64ToString(timestamp_ms));
3451  }
3452 
3453  GoogleString ToString() const {
3454  return StrCat(
3455  url_pattern.spec(), ", ",
3456  (ignores_metadata_and_pcache ? "STRICT" : "REFERENCE"), " @ ",
3457  Integer64ToString(timestamp_ms));
3458  }
3459 
3460  Wildcard url_pattern;
3461  int64 timestamp_ms;
3462  bool ignores_metadata_and_pcache;
3463  };
3464 
3465  typedef std::vector<UrlCacheInvalidationEntry*>
3466  UrlCacheInvalidationEntryVector;
3467  typedef dense_hash_map<GoogleString, int64> UrlCacheInvalidationMap;
3468 
3472  typedef rde::hash_map<StringPiece, const PropertyBase*,
3473  CaseFoldStringPieceHash, 6,
3474  CaseFoldStringPieceEqual> PropertyNameMap;
3475 
3488  template<class OptionClass>
3489  static void AddRequestProperty(typename OptionClass::ValueType default_value,
3490  OptionClass RewriteOptions::*offset,
3491  const char* id, bool safe_to_print) {
3492  AddProperty(default_value, offset, id, kNullOption, kProcessScopeStrict,
3493  NULL, safe_to_print, properties_);
3494  }
3495 
3498  template<class OptionClass>
3499  static void AddBaseProperty(typename OptionClass::ValueType default_value,
3500  OptionClass RewriteOptions::*offset,
3501  const char* id,
3502  StringPiece option_name,
3503  OptionScope scope,
3504  const char* help,
3505  bool safe_to_print) {
3506  AddProperty(default_value, offset, id, option_name, scope, help,
3507  safe_to_print, properties_);
3508  }
3509 
3510  static void AddProperties();
3511  bool AddCommaSeparatedListToFilterSetState(
3512  const StringPiece& filters, FilterSet* set, MessageHandler* handler);
3513  static bool AddCommaSeparatedListToFilterSet(
3514  const StringPiece& filters, FilterSet* set, MessageHandler* handler);
3516  static void InitFilterIdToEnumArray();
3517  static void InitOptionIdToPropertyArray();
3518  static void InitOptionNameToPropertyArray();
3521  static void InitFixedResourceHeaders();
3522 
3526  OptionSettingResult FormatSetOptionMessage(
3527  OptionSettingResult result, StringPiece name, StringPiece value,
3528  StringPiece error_detail, GoogleString* msg);
3529 
3532  OptionSettingResult SetOptionFromNameInternal(
3533  StringPiece name, StringPiece value, OptionScope max_scope,
3534  GoogleString* error_detail);
3535 
3538  static GoogleString OptionSignature(bool x, const Hasher* hasher) {
3539  return x ? "T" : "F";
3540  }
3541  static GoogleString OptionSignature(int x, const Hasher* hasher) {
3542  return IntegerToString(x);
3543  }
3544  static GoogleString OptionSignature(int64 x, const Hasher* hasher) {
3545  return Integer64ToString(x);
3546  }
3547  static GoogleString OptionSignature(const GoogleString& x,
3548  const Hasher* hasher);
3549  static GoogleString OptionSignature(RewriteLevel x,
3550  const Hasher* hasher);
3551  static GoogleString OptionSignature(ResourceCategorySet x,
3552  const Hasher* hasher);
3553  static GoogleString OptionSignature(const BeaconUrl& beacon_url,
3554  const Hasher* hasher);
3555  static GoogleString OptionSignature(const MobTheme& mob_theme,
3556  const Hasher* hasher);
3557  static GoogleString OptionSignature(const ResponsiveDensities& densities,
3558  const Hasher* hasher);
3559  static GoogleString OptionSignature(const AllowVaryOn& allow_vary_on,
3560  const Hasher* hasher);
3561  static GoogleString OptionSignature(
3562  const protobuf::MessageLite& proto,
3563  const Hasher* hasher);
3564 
3567  static GoogleString ToString(bool x) {
3568  return x ? "True" : "False";
3569  }
3570  static GoogleString ToString(int x) {
3571  return IntegerToString(x);
3572  }
3573  static GoogleString ToString(int64 x) {
3574  return Integer64ToString(x);
3575  }
3576  static GoogleString ToString(const GoogleString& x) {
3577  return x;
3578  }
3579  static GoogleString ToString(RewriteLevel x);
3580  static GoogleString ToString(const ResourceCategorySet &x);
3581  static GoogleString ToString(const BeaconUrl& beacon_url);
3582  static GoogleString ToString(const MobTheme& mob_theme);
3583  static GoogleString ToString(const Color& color);
3584  static GoogleString ToString(const ResponsiveDensities& densities);
3585  static GoogleString ToString(const protobuf::MessageLite& proto);
3586  static GoogleString ToString(const AllowVaryOn& allow_vary_on);
3587 
3590  static bool PropertyLessThanByOptionName(PropertyBase* p1, PropertyBase* p2) {
3591  return StringCaseCompare(p1->option_name(), p2->option_name()) < 0;
3592  }
3593 
3595  static bool OptionNameLessThanArg(OptionBase* option, StringPiece arg) {
3596  return StringCaseCompare(option->option_name(), arg) < 0;
3597  }
3598 
3600  static bool CompareUrlCacheInvalidationEntry(UrlCacheInvalidationEntry* e1,
3601  UrlCacheInvalidationEntry* e2) {
3602  return e1->timestamp_ms < e2->timestamp_ms;
3603  }
3604 
3606  static bool FilterEnumToIdAndNameEntryLessThanById(
3607  const FilterEnumToIdAndNameEntry* e1,
3608  const FilterEnumToIdAndNameEntry* e2) {
3609  return strcmp(e1->filter_id, e2->filter_id) < 0;
3610  }
3611 
3614  static StringPiece GetEffectiveOptionName(StringPiece name);
3615 
3619  bool CheckLevelSpecificOption(RewriteLevel rewrite_level,
3620  const Option<bool>& option) const;
3621 
3624  bool CheckBandwidthOption(const Option<bool>& option) const {
3625  return CheckLevelSpecificOption(kOptimizeForBandwidth, option);
3626  }
3627 
3630  bool CheckMobilizeFiltersOption(const Option<bool>& option) const {
3631  return CheckLevelSpecificOption(kMobilizeFilters, option);
3632  }
3633 
3640  MergeOverride ComputeMergeOverride(
3641  Filter filter,
3642  const Option<bool>& src_preserve_option,
3643  const Option<bool>& preserve_option,
3644  const RewriteOptions& src);
3645 
3647  void ApplyMergeOverride(
3648  MergeOverride merge_override,
3649  Filter filter,
3650  Option<bool>* preserve_option);
3651 
3652  bool modified_;
3653  bool frozen_;
3654  FilterSet enabled_filters_;
3655  FilterSet disabled_filters_;
3656  FilterSet forbidden_filters_;
3657 
3663  Option<RewriteLevel> level_;
3664 
3667  UrlCacheInvalidationEntryVector url_cache_invalidation_entries_;
3668 
3675  CopyOnWrite<PurgeSet> purge_set_ GUARDED_BY(cache_purge_mutex_);
3676 
3677  scoped_ptr<ThreadSystem::RWLock> cache_purge_mutex_;
3678  Option<int64> css_flatten_max_bytes_;
3679  Option<bool> cache_small_images_unrewritten_;
3680  Option<bool> no_transform_optimized_images_;
3681 
3683  Option<int64> image_resolution_limit_bytes_;
3684  Option<int64> css_image_inline_max_bytes_;
3685  Option<int64> css_inline_max_bytes_;
3686  Option<int64> css_outline_min_bytes_;
3687  Option<int64> google_font_css_inline_max_bytes_;
3688 
3690  Option<bool> css_preserve_urls_;
3691  Option<bool> js_preserve_urls_;
3692  Option<bool> image_preserve_urls_;
3693 
3694  Option<int64> image_inline_max_bytes_;
3695  Option<int64> js_inline_max_bytes_;
3696  Option<int64> js_outline_min_bytes_;
3697  Option<int64> progressive_jpeg_min_bytes_;
3699  Option<int64> max_html_cache_time_ms_;
3702  Option<int64> max_html_parse_bytes_;
3704  Option<int64> min_resource_cache_time_to_rewrite_ms_;
3705  Option<int64> idle_flush_time_ms_;
3706  Option<int64> flush_buffer_limit_bytes_;
3707 
3711  Option<int64> blocking_fetch_timeout_ms_;
3712 
3715  Option<int64> image_recompress_quality_;
3716 
3718  Option<int64> image_jpeg_recompress_quality_;
3719  Option<int64> image_jpeg_recompress_quality_for_small_screens_;
3720  Option<int64> image_jpeg_quality_for_save_data_;
3721  Option<int64> image_jpeg_num_progressive_scans_;
3722  Option<int64> image_jpeg_num_progressive_scans_for_small_screens_;
3723 
3725  Option<int> image_limit_optimized_percent_;
3726  Option<int> image_limit_resize_area_percent_;
3727  Option<int> image_limit_rendered_area_percent_;
3728 
3730  Option<int64> image_webp_recompress_quality_;
3731  Option<int64> image_webp_recompress_quality_for_small_screens_;
3732  Option<int64> image_webp_animated_recompress_quality_;
3733  Option<int64> image_webp_quality_for_save_data_;
3734  Option<int64> image_webp_timeout_ms_;
3735 
3736  Option<int> image_max_rewrites_at_once_;
3737  Option<int> max_url_segment_size_;
3738  Option<int> max_url_size_;
3739  Option<int> rewrite_deadline_ms_;
3743  Option<int> domain_shard_count_;
3744 
3745  Option<EnabledEnum> enabled_;
3746 
3749  Option<bool> add_options_to_urls_;
3750 
3756  Option<bool> publicly_cache_mismatched_hashes_experimental_;
3757 
3759  Option<bool> in_place_rewriting_enabled_;
3761  Option<bool> in_place_wait_for_optimized_;
3764  Option<int> in_place_rewrite_deadline_ms_;
3769  Option<int> in_place_s_maxage_sec_;
3772  Option<bool> in_place_preemptive_rewrite_css_;
3774  Option<bool> in_place_preemptive_rewrite_css_images_;
3777  Option<bool> in_place_preemptive_rewrite_images_;
3780  Option<bool> in_place_preemptive_rewrite_javascript_;
3786  Option<bool> private_not_vary_for_ie_;
3787  Option<bool> combine_across_paths_;
3788  Option<bool> log_background_rewrites_;
3789  Option<bool> log_mobilization_samples_;
3790  Option<bool> log_rewrite_timing_;
3791  Option<bool> log_url_indices_;
3792  Option<bool> lowercase_html_names_;
3793  Option<bool> always_rewrite_css_;
3794  Option<bool> respect_vary_;
3795  Option<bool> respect_x_forwarded_proto_;
3796  Option<bool> flush_html_;
3799  Option<bool> follow_flushes_;
3802  Option<bool> serve_stale_if_fetch_error_;
3804  Option<bool> serve_xhr_access_control_headers_;
3807  Option<bool> proactively_freshen_user_facing_request_;
3810  Option<int64> serve_stale_while_revalidate_threshold_sec_;
3811 
3816  Option<bool> default_cache_html_;
3821  Option<bool> modify_caching_headers_;
3825  Option<bool> lazyload_images_after_onload_;
3828  Option<GoogleString> lazyload_images_blank_url_;
3831  Option<bool> use_blank_image_for_inline_preview_;
3835  Option<bool> inline_only_critical_images_;
3838  Option<bool> critical_images_beacon_enabled_;
3841  Option<bool> client_domain_rewrite_;
3844  Option<bool> domain_rewrite_cookies_;
3847  Option<bool> domain_rewrite_hyperlinks_;
3850  Option<bool> running_experiment_;
3853  Option<int> experiment_ga_slot_;
3856  Option<int> enroll_experiment_id_;
3857 
3860  Option<GoogleString> content_experiment_id_;
3861  Option<GoogleString> content_experiment_variant_id_;
3862 
3864  Option<bool> use_analytics_js_;
3865 
3868  Option<bool> increase_speed_tracking_;
3869 
3873  Option<bool> report_unload_time_;
3874 
3875  Option<bool> serve_rewritten_webp_urls_to_any_agent_;
3876 
3878  Option<bool> enable_defer_js_experimental_;
3879 
3881  Option<bool> disable_rewrite_on_no_transform_;
3882 
3884  Option<bool> disable_background_fetches_for_bots_;
3885 
3895  Option<bool> enable_cache_purge_;
3896 
3900  Option<bool> proactive_resource_freshening_;
3901 
3903  Option<bool> lazyload_highres_images_;
3904 
3907  Option<bool> avoid_renaming_introspective_javascript_;
3908 
3910  Option<bool> override_ie_document_mode_;
3911 
3913  Option<bool> test_instant_fetch_rewrite_deadline_;
3914 
3918  Option<bool> test_only_prioritize_critical_css_dont_apply_original_css_;
3919 
3925  Option<GoogleString> blocking_rewrite_key_;
3926 
3930  Option<int> beacon_reinstrument_time_sec_;
3931 
3934  Option<int> max_inlined_preview_images_index_;
3936  Option<int64> min_image_size_low_resolution_bytes_;
3938  Option<int64> max_image_size_low_resolution_bytes_;
3941  Option<int> rewrite_random_drop_percentage_;
3942 
3945  Option<bool> oblivious_pagespeed_urls_;
3946 
3950  Option<int64> finder_properties_cache_expiration_time_ms_;
3951 
3955  Option<int64> finder_properties_cache_refresh_time_ms_;
3958  Option<int64> experiment_cookie_duration_ms_;
3959 
3962  Option<int64> metadata_cache_staleness_threshold_ms_;
3963 
3965  Option<int64> metadata_input_errors_cache_ttl_ms_;
3966 
3969  Option<GoogleString> downstream_cache_purge_method_;
3970 
3972  Option<GoogleString> downstream_cache_purge_location_prefix_;
3973 
3976  Option<GoogleString> downstream_cache_rebeaconing_key_;
3977 
3983  Option<int64> downstream_cache_rewritten_percentage_threshold_;
3984 
3988  Option<int64> implicit_cache_ttl_ms_;
3989 
3994  Option<int64> load_from_file_cache_ttl_ms_;
3995 
3997  Option<int64> max_cacheable_response_content_length_;
3998 
4000  Option<bool> preserve_subresource_hints_;
4001 
4004  Option<bool> preserve_url_relativity_;
4005 
4006  Option<GoogleString> ga_id_;
4007 
4009  Option<bool> use_fallback_property_cache_values_;
4011  Option<bool> await_pcache_lookup_;
4013  Option<bool> enable_prioritizing_scripts_;
4015  Option<bool> rewrite_uncacheable_resources_;
4021  Option<bool> forbid_all_disabled_filters_;
4023  Option<bool> enable_aggressive_rewriters_for_mobile_;
4024 
4030  Option<bool> reject_blacklisted_;
4031  Option<int> reject_blacklisted_status_code_;
4032 
4036  Option<bool> support_noscript_enabled_;
4037 
4040  Option<bool> enable_extended_instrumentation_;
4041 
4042  Option<bool> use_experimental_js_minifier_;
4043 
4046  Option<int64> max_combined_css_bytes_;
4047 
4050  Option<int64> max_combined_js_bytes_;
4051 
4053  Option<GoogleString> pre_connect_url_;
4056  Option<int> property_cache_http_status_stability_threshold_;
4058  Option<int> max_rewrite_info_log_size_;
4059 
4064  Option<int64> override_caching_ttl_ms_;
4065  CopyOnWrite<FastWildcardGroup> override_caching_wildcard_;
4066 
4068  Option<bool> allow_logging_urls_in_log_record_;
4069 
4071  Option<bool> allow_options_to_be_set_by_cookies_;
4072 
4074  Option<GoogleString> non_cacheables_for_cache_partial_html_;
4075 
4079  Option<GoogleString> access_control_allow_origins_;
4080 
4082  Option<bool> hide_referer_using_meta_;
4083 
4088  Option<int64> max_low_res_image_size_bytes_;
4089  Option<int> max_low_res_to_full_res_image_size_percentage_;
4090 
4092  Option<GoogleString> remote_configuration_url_;
4094  Option<int64> remote_configuration_timeout_ms_;
4095 
4097  Option<int> http_cache_compression_level_;
4098 
4100  Option<GoogleString> request_option_override_;
4101 
4103  Option<GoogleString> url_signing_key_;
4104 
4106  Option<bool> accept_invalid_signatures_;
4107 
4112  Option<GoogleString> sticky_query_parameters_;
4113  Option<int64> option_cookies_duration_ms_;
4114 
4116  Option<ResponsiveDensities> responsive_image_densities_;
4117 
4122  Option<GoogleString> amp_link_pattern_;
4123 
4125  Option<bool> honor_csp_;
4126 
4129  CacheFragmentOption cache_fragment_;
4130 
4133  OptionBaseVector all_options_;
4134  size_t initialized_options_;
4135 
4138  static const FilterEnumToIdAndNameEntry* filter_id_to_enum_array_[
4139  kEndOfFilters];
4140 
4142  static PropertyNameMap* option_name_to_property_map_;
4143 
4145  static const PropertyBase** option_id_to_property_array_;
4146 
4153  bool options_uniqueness_checked_;
4154 
4155  bool need_to_store_experiment_data_;
4156  int experiment_id_;
4157  int experiment_percent_;
4158  std::vector<ExperimentSpec*> experiment_specs_;
4159 
4164  std::vector<NameValue*> resource_headers_;
4165 
4167  std::vector<NameValue*> custom_fetch_headers_;
4168 
4171  scoped_ptr<std::vector<ElementAttributeCategory> > url_valued_attributes_;
4172 
4173  Option<ResourceCategorySet> inline_unauthorized_resource_types_;
4174 
4175  Option<int64> noop_;
4176 
4178  Option<AllowVaryOn> allow_vary_on_;
4179 
4180  CopyOnWrite<JavascriptLibraryIdentification>
4181  javascript_library_identification_;
4182 
4183  CopyOnWrite<DomainLawyer> domain_lawyer_;
4184  FileLoadPolicy file_load_policy_;
4185 
4186  CopyOnWrite<FastWildcardGroup> allow_resources_;
4187  CopyOnWrite<FastWildcardGroup> allow_when_inlining_resources_;
4188  CopyOnWrite<FastWildcardGroup> retain_comments_;
4189  CopyOnWrite<FastWildcardGroup> lazyload_enabled_classes_;
4190  CopyOnWrite<FastWildcardGroup> css_combining_permitted_ids_;
4191 
4194  CopyOnWrite<FastWildcardGroup> blocking_rewrite_referer_urls_;
4195 
4198  typedef std::map<StringPiece, FastWildcardGroup*> FastWildcardGroupMap;
4199  FastWildcardGroupMap rejected_request_map_;
4200 
4201  GoogleString signature_;
4202  MD5Hasher hasher_;
4203  SHA1Signature sha1signature_;
4204 
4205  ThreadSystem* thread_system_;
4206 
4219  scoped_ptr<ThreadSystem::ThreadId> last_thread_id_;
4220 
4221 
4222 };
4223 
4224 }
4225 
4226 #endif
void set_experiment_ga_slot(int x)
x should be between 1 and 5 inclusive.
Definition: rewrite_options.h:2477
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:575
EnabledEnum
Definition: rewrite_options.h:226
bool AdjustFiltersByCommaSeparatedList(const StringPiece &filters, MessageHandler *handler)
static const int64 kDefaultMaxCombinedCssBytes
Default maximum size of the combined CSS resource.
Definition: rewrite_options.h:901
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:3167
bool ClearSignatureForTesting()
Definition: rewrite_options.h:2945
bool IsRetainedComment(StringPiece comment) const
Definition: rewrite_options.h:2833
int64 idle_flush_time_ms() const
Definition: rewrite_options.h:1785
static bool Initialize(Properties **properties)
bool MatchesDownstreamCacheRebeaconingKey(StringPiece key) const
Definition: rewrite_options.h:2257
customized at directory level (.htaccess, <Directory>)
Definition: rewrite_options.h:632
Implementation class of Signature, using HMAC-SHA1 for signing.
Definition: sha1_signature.h:32
Definition: rewrite_options.h:630
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:2921
static const int kDefaultMaxUrlSize
Definition: rewrite_options.h:865
static const int64 kDefaultExperimentCookieDurationMs
Definition: rewrite_options.h:894
void set_downstream_cache_purge_location_prefix(StringPiece p)
Definition: rewrite_options.h:2234
Definition: rewrite_options.h:493
Maps a filter's enum (kAddHead) to its id ("ah") and name ("Add Head").
Definition: rewrite_options.h:1116
void AddResourceHeader(const StringPiece &name, const StringPiece &value)
Definition: rewrite_options.h:750
bool OptionValue(StringPiece option_name, const char **id, bool *was_set, GoogleString *value) const
Definition: rewrite_options.h:235
static bool Terminate(Properties **properties_handle)
void AddOverrideCacheTtl(StringPiece wildcard)
Definition: rewrite_options.h:2871
Definition: rewrite_options.h:637
int max_url_segment_size() const
Definition: rewrite_options.h:1803
bool InsertExperimentSpecInVector(ExperimentSpec *spec)
bool ImageOptimizationEnabled() const
static bool LooksLikeValidHost(const StringPiece &s)
std::pair< GoogleString, GoogleString > OptionStringPair
Definition: rewrite_options.h:690
Definition: rewrite_options.h:3137
Definition: rewrite_options.h:3046
virtual void InitializeOption(RewriteOptions *options) const
Definition: rewrite_options.h:3332
virtual void DisallowTroublesomeResources()
static const char kAcceptInvalidSignatures[]
Definition: rewrite_options.h:247
static const char kCacheFlushFilename[]
Definition: rewrite_options.h:432
static const char kNoneString[]
Strings for display.
Definition: rewrite_options.h:510
void Allow(StringPiece wildcard_pattern)
Definition: rewrite_options.h:2737
OptionClass RewriteOptionsSubclass::* OptionOffset
Definition: rewrite_options.h:3321
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:2278
Definition: signature.h:42
Option< BeaconUrl > beacon_url_
Protected option values so that derived class can modify.
Definition: rewrite_options.h:3252
void DisableAllFilters()
Set rewrite level to kPassThrough and explicitly disable all filters.
static bool IsDeprecatedOptionName(StringPiece option_name)
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
bool StringToInt(const char *in, int *out)
Definition: string_util.h:94
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:107
static const int kDefaultExperimentSlot
Default Custom Variable slot in which to put Experiment information.
Definition: rewrite_options.h:908
Definition: rewrite_options.h:695
void Modify()
Marks the config as modified.
virtual RewriteOptions * Clone() const
Definition: rewrite_options.h:504
int64 flush_buffer_limit_bytes() const
How much accumulated HTML will result in PSA introducing a flush.
Definition: rewrite_options.h:1793
Definition: rewrite_options.h:238
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:2800
Definition: rewrite_options.h:474
void InitializeOption(RewriteOptions *options) const override
Definition: rewrite_options.h:3270
Definition: rewrite_options.h:507
void set_cache_invalidation_timestamp_mutex(ThreadSystem::RWLock *lock)
Definition: rewrite_options.h:1747
static void MergeSubclassProperties(Properties *properties)
void set_domain_shard_count(int64 x)
Definition: rewrite_options.h:1843
int64 css_outline_min_bytes() const
Definition: rewrite_options.h:1544
void DisableFiltersRequiringScriptExecution()
Disables all filters that depend on executing custom javascript.
bool IsAllowedWhenInlining(StringPiece url) const
Definition: rewrite_options.h:2819
void set_global_default(const T &val)
Definition: rewrite_options.h:3107
static const char kImageJpegNumProgressiveScans[]
Definition: rewrite_options.h:306
bool IsUrlCacheInvalidationEntriesSorted() const
static const int64 kDefaultMetadataCacheStalenessThresholdMs
Definition: rewrite_options.h:898
virtual GoogleString ToExperimentString() const
static const int kOptionsVersion
Definition: rewrite_options.h:615
void MergeHelper(const OptionTemplateBase *src)
Definition: rewrite_options.h:3078
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:2758
std::vector< OptionBase * > OptionBaseVector
Convenience name for a set of rewrite options.
Definition: rewrite_options.h:775
OptionScope
Definition: rewrite_options.h:629
Definition: rewrite_options.h:487
void set_default_x_header_value(StringPiece x_header_value)
Definition: rewrite_options.h:3234
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:888
bool RegisterLibrary(SizeInBytes bytes, StringPiece md5_hash, StringPiece canonical_url)
Represents the content type of user-defined url-valued attributes.
Definition: rewrite_options.h:1045
Option< GoogleString > x_header_value_
The value we put for the X-Mod-Pagespeed header. Default is our version.
Definition: rewrite_options.h:3255
void set_option(const T &new_value, OptionTemplateBase< T > *option)
Definition: rewrite_options.h:3219
static bool AddCommaSeparatedListToOptionSet(const StringPiece &options, OptionSet *set, MessageHandler *handler)
int max_url_size() const
The maximum size of the entire URL. If '0', this is left unlimited.
Definition: rewrite_options.h:1816
virtual OptionSettingResult ParseAndSetOptionFromName1(StringPiece name, StringPiece arg, GoogleString *msg, MessageHandler *handler)
Definition: rewrite_options.h:1057
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
static GoogleString QuoteHostPort(const GoogleString &in)
Definition: rewrite_options.h:924
void DoNotUseForSignatureComputation()
Definition: rewrite_options.h:3120
used while developing proper HTTP2 features.
Definition: rewrite_options.h:138
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.
Definition: thread_system.h:61
virtual bool SetFromString(StringPiece value_string, GoogleString *error_detail)=0
static const int kDefaultMaxInlinedPreviewImagesIndex
Definition: rewrite_options.h:880
void DisallowWhenInlining(StringPiece wildcard_pattern)
Like Disallow(). See IsAllowedWhenInlining().
Definition: rewrite_options.h:2764
static const char kAllow[]
Options that require special handling, e.g. non-scalar values.
Definition: rewrite_options.h:403
void set_property(const Property< T > *property)
The static properties of an Option are held in a Property<T>*.
Definition: rewrite_options.h:3088
static const char kAddResourceHeader[]
2-argument ones:
Definition: rewrite_options.h:417
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:1314
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:3021
static const int64 kDefaultMaxCombinedJsBytes
Default maximum size of the combined js resource generated by JsCombiner.
Definition: rewrite_options.h:904
std::set< GoogleString > FilterIdSet
Convenience name for a set of rewrite filter ids.
Definition: rewrite_options.h:678
Definition: rewrite_options.h:633
bool SetOptionFromNameAndLog(StringPiece name, StringPiece value, MessageHandler *handler)
static void CombineQuotedHostPort(StringPieceVector *vec, size_t first_pos, GoogleString *combined_container)
static const char kLibrary[]
3-argument ones:
Definition: rewrite_options.h:428
virtual void Merge(const RewriteOptions &src)
void SetDefaultRewriteLevel(RewriteLevel level)
Definition: rewrite_options.h:1180
void PurgeUrl(StringPiece url, int64 timestamp_ms)
Purge a cache entry for an exact URL, not a wildcard.
GoogleString SafeEnabledOptionsToString() const
bool IsLazyloadEnabledForClassName(StringPiece class_name) const
Checks if lazyload images is enabled for the specified class.
Definition: rewrite_options.h:2844
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:2750
const OptionBaseVector & all_options() const
Definition: rewrite_options.h:3007
Filter
Definition: rewrite_options.h:106
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:232
Definition: rewrite_options.h:91
static const int kDefaultMaxUrlSegmentSize
Definition: rewrite_options.h:873
void DisableLazyloadForClassName(StringPiece class_name)
Adds a new class name for which lazyload should be disabled.
Definition: rewrite_options.h:2838
virtual void SetRequiredExperimentFilters()
Enables filters needed by Experiment regardless of experiment.
void MergeOnlyProcessScopeOptions(const RewriteOptions &src)
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:3285
static const int kDefaultRewriteDeadlineMs
Default time to wait for rewrite before returning original resource.
Definition: rewrite_options.h:876
void AddCssCombiningWildcard(StringPiece id_wildcard)
Adds a new comment wildcard pattern to be retained.
Definition: rewrite_options.h:2849
bool NeedsDependenciesCohort() const
void InitializeOptions(const Properties *properties)
Definition: rewrite_options.h:90
Definition: rewrite_options.h:3260
int StringCaseCompare(StringPiece s1, StringPiece s2)
Case-insensitive string comparison that is locale-independent.
bool IsCacheTtlOverridden(StringPiece url) const
Is the cache TTL overridden for the given url?
Definition: rewrite_options.h:2877
static const int64 kDefaultMaxImageSizeLowResolutionBytes
Definition: rewrite_options.h:886
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:3142
Definition: copy_on_write.h:34
Definition: thread_system.h:40
OptionSettingResult
Used for return value of SetOptionFromName.
Definition: rewrite_options.h:813
bool StringToDouble(const char *in, double *out)
static const int64 kDefaultMinImageSizeLowResolutionBytes
Definition: rewrite_options.h:883
Definition: message_handler.h:39
Customized at process level and enforced as such.
Definition: rewrite_options.h:640
static Filter LookupFilterById(const StringPiece &filter_id)
DeviceType
Definition: user_agent_matcher.h:49
Definition: rewrite_options.h:481
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:465
Definition: rewrite_options.h:230
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:784
void Disallow(StringPiece wildcard_pattern)
Definition: rewrite_options.h:2744
OptionSettingResult SetOptionFromRemoteConfig(StringPiece name, StringPiece value)
bool IsAllowed(StringPiece url) const
Definition: rewrite_options.h:2808
const JavascriptLibraryIdentification * javascript_library_identification() const
Definition: rewrite_options.h:1322
bool ForbidFiltersByCommaSeparatedList(const StringPiece &filters, MessageHandler *handler)
Definition: rewrite_options.h:796
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:946
void Merge(const ExperimentSpec &spec)
Definition: thread_system.h:89
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:169
RewriteLevel
Definition: rewrite_options.h:779
Definition: rewrite_options.h:805
const GoogleString & signature() const
Returns the computed signature.
Definition: rewrite_options.h:2952
bool UsePerOriginPropertyCachePage() const
int size() const
Returns the number of properties.
Definition: rewrite_options.h:1080
Definition: rewrite_options.h:800
void set_option_at(int index, OptionBase *option)
Definition: rewrite_options.h:3211
bool has_cache_invalidation_timestamp_ms() const
static const int64 kDefaultFinderPropertiesCacheRefreshTimeMs
Default cache refresh value for finder properties in pcache.
Definition: rewrite_options.h:890
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:618
static bool ParseFromString(StringPiece value_string, bool *value)
Definition: hasher.h:30
static const int kCachePurgeBytes
Number of bytes capacity in the URL invalidation set.
Definition: rewrite_options.h:621
virtual void Merge(const OptionBase *src)
Definition: rewrite_options.h:3073
bool HasValidSaveDataQualities() const
Definition: rewrite_options.h:809
static const Filter kFirstFilter
Used for enumerating over all entries in the Filter enum.
Definition: rewrite_options.h:672
void DisableFiltersThatCantRunInAjax()
Disables all filters that cannot be run in an Ajax call.
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:2188
void RetainComment(StringPiece comment)
Adds a new comment wildcard pattern to be retained.
Definition: rewrite_options.h:2825