This repository has been archived by the owner on Apr 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 156
/
Copy pathrewrite_options.cc
5099 lines (4687 loc) · 210 KB
/
rewrite_options.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "net/instaweb/rewriter/public/rewrite_options.h"
#include <algorithm>
#include <cstddef>
#include <memory>
#include <new>
#include <set>
#include <utility>
#include "base/logging.h"
#include "net/instaweb/rewriter/public/domain_lawyer.h"
#include "net/instaweb/rewriter/public/experiment_util.h"
#include "net/instaweb/rewriter/public/file_load_policy.h"
#include "pagespeed/kernel/base/abstract_mutex.h"
#include "pagespeed/kernel/base/base64_util.h"
#include "pagespeed/kernel/base/basictypes.h"
#include "pagespeed/kernel/base/dynamic_annotations.h" // RunningOnValgrind
#include "pagespeed/kernel/base/hasher.h"
#include "pagespeed/kernel/base/message_handler.h"
#include "pagespeed/kernel/base/null_message_handler.h"
#include "pagespeed/kernel/base/null_rw_lock.h"
#include "pagespeed/kernel/base/stl_util.h"
#include "pagespeed/kernel/base/time_util.h"
#include "pagespeed/kernel/base/timer.h"
#include "pagespeed/kernel/cache/purge_set.h"
#include "pagespeed/kernel/http/google_url.h"
#include "pagespeed/kernel/http/http_options.h"
#include "pagespeed/kernel/http/request_headers.h"
#include "pagespeed/kernel/http/semantic_type.h"
#include "pagespeed/kernel/http/user_agent_matcher.h"
namespace net_instaweb {
// Option names.
// TODO(matterbury): Evaluate these filters to check which ones aren't global,
// rather are (say) Apache specific, and move them out.
// TODO(jmarantz): Use consistent naming from semantic_type.h for all option
// names that reference css/styles/js/scripts etc. such as CssPreserveUrls.
const char RewriteOptions::kAddOptionsToUrls[] = "AddOptionsToUrls";
const char RewriteOptions::kAcceptInvalidSignatures[] =
"AcceptInvalidSignatures";
const char RewriteOptions::kAccessControlAllowOrigins[] =
"AccessControlAllowOrigins";
const char RewriteOptions::kAllowLoggingUrlsInLogRecord[] =
"AllowLoggingUrlsInLogRecord";
const char RewriteOptions::kAllowOptionsToBeSetByCookies[] =
"AllowOptionsToBeSetByCookies";
const char RewriteOptions::kAlwaysRewriteCss[] = "AlwaysRewriteCss";
const char RewriteOptions::kAmpLinkPattern[] = "AmpLinkPattern";
const char RewriteOptions::kAnalyticsID[] = "AnalyticsID";
const char RewriteOptions::kAvoidRenamingIntrospectiveJavascript[] =
"AvoidRenamingIntrospectiveJavascript";
const char RewriteOptions::kAwaitPcacheLookup[] = "AwaitPcacheLookup";
const char RewriteOptions::kBeaconReinstrumentTimeSec[] =
"BeaconReinstrumentTimeSec";
const char RewriteOptions::kBeaconUrl[] = "BeaconUrl";
const char RewriteOptions::kCacheFragment[] = "CacheFragment";
const char RewriteOptions::kCacheSmallImagesUnrewritten[] =
"CacheSmallImagesUnrewritten";
const char RewriteOptions::kClientDomainRewrite[] = "ClientDomainRewrite";
const char RewriteOptions::kCombineAcrossPaths[] = "CombineAcrossPaths";
const char RewriteOptions::kCompressMetadataCache[] = "CompressMetadataCache";
const char RewriteOptions::kContentExperimentID[] = "ContentExperimentID";
const char RewriteOptions::kContentExperimentVariantID[] =
"ContentExperimentVariantID";
const char RewriteOptions::kCriticalImagesBeaconEnabled[] =
"CriticalImagesBeaconEnabled";
const char RewriteOptions::kCssFlattenMaxBytes[] = "CssFlattenMaxBytes";
const char RewriteOptions::kCssImageInlineMaxBytes[] = "CssImageInlineMaxBytes";
const char RewriteOptions::kCssInlineMaxBytes[] = "CssInlineMaxBytes";
const char RewriteOptions::kCssOutlineMinBytes[] = "CssOutlineMinBytes";
const char RewriteOptions::kCssPreserveURLs[] = "CssPreserveURLs";
const char RewriteOptions::kDefaultCacheHtml[] = "DefaultCacheHtml";
const char RewriteOptions::kDisableRewriteOnNoTransform[] =
"DisableRewriteOnNoTransform";
const char RewriteOptions::kDisableBackgroundFetchesForBots[] =
"DisableBackgroundFetchesForBots";
const char RewriteOptions::kDomainRewriteCookies[] = "DomainRewriteCookies";
const char RewriteOptions::kDomainRewriteHyperlinks[] =
"DomainRewriteHyperlinks";
const char RewriteOptions::kDomainShardCount[] = "DomainShardCount";
const char RewriteOptions::kDownstreamCachePurgeMethod[] =
"DownstreamCachePurgeMethod";
const char RewriteOptions::kDownstreamCacheRebeaconingKey[] =
"DownstreamCacheRebeaconingKey";
const char RewriteOptions::kDownstreamCacheRewrittenPercentageThreshold[] =
"DownstreamCacheRewrittenPercentageThreshold";
const char RewriteOptions::kEnableAggressiveRewritersForMobile[] =
"EnableAggressiveRewritersForMobile";
const char RewriteOptions::kEnableDeferJsExperimental[] =
"EnableDeferJsExperimental";
const char RewriteOptions::kEnableCachePurge[] = "EnableCachePurge";
const char RewriteOptions::kEnableExtendedInstrumentation[] =
"EnableExtendedInstrumentation";
const char RewriteOptions::kEnableLazyLoadHighResImages[] =
"EnableLazyLoadHighResImages";
const char RewriteOptions::kEnablePrioritizingScripts[] =
"EnablePrioritizingScripts";
const char RewriteOptions::kEnabled[] = "EnableRewriting";
const char RewriteOptions::kEnrollExperiment[] = "EnrollExperiment";
const char RewriteOptions::kExperimentCookieDurationMs[] =
"ExperimentCookieDurationMs";
const char RewriteOptions::kExperimentSlot[] = "ExperimentSlot";
const char RewriteOptions::kFetcherProxy[] = "FetchProxy";
const char RewriteOptions::kFinderPropertiesCacheExpirationTimeMs[] =
"FinderPropertiesCacheExpirationTimeMs";
const char RewriteOptions::kFinderPropertiesCacheRefreshTimeMs[] =
"FinderPropertiesCacheRefreshTimeMs";
const char RewriteOptions::kFlushBufferLimitBytes[] = "FlushBufferLimitBytes";
const char RewriteOptions::kFlushHtml[] = "FlushHtml";
const char RewriteOptions::kFollowFlushes[] = "FollowFlushes";
const char RewriteOptions::kForbidAllDisabledFilters[] =
"ForbidAllDisabledFilters";
const char RewriteOptions::kGoogleFontCssInlineMaxBytes[] =
"GoogleFontCssInlineMaxBytes";
const char RewriteOptions::kHideRefererUsingMeta[] = "HideRefererUsingMeta";
const char RewriteOptions::kHttpCacheCompressionLevel[] =
"HttpCacheCompressionLevel";
const char RewriteOptions::kHonorCsp[] = "HonorCsp";
const char RewriteOptions::kIdleFlushTimeMs[] = "IdleFlushTimeMs";
const char RewriteOptions::kImageInlineMaxBytes[] = "ImageInlineMaxBytes";
const char RewriteOptions::kImageJpegNumProgressiveScans[] =
"ImageJpegNumProgressiveScans";
const char RewriteOptions::kImageJpegNumProgressiveScansForSmallScreens[] =
"ImageJpegNumProgressiveScansForSmallScreens";
const char RewriteOptions::kImageJpegRecompressionQuality[] =
"JpegRecompressionQuality";
const char RewriteOptions::kImageJpegRecompressionQualityForSmallScreens[] =
"JpegRecompressionQualityForSmallScreens";
const char RewriteOptions::kImageJpegQualityForSaveData[] =
"JpegQualityForSaveData";
const char RewriteOptions::kImageLimitOptimizedPercent[] =
"ImageLimitOptimizedPercent";
const char RewriteOptions::kImageLimitRenderedAreaPercent[] =
"ImageLimitRenderedAreaPercent";
const char RewriteOptions::kImageLimitResizeAreaPercent[] =
"ImageLimitResizeAreaPercent";
const char RewriteOptions::kImageMaxRewritesAtOnce[] = "ImageMaxRewritesAtOnce";
const char RewriteOptions::kImagePreserveURLs[] = "ImagePreserveURLs";
const char RewriteOptions::kImageRecompressionQuality[] =
"ImageRecompressionQuality";
const char RewriteOptions::kImageResolutionLimitBytes[] =
"ImageResolutionLimitBytes";
const char RewriteOptions::kImageWebpRecompressionQuality[] =
"WebpRecompressionQuality";
const char RewriteOptions::kImageWebpRecompressionQualityForSmallScreens[] =
"WebpRecompressionQualityForSmallScreens";
const char RewriteOptions::kImageWebpAnimatedRecompressionQuality[] =
"WebpAnimatedRecompressionQuality";
const char RewriteOptions::kImageWebpQualityForSaveData[] =
"WebpQualityForSaveData";
const char RewriteOptions::kImageWebpTimeoutMs[] = "WebpTimeoutMs";
const char RewriteOptions::kImplicitCacheTtlMs[] = "ImplicitCacheTtlMs";
const char RewriteOptions::kInPlaceResourceOptimization[] =
"InPlaceResourceOptimization";
const char RewriteOptions::kInPlaceSMaxAgeSec[] = "InPlaceSMaxAgeSec";
const char RewriteOptions::kInPlaceWaitForOptimized[] =
"InPlaceWaitForOptimized";
const char RewriteOptions::kInPlacePreemptiveRewriteCss[] =
"InPlacePreemptiveRewriteCss";
const char RewriteOptions::kInPlacePreemptiveRewriteCssImages[] =
"InPlacePreemptiveRewriteCssImages";
const char RewriteOptions::kInPlacePreemptiveRewriteImages[] =
"InPlacePreemptiveRewriteImages";
const char RewriteOptions::kInPlacePreemptiveRewriteJavascript[] =
"InPlacePreemptiveRewriteJavascript";
const char RewriteOptions::kInPlaceRewriteDeadlineMs[] =
"InPlaceRewriteDeadlineMs";
const char RewriteOptions::kIncreaseSpeedTracking[] = "IncreaseSpeedTracking";
const char RewriteOptions::kInlineOnlyCriticalImages[] =
"InlineOnlyCriticalImages";
const char RewriteOptions::kJsInlineMaxBytes[] = "JsInlineMaxBytes";
const char RewriteOptions::kJsOutlineMinBytes[] = "JsOutlineMinBytes";
const char RewriteOptions::kJsPreserveURLs[] = "JsPreserveURLs";
const char RewriteOptions::kLazyloadImagesAfterOnload[] =
"LazyloadImagesAfterOnload";
const char RewriteOptions::kLazyloadImagesBlankUrl[] = "LazyloadImagesBlankUrl";
const char RewriteOptions::kLoadFromFileCacheTtlMs[] = "LoadFromFileCacheTtlMs";
const char RewriteOptions::kLogBackgroundRewrite[] = "LogBackgroundRewrite";
const char RewriteOptions::kLogMobilizationSamples[] = "LogMobilizationSamples";
const char RewriteOptions::kLogRewriteTiming[] = "LogRewriteTiming";
const char RewriteOptions::kLogUrlIndices[] = "LogUrlIndices";
const char RewriteOptions::kLowercaseHtmlNames[] = "LowercaseHtmlNames";
const char RewriteOptions::kMaxCacheableResponseContentLength[] =
"MaxCacheableContentLength";
const char RewriteOptions::kMaxCombinedCssBytes[] = "MaxCombinedCssBytes";
const char RewriteOptions::kMaxCombinedJsBytes[] = "MaxCombinedJsBytes";
const char RewriteOptions::kMaxHtmlCacheTimeMs[] = "MaxHtmlCacheTimeMs";
const char RewriteOptions::kMaxHtmlParseBytes[] = "MaxHtmlParseBytes";
const char RewriteOptions::kMaxImageSizeLowResolutionBytes[] =
"MaxImageSizeLowResolutionBytes";
const char RewriteOptions::kMaxInlinedPreviewImagesIndex[] =
"MaxInlinedPreviewImagesIndex";
const char RewriteOptions::kMaxLowResImageSizeBytes[] =
"MaxLowResImageSizeBytes";
const char RewriteOptions::kMaxLowResToHighResImageSizePercentage[] =
"MaxLowResToHighResImageSizePercentage";
const char RewriteOptions::kMaxRewriteInfoLogSize[] = "MaxRewriteInfoLogSize";
const char RewriteOptions::kMaxUrlSegmentSize[] = "MaxSegmentLength";
const char RewriteOptions::kMaxUrlSize[] = "MaxUrlSize";
const char RewriteOptions::kMetadataCacheStalenessThresholdMs[] =
"MetadataCacheStalenessThresholdMs";
const char RewriteOptions::kMinImageSizeLowResolutionBytes[] =
"MinImageSizeLowResolutionBytes";
const char RewriteOptions::kMinResourceCacheTimeToRewriteMs[] =
"MinResourceCacheTimeToRewriteMs";
const char RewriteOptions::kModifyCachingHeaders[] = "ModifyCachingHeaders";
const char RewriteOptions::kNoop[] = "Noop";
const char RewriteOptions::kNoTransformOptimizedImages[] =
"NoTransformOptimizedImages";
const char RewriteOptions::kNonCacheablesForCachePartialHtml[] =
"NonCacheablesForCachePartialHtml";
const char RewriteOptions::kObliviousPagespeedUrls[] = "ObliviousPagespeedUrls";
const char RewriteOptions::kOptionCookiesDurationMs[] =
"OptionCookiesDurationMs";
const char RewriteOptions::kOverrideCachingTtlMs[] = "OverrideCachingTtlMs";
const char RewriteOptions::kPreserveSubresourceHints[] =
"PreserveSubresourceHints";
const char RewriteOptions::kPreserveUrlRelativity[] = "PreserveUrlRelativity";
const char RewriteOptions::kPrivateNotVaryForIE[] = "PrivateNotVaryForIE";
const char RewriteOptions::kPubliclyCacheMismatchedHashesExperimental[] =
"PubliclyCacheMismatchedHashesExperimental";
const char RewriteOptions::kProactivelyFreshenUserFacingRequest[] =
"ProactivelyFreshenUserFacingRequest";
const char RewriteOptions::kProactiveResourceFreshening[] =
"ProactiveResourceFreshening";
const char RewriteOptions::kProgressiveJpegMinBytes[] =
"ProgressiveJpegMinBytes";
const char RewriteOptions::kRejectBlacklisted[] = "RejectBlacklisted";
const char RewriteOptions::kRejectBlacklistedStatusCode[] =
"RejectBlacklistedStatusCode";
const char RewriteOptions::kReportUnloadTime[] = "ReportUnloadTime";
const char RewriteOptions::kRespectVary[] = "RespectVary";
const char RewriteOptions::kRespectXForwardedProto[] = "RespectXForwardedProto";
const char RewriteOptions::kResponsiveImageDensities[] =
"ResponsiveImageDensities";
const char RewriteOptions::kRewriteDeadlineMs[] = "RewriteDeadlinePerFlushMs";
const char RewriteOptions::kRewriteLevel[] = "RewriteLevel";
const char RewriteOptions::kRewriteRandomDropPercentage[] =
"RewriteRandomDropPercentage";
const char RewriteOptions::kRewriteUncacheableResources[] =
"RewriteUncacheableResources";
const char RewriteOptions::kRunningExperiment[] = "RunExperiment";
const char RewriteOptions::kServeStaleIfFetchError[] = "ServeStaleIfFetchError";
const char RewriteOptions::kServeStaleWhileRevalidateThresholdSec[] =
"ServeStaleWhileRevalidateThresholdSec";
const char RewriteOptions::kServeXhrAccessControlHeaders[] =
"ServeXhrAccessControlHeaders";
const char RewriteOptions::kStickyQueryParameters[] = "StickyQueryParameters";
const char RewriteOptions::kSupportNoScriptEnabled[] = "SupportNoScriptEnabled";
const char
RewriteOptions::kTestOnlyPrioritizeCriticalCssDontApplyOriginalCss[] =
"TestOnlyPrioritizeCriticalCssDontApplyOriginalCss";
const char RewriteOptions::kUseBlankImageForInlinePreview[] =
"UseBlankImageForInlinePreview";
const char RewriteOptions::kUseExperimentalJsMinifier[] =
"UseExperimentalJsMinifier";
const char RewriteOptions::kUseFallbackPropertyCacheValues[] =
"UseFallbackPropertyCacheValues";
const char RewriteOptions::kUseImageScanlineApi[] = "UseImageScanlineApi";
const char RewriteOptions::kXModPagespeedHeaderValue[] = "XHeaderValue";
const char RewriteOptions::kXPsaBlockingRewrite[] = "BlockingRewriteKey";
const char RewriteOptions::kAllow[] = "Allow";
const char RewriteOptions::kAllowVaryOn[] = "AllowVaryOn";
const char RewriteOptions::kBlockingRewriteRefererUrls[] =
"BlockingRewriteRefererUrls";
const char RewriteOptions::kDisableFilters[] = "DisableFilters";
const char RewriteOptions::kDisallow[] = "Disallow";
const char RewriteOptions::kDomain[] = "Domain";
const char RewriteOptions::kDownstreamCachePurgeLocationPrefix[] =
"DownstreamCachePurgeLocationPrefix";
const char RewriteOptions::kEnableFilters[] = "EnableFilters";
const char RewriteOptions::kExperimentVariable[] = "ExperimentVariable";
const char RewriteOptions::kExperimentSpec[] = "ExperimentSpec";
const char RewriteOptions::kForbidFilters[] = "ForbidFilters";
const char RewriteOptions::kInlineResourcesWithoutExplicitAuthorization[] =
"InlineResourcesWithoutExplicitAuthorization";
const char RewriteOptions::kRetainComment[] = "RetainComment";
const char RewriteOptions::kPermitIdsForCssCombining[] =
"PermitIdsForCssCombining";
const char RewriteOptions::kAddResourceHeader[] = "AddResourceHeader";
const char RewriteOptions::kCustomFetchHeader[] = "CustomFetchHeader";
const char RewriteOptions::kLoadFromFile[] = "LoadFromFile";
const char RewriteOptions::kLoadFromFileMatch[] = "LoadFromFileMatch";
const char RewriteOptions::kLoadFromFileRule[] = "LoadFromFileRule";
const char RewriteOptions::kLoadFromFileRuleMatch[] = "LoadFromFileRuleMatch";
const char RewriteOptions::kMapOriginDomain[] = "MapOriginDomain";
const char RewriteOptions::kMapRewriteDomain[] = "MapRewriteDomain";
const char RewriteOptions::kMapProxyDomain[] = "MapProxyDomain";
const char RewriteOptions::kShardDomain[] = "ShardDomain";
const char RewriteOptions::kUrlValuedAttribute[] = "UrlValuedAttribute";
const char RewriteOptions::kLibrary[] = "Library";
const char RewriteOptions::kCacheFlushFilename[] = "CacheFlushFilename";
const char RewriteOptions::kCacheFlushPollIntervalSec[] =
"CacheFlushPollIntervalSec";
const char RewriteOptions::kFetchHttps[] = "FetchHttps";
const char RewriteOptions::kFetcherTimeOutMs[] = "FetcherTimeOutMs";
const char RewriteOptions::kFileCacheCleanInodeLimit[] = "FileCacheInodeLimit";
const char RewriteOptions::kFileCacheCleanIntervalMs[] =
"FileCacheCleanIntervalMs";
const char RewriteOptions::kFileCacheCleanSizeKb[] = "FileCacheSizeKb";
const char RewriteOptions::kFileCachePath[] = "FileCachePath";
const char RewriteOptions::kLogDir[] = "LogDir";
const char RewriteOptions::kLruCacheByteLimit[] = "LRUCacheByteLimit";
const char RewriteOptions::kLruCacheKbPerProcess[] = "LRUCacheKbPerProcess";
const char RewriteOptions::kMemcachedServers[] = "MemcachedServers";
const char RewriteOptions::kMemcachedThreads[] = "MemcachedThreads";
const char RewriteOptions::kMemcachedTimeoutUs[] = "MemcachedTimeoutUs";
const char RewriteOptions::kProxySuffix[] = "ProxySuffix";
const char RewriteOptions::kRateLimitBackgroundFetches[] =
"RateLimitBackgroundFetches";
const char RewriteOptions::kRemoteConfigurationUrl[] = "RemoteConfigurationUrl";
const char RewriteOptions::kRemoteConfigurationTimeoutMs[] =
"RemoteConfigurationTimeoutMs";
const char RewriteOptions::kRequestOptionOverride[] = "RequestOptionOverride";
const char RewriteOptions::kServeWebpToAnyAgent[] =
"ServeRewrittenWebpUrlsToAnyAgent";
const char RewriteOptions::kSlurpDirectory[] = "SlurpDirectory";
const char RewriteOptions::kSlurpFlushLimit[] = "SlurpFlushLimit";
const char RewriteOptions::kSlurpReadOnly[] = "SlurpReadOnly";
const char RewriteOptions::kSslCertDirectory[] = "SslCertDirectory";
const char RewriteOptions::kSslCertFile[] = "SslCertFile";
const char RewriteOptions::kStatisticsEnabled[] = "Statistics";
const char RewriteOptions::kStatisticsLoggingChartsCSS[] =
"StatisticsLoggingChartsCSS";
const char RewriteOptions::kStatisticsLoggingChartsJS[] =
"StatisticsLoggingChartsJS";
const char RewriteOptions::kStatisticsLoggingEnabled[] = "StatisticsLogging";
const char RewriteOptions::kStatisticsLoggingIntervalMs[] =
"StatisticsLoggingIntervalMs";
const char RewriteOptions::kStatisticsLoggingMaxFileSizeKb[] =
"StatisticsLoggingMaxFileSizeKb";
const char RewriteOptions::kTestProxy[] = "TestProxy";
const char RewriteOptions::kTestProxySlurp[] = "TestProxySlurp";
const char RewriteOptions::kUrlSigningKey[] = "UrlSigningKey";
const char RewriteOptions::kUseAnalyticsJs[] = "UseAnalyticsJs";
const char RewriteOptions::kUseSharedMemLocking[] = "SharedMemoryLocks";
const char RewriteOptions::kNullOption[] = "";
// RewriteFilter prefixes
const char RewriteOptions::kCacheExtenderId[] = "ce";
const char RewriteOptions::kCssCombinerId[] = "cc";
const char RewriteOptions::kCssFilterId[] = "cf";
const char RewriteOptions::kCssImportFlattenerId[] = "if";
const char RewriteOptions::kCssInlineId[] = "ci";
const char RewriteOptions::kGoogleFontCssInlineId[] = "gf";
const char RewriteOptions::kImageCombineId[] = "is";
const char RewriteOptions::kImageCompressionId[] = "ic";
const char RewriteOptions::kInPlaceRewriteId[] = "aj"; // Comes from ajax.
const char RewriteOptions::kJavascriptCombinerId[] = "jc";
const char RewriteOptions::kJavascriptMinId[] = "jm";
const char RewriteOptions::kJavascriptMinSourceMapId[] = "sm";
const char RewriteOptions::kJavascriptInlineId[] = "ji";
const char RewriteOptions::kLocalStorageCacheId[] = "ls";
const char RewriteOptions::kPrioritizeCriticalCssId[] = "pr";
// TODO(jmarantz): consider merging this threshold with the image-inlining
// threshold, which is currently defaulting at 2000, so we have a single
// byte-count threshold, above which inlined resources get outlined, and
// below which outlined resources get inlined.
//
// TODO(jmarantz): user-agent-specific selection of inline threshold so that
// mobile phones are more prone to inlining.
//
// Further notes; jmaessen says:
//
// I suspect we do not want these bounds to match, and inlining for
// images is a bit more complicated because base64 encoding inflates
// the byte count of data: urls. This is a non-issue for other
// resources (there may be some weirdness with iframes I haven't
// thought about...).
//
// jmarantz says:
//
// One thing we could do, if we believe they should be conceptually
// merged, is in image_rewrite_filter you could apply the
// base64-bloat-factor before comparing against the threshold. Then
// we could use one number if we like that idea.
//
// jmaessen: For the moment, there's a separate threshold for image inline.
const int64 RewriteOptions::kDefaultCssInlineMaxBytes = 2048;
const int64 RewriteOptions::kDefaultCssFlattenMaxBytes = 1024000;
const int64 RewriteOptions::kDefaultCssImageInlineMaxBytes = 0;
const int64 RewriteOptions::kDefaultCssOutlineMinBytes = 3000;
// 3K is bigger than Roboto loader for Chrome (2.2k)
const int64 RewriteOptions::kDefaultGoogleFontCssInlineMaxBytes = 3 * 1024;
const int64 RewriteOptions::kDefaultImageInlineMaxBytes = 3072;
const int64 RewriteOptions::kDefaultJsInlineMaxBytes = 2048;
const int64 RewriteOptions::kDefaultJsOutlineMinBytes = 3000;
const int64 RewriteOptions::kDefaultProgressiveJpegMinBytes = 10240;
const int64 RewriteOptions::kDefaultMaxHtmlCacheTimeMs = 0;
const int64 RewriteOptions::kDefaultMaxHtmlParseBytes = -1;
const int64 RewriteOptions::kDefaultMinResourceCacheTimeToRewriteMs = 0;
const int64 RewriteOptions::kDefaultFlushBufferLimitBytes = 100 * 1024;
const int64 RewriteOptions::kDefaultIdleFlushTimeMs = 10;
const int64 RewriteOptions::kDefaultImplicitCacheTtlMs = 5 * Timer::kMinuteMs;
const int64 RewriteOptions::kDefaultLoadFromFileCacheTtlMs =
5 * Timer::kMinuteMs;
const int64 RewriteOptions::kDefaultMetadataInputErrorsCacheTtlMs =
5 * Timer::kMinuteMs;
const int64 RewriteOptions::kDefaultPrioritizeVisibleContentCacheTimeMs =
30 * Timer::kMinuteMs; // 30 mins.
// Limit on concurrent ongoing image rewrites.
// TODO(jmaessen): Determine a sane default for this value.
const int RewriteOptions::kDefaultImageMaxRewritesAtOnce = 8;
// IE limits URL size overall to about 2k characters. See
// http://support.microsoft.com/kb/208427/EN-US
const int RewriteOptions::kDefaultMaxUrlSize = 2083;
// Quality that needs to be used while recompressing any image type.
// If set to -1, we use source image quality parameters, and is lossless.
const int64 RewriteOptions::kDefaultImageRecompressQuality = 85;
// Jpeg quality that needs to be used while recompressing. If set to -1, we
// use the value of image_recompress_quality.
const int64 RewriteOptions::kDefaultImageJpegRecompressQuality = -1;
const int64 RewriteOptions::kDefaultImageJpegRecompressQualityForSmallScreens =
70;
// TODO(huibao): Determine proper value for kDefaultImageJpegQualityForSaveData.
const int64 RewriteOptions::kDefaultImageJpegQualityForSaveData = 50;
// Number of scans to output for jpeg images when using progressive mode. If set
// to -1, we retain all scans of a progressive jpeg.
const int64 RewriteOptions::kDefaultImageJpegNumProgressiveScans = -1;
// Percentage savings in order to retain rewritten images; these default
// to 100% so that we always attempt to resize downsized images, and
// unconditionally retain images if they save any bytes at all.
const int RewriteOptions::kDefaultImageLimitOptimizedPercent = 100;
const int RewriteOptions::kDefaultImageLimitResizeAreaPercent = 100;
// Percentage limit on image wxh reduction for the rendered dimensions to be
// stored in the property cache. This is kept at default 95 after
// some experiments."
const int RewriteOptions::kDefaultImageLimitRenderedAreaPercent = 95;
// Sets limit for image optimization to 32MB.
const int64 RewriteOptions::kDefaultImageResolutionLimitBytes =
32 * 1024 * 1024;
// WebP quality that needs to be used while recompressing. If set to -1, we
// use source image quality parameters.
const int64 RewriteOptions::kDefaultImageWebpRecompressQuality = 80;
const int64 RewriteOptions::kDefaultImageWebpRecompressQualityForSmallScreens =
70;
const int64 RewriteOptions::kDefaultImageWebpAnimatedRecompressQuality = 70;
const int64 RewriteOptions::kDefaultImageWebpQualityForSaveData = 50;
// Timeout, in ms, for all WebP conversion attempts for each source
// image. If negative, does not time out.
const int64 RewriteOptions::kDefaultImageWebpTimeoutMs = -1;
const int64 RewriteOptions::kDefaultMaxCacheableResponseContentLength =
16777216; // 16 MB in bytes
// See https://github.com/apache/incubator-pagespeed-mod/issues/9. By
// default, Apache evidently limits each URL path segment (between /)
// to about 256 characters. This is not a fundamental URL limitation
// but is Apache specific. Ben Noordhuis has provided a workaround
// of hooking map_to_storage to skip the directory-mapping phase in
// Apache. See https://github.com/apache/incubator-pagespeed-mod/issues/176
const int RewriteOptions::kDefaultMaxUrlSegmentSize = 1024;
// Expiration limit for cookies that set PageSpeed options: 10 minutes.
const int64 RewriteOptions::kDefaultOptionCookiesDurationMs = 10 * 60 * 1000;
#ifdef NDEBUG
const int RewriteOptions::kDefaultRewriteDeadlineMs = 10;
#else
const int RewriteOptions::kDefaultRewriteDeadlineMs = 20;
#endif
const int kValgrindWaitForRewriteMs = 1000;
const int RewriteOptions::kDefaultPropertyCacheHttpStatusStabilityThreshold = 5;
const int RewriteOptions::kDefaultMaxRewriteInfoLogSize = 150;
const char RewriteOptions::kDefaultBeaconUrl[] = "/mod_pagespeed_beacon";
const int RewriteOptions::kDefaultMaxInlinedPreviewImagesIndex = -1;
const int64 RewriteOptions::kDefaultMinImageSizeLowResolutionBytes = 3 * 1024;
const int64 RewriteOptions::kDefaultMaxImageSizeLowResolutionBytes =
1 * 1024 * 1024; // 1 MB.
const int64 RewriteOptions::kDefaultMaxCombinedCssBytes = -1; // No size limit
// Setting the limit on combined js resource to -1 will bypass the size check.
const int64 RewriteOptions::kDefaultMaxCombinedJsBytes = 90 * 1024;
const int64 RewriteOptions::kDefaultExperimentCookieDurationMs = Timer::kWeekMs;
const int64 RewriteOptions::kDefaultFinderPropertiesCacheExpirationTimeMs =
2 * Timer::kHourMs;
const int64 RewriteOptions::kDefaultFinderPropertiesCacheRefreshTimeMs =
(3 * Timer::kHourMs) / 2;
const int64 RewriteOptions::kDefaultMetadataCacheStalenessThresholdMs = 0;
const char RewriteOptions::kDefaultDownstreamCachePurgeMethod[] = "PURGE";
const int64
RewriteOptions::kDefaultDownstreamCacheRewrittenPercentageThreshold = 95;
const int RewriteOptions::kDefaultExperimentTrafficPercent = 50;
const int RewriteOptions::kDefaultExperimentSlot = 1;
// An empty default key indicates that the blocking rewrite feature is disabled.
const char RewriteOptions::kDefaultBlockingRewriteKey[] = "";
const char RewriteOptions::kRejectedRequestUrlKeyName[] = "RejectedUrl";
// Allow all the declared shards.
const int RewriteOptions::kDefaultDomainShardCount = 0;
// By default, rebeacon every 5 seconds in high frequency mode. This will be
// multiplied by kLowFreqBeaconMult in critical_finder_support_util.h to
// determine the low frequency rebeacon time.
const int RewriteOptions::kDefaultBeaconReinstrumentTimeSec = 5;
// By default, all images are inline-previewed irrespective of size.
const int64 RewriteOptions::kDefaultMaxLowResImageSizeBytes = -1;
// By default, all images are inline-previewed, as long as the low-res size is
// lesser than the full-res size.
const int RewriteOptions::kDefaultMaxLowResToFullResImageSizePercentage = 100;
const double RewriteOptions::kDefaultResponsiveImageDensities[] = {1.5, 2.0,
3.0};
const RewriteOptions::FilterEnumToIdAndNameEntry*
RewriteOptions::filter_id_to_enum_array_[RewriteOptions::kEndOfFilters];
RewriteOptions::PropertyNameMap* RewriteOptions::option_name_to_property_map_ =
nullptr;
const RewriteOptions::PropertyBase**
RewriteOptions::option_id_to_property_array_ = nullptr;
RewriteOptions::Properties* RewriteOptions::properties_ = nullptr;
RewriteOptions::Properties* RewriteOptions::all_properties_ = nullptr;
RewriteOptions::Properties* RewriteOptions::deprecated_properties_ = nullptr;
const char RewriteOptions::AllowVaryOn::kNoneString[] = "None";
const char RewriteOptions::AllowVaryOn::kAutoString[] = "Auto";
namespace {
// When you change this, remember to update the documentation:
// doc/en/speed/pagespeed/module/config_filters.html
// The documentation there includes the filter groups
// "rewrite_images", "extend_cache", and "rewrite_javascript", which
// expand to multiple filters, all of which need to be listed here.
// config_filters.html both includes lists of filters in each group
// and, redundantly, a table of all filters with one-liner
// documentation and which groups they are in.
const RewriteOptions::Filter kCoreFilterSet[] = {
RewriteOptions::kAddHead,
RewriteOptions::kCombineCss,
RewriteOptions::kCombineJavascript,
RewriteOptions::kConvertGifToPng, // rewrite_images
RewriteOptions::kConvertJpegToProgressive, // rewrite_images
RewriteOptions::kConvertJpegToWebp, // rewrite_images
RewriteOptions::kConvertMetaTags,
RewriteOptions::kConvertPngToJpeg, // rewrite_images
RewriteOptions::kConvertToWebpLossless, // rewrite_images
RewriteOptions::kExtendCacheCss, // extend_cache
RewriteOptions::kExtendCacheImages, // extend_cache
RewriteOptions::kExtendCacheScripts, // extend_cache
RewriteOptions::kFallbackRewriteCssUrls,
RewriteOptions::kFlattenCssImports,
RewriteOptions::kInlineCss,
RewriteOptions::kInlineImages, // rewrite_images
RewriteOptions::kInlineImportToLink,
RewriteOptions::kInlineJavascript,
RewriteOptions::kJpegSubsampling, // rewrite_images
RewriteOptions::kRecompressJpeg, // rewrite_images
RewriteOptions::kRecompressPng, // rewrite_images
RewriteOptions::kRecompressWebp, // rewrite_images
RewriteOptions::kResizeImages, // rewrite_images
RewriteOptions::kRewriteCss,
RewriteOptions::kRewriteJavascriptExternal, // rewrite_javascript
RewriteOptions::kRewriteJavascriptInline, // rewrite_javascript
RewriteOptions::kRewriteStyleAttributesWithUrl,
RewriteOptions::kStripImageColorProfile, // rewrite_images
RewriteOptions::kStripImageMetaData, // rewrite_images
};
// The bandwidth-reduction filters exclude any filter that may modify
// URLs (combine, cache-extend, inline, outline). Note also that turning
// on this level enables "preserve" mode which has the effect of
// making combine_css et al turn itself off.
//
// When you change this, remember to update the documentation:
// doc/en/speed/pagespeed/module/config_filters.html
// The documentation there includes the filter groups "rewrite_images" and
// "extend_cache" which expand to multiple filters, all of which need to be
// listed here. config_filters.html both includes lists of filters in each
// group and, redundantly, a table of all filters with one-liner documentation
// and which groups they are in.
const RewriteOptions::Filter kOptimizeForBandwidthFilterSet[] = {
RewriteOptions::kConvertGifToPng, // rewrite_images
RewriteOptions::kConvertJpegToProgressive, // rewrite_images
RewriteOptions::kConvertJpegToWebp, // rewrite_images
RewriteOptions::kConvertPngToJpeg, // rewrite_images
RewriteOptions::kInPlaceOptimizeForBrowser,
RewriteOptions::kJpegSubsampling, // rewrite_images
RewriteOptions::kRecompressJpeg, // rewrite_images
RewriteOptions::kRecompressPng, // rewrite_images
RewriteOptions::kRecompressWebp, // rewrite_images
RewriteOptions::kRewriteCss,
RewriteOptions::kRewriteJavascriptExternal, // rewrite_javascript
RewriteOptions::kRewriteJavascriptInline, // rewrite_javascript
RewriteOptions::kStripImageColorProfile, // rewrite_images
RewriteOptions::kStripImageMetaData, // rewrite_images
};
// Note: all Core filters are Test filters as well. For maintainability,
// this is managed in the c++ switch statement.
const RewriteOptions::Filter kTestFilterSet[] = {
RewriteOptions::kConvertJpegToWebp,
RewriteOptions::kDebug,
RewriteOptions::kDeferIframe,
RewriteOptions::kDeferJavascript,
RewriteOptions::kDelayImages, // AKA inline_preview_images
RewriteOptions::kIncludeJsSourceMaps,
RewriteOptions::kInsertAmpLink,
RewriteOptions::kInsertGA,
RewriteOptions::kInsertImageDimensions,
RewriteOptions::kLazyloadImages,
RewriteOptions::kLeftTrimUrls,
RewriteOptions::kMakeGoogleAnalyticsAsync,
RewriteOptions::kPrioritizeCriticalCss,
RewriteOptions::kResizeToRenderedImageDimensions,
RewriteOptions::kResponsiveImages,
RewriteOptions::kRewriteDomains,
RewriteOptions::kSpriteImages,
};
// Note: These filters should not be included even if the level is "All".
const RewriteOptions::Filter kDangerousFilterSet[] = {
RewriteOptions::kCachePartialHtmlDeprecated,
RewriteOptions::kCanonicalizeJavascriptLibraries,
RewriteOptions::kComputeVisibleTextDeprecated,
RewriteOptions::kDeterministicJs, // used for measurement
RewriteOptions::kDisableJavascript,
RewriteOptions::kDivStructure,
RewriteOptions::kExperimentCollectMobImageInfo,
RewriteOptions::kExplicitCloseTags,
RewriteOptions::kFixReflows,
RewriteOptions::kMobilize,
RewriteOptions::kMobilizePrecompute, // TODO(jud): Unused, remove.
RewriteOptions::kServeDeprecationNotice, // internal.
RewriteOptions::kStripScripts,
};
// List of filters whose correct behavior requires script execution.
// NOTE: Modify the
// SupportNoscriptFilter::IsAnyFilterRequiringScriptExecutionEnabled() method
// if you update this list.
const RewriteOptions::Filter kRequiresScriptExecutionFilterSet[] = {
RewriteOptions::kCachePartialHtmlDeprecated,
RewriteOptions::kDedupInlinedImages,
RewriteOptions::kDeferIframe,
RewriteOptions::kDeferJavascript,
RewriteOptions::kDelayImages,
RewriteOptions::kFlushSubresources,
RewriteOptions::kLazyloadImages,
RewriteOptions::kLocalStorageCache,
RewriteOptions::kMobilize,
// We do not include kPrioritizeVisibleContent since we do not want to
// attach SupportNoscriptFilter in the case of blink pcache miss
// pass-through, since this response will not have any custom script
// inserted. Do the various critical css filters belong here? Arguably not,
// since even if we transform a page based on beacon results we'll enclose
// the necessary in a noscript block and the page will still load / function
// normally.
};
// List of filters that require a 'head' element to exist.
const RewriteOptions::Filter kAddHeadFilters[] = {
RewriteOptions::kAddBaseTag,
RewriteOptions::kAddHead,
RewriteOptions::kAddInstrumentation,
RewriteOptions::kCombineHeads,
RewriteOptions::kDeterministicJs,
RewriteOptions::kHandleNoscriptRedirect,
RewriteOptions::kMakeGoogleAnalyticsAsync,
RewriteOptions::kMobilize,
RewriteOptions::kMoveCssAboveScripts,
RewriteOptions::kMoveCssToHead,
};
// List of filters which are essential for mobilizing webpages, i.e., for
// making webpages designed for desktop computers look good on mobile devices.
//
// TODO(huibao): Once rewrite levels can be combined, move kRewriteCss and
// kRewriteDomains (and kDomainRewriteHyperlinks Option) into a proxy mode.
const RewriteOptions::Filter kMobilizeFilterSet[] = {
RewriteOptions::kMobilize,
// Turn on rewrite_css in order to rewrite hyper-links in CSS.
RewriteOptions::kRewriteCss,
RewriteOptions::kRewriteDomains,
};
// Array of mappings from Filter enum to corresponding filter id and name,
// used to map an enum value to id/name, and also used to initialize the
// reverse map from id to enum. Although the filter_enum field is not strictly
// necessary (because it equals the entry's index in the array), it is here so
// we can check during initialization that the array has been set up correctly.
//
// MUST be updated whenever a new Filter value is added and the new entry
// MUST be inserted in Filter enum order.
const RewriteOptions::FilterEnumToIdAndNameEntry
kFilterVectorStaticInitializer[] = {
{RewriteOptions::kAddBaseTag, "ab", "Add Base Tag"},
{RewriteOptions::kAddHead, "ah", "Add Head"},
{RewriteOptions::kAddIds, "ad", "Add Ids"},
{RewriteOptions::kAddInstrumentation, "ai", "Add Instrumentation"},
{RewriteOptions::kComputeStatistics, "ca", "Compute HTML statistics"},
{RewriteOptions::kCachePartialHtmlDeprecated, "ct", "Deprecated."},
{RewriteOptions::kCanonicalizeJavascriptLibraries, "ij",
"Canonicalize Javascript library URLs"},
{RewriteOptions::kCollapseWhitespace, "cw", "Collapse Whitespace"},
{RewriteOptions::kCombineCss, RewriteOptions::kCssCombinerId,
"Combine Css"},
{RewriteOptions::kCombineHeads, "ch", "Combine Heads"},
{RewriteOptions::kCombineJavascript,
RewriteOptions::kJavascriptCombinerId, "Combine Javascript"},
{RewriteOptions::kComputeCriticalCss, "bc",
"Background Compute Critical css"},
{RewriteOptions::kComputeVisibleTextDeprecated, "bp", "Deprecated."},
{RewriteOptions::kConvertGifToPng, "gp", "Convert Gif to Png"},
{RewriteOptions::kConvertJpegToProgressive, "jp",
"Convert Jpeg to Progressive"},
{RewriteOptions::kConvertJpegToWebp, "jw", "Convert Jpeg To Webp"},
{RewriteOptions::kConvertMetaTags, "mc", "Convert Meta Tags"},
{RewriteOptions::kConvertPngToJpeg, "pj", "Convert Png to Jpeg"},
{RewriteOptions::kConvertToWebpAnimated, "wa",
"Convert animated images to WebP"},
{RewriteOptions::kConvertToWebpLossless, "ws",
"When converting images to WebP, prefer lossless conversions"},
{RewriteOptions::kDebug, "db", "Debug"},
{RewriteOptions::kDecodeRewrittenUrls, "du", "Decode Rewritten URLs"},
{RewriteOptions::kDedupInlinedImages, "dd", "Dedup Inlined Images"},
{RewriteOptions::kDeferIframe, "df", "Defer Iframe"},
{RewriteOptions::kDeferJavascript, "dj", "Defer Javascript"},
{RewriteOptions::kDelayImages, "di", "Delay Images"},
{RewriteOptions::kDeterministicJs, "mj", "Deterministic Js"},
{RewriteOptions::kDisableJavascript, "jd",
"Disables scripts by placing them inside noscript tags"},
{RewriteOptions::kDivStructure, "ds", "Div Structure"},
{RewriteOptions::kElideAttributes, "ea", "Elide Attributes"},
{RewriteOptions::kExperimentCollectMobImageInfo, "xi",
"Experiment: collect image info to help mobilization"},
{RewriteOptions::kExperimentHttp2, "x2",
"Experiment: http2-specific features in development"},
{RewriteOptions::kExplicitCloseTags, "xc", "Explicit Close Tags"},
{RewriteOptions::kExtendCacheCss, "ec", "Cache Extend Css"},
{RewriteOptions::kExtendCacheImages, "ei", "Cache Extend Images"},
{RewriteOptions::kExtendCachePdfs, "ep", "Cache Extend PDFs"},
{RewriteOptions::kExtendCacheScripts, "es", "Cache Extend Scripts"},
{RewriteOptions::kFallbackRewriteCssUrls, "fc",
"Fallback Rewrite Css "},
{RewriteOptions::kFixReflows, "fr", "Fix Reflows"},
{RewriteOptions::kFlattenCssImports,
RewriteOptions::kCssImportFlattenerId, "Flatten CSS Imports"},
{RewriteOptions::kFlushSubresources, "fs", "Flush Subresources"},
{RewriteOptions::kHandleNoscriptRedirect, "hn",
"Handles Noscript Redirects"},
{RewriteOptions::kHintPreloadSubresources, "hpsr",
"Hint Preload of Subresources"},
{RewriteOptions::kHtmlWriterFilter, "hw", "Flushes html"},
{RewriteOptions::kIncludeJsSourceMaps,
RewriteOptions::kJavascriptMinSourceMapId, "Include JS Source Maps"},
{RewriteOptions::kInlineCss, RewriteOptions::kCssInlineId,
"Inline Css"},
{RewriteOptions::kInlineGoogleFontCss,
RewriteOptions::kGoogleFontCssInlineId, "Inline Google Font CSS"},
{RewriteOptions::kInlineImages, "ii", "Inline Images"},
{RewriteOptions::kInlineImportToLink, "il", "Inline @import to Link"},
{RewriteOptions::kInlineJavascript, RewriteOptions::kJavascriptInlineId,
"Inline Javascript"},
{RewriteOptions::kInPlaceOptimizeForBrowser, "io",
"In-place optimize for browser"},
{RewriteOptions::kInsertAmpLink, "ial", "Insert AMP link"},
{RewriteOptions::kInsertDnsPrefetch, "idp", "Insert DNS Prefetch"},
{RewriteOptions::kInsertGA, "ig", "Insert Google Analytics"},
{RewriteOptions::kInsertImageDimensions, "id",
"Insert Image Dimensions"},
{RewriteOptions::kJpegSubsampling, "js", "Jpeg Subsampling"},
{RewriteOptions::kLazyloadImages, "ll", "Lazyload Images"},
{RewriteOptions::kLeftTrimUrls, "tu", "Left Trim Urls"},
{RewriteOptions::kLocalStorageCache,
RewriteOptions::kLocalStorageCacheId, "Local Storage Cache"},
{RewriteOptions::kMakeGoogleAnalyticsAsync, "ga",
"Make Google Analytics Async"},
{RewriteOptions::kMakeShowAdsAsync, "gaa",
"Convert showads.js use to async adsbygoogle.js"},
{RewriteOptions::kMobilize, "mob", "Mobilize Webpage"},
{RewriteOptions::kMobilizePrecompute, "mob_precompute", "Deprecated."},
{RewriteOptions::kMoveCssAboveScripts, "cj", "Move Css Above Scripts"},
{RewriteOptions::kMoveCssToHead, "cm", "Move Css To Head"},
{RewriteOptions::kOutlineCss, "co", "Outline Css"},
{RewriteOptions::kOutlineJavascript, "jo", "Outline Javascript"},
{RewriteOptions::kPedantic, "pc", "Add pedantic types"},
{RewriteOptions::kPrioritizeCriticalCss,
RewriteOptions::kPrioritizeCriticalCssId, "Prioritize Critical Css"},
{RewriteOptions::kRecompressJpeg, "rj", "Recompress Jpeg"},
{RewriteOptions::kRecompressPng, "rp", "Recompress Png"},
{RewriteOptions::kRecompressWebp, "rw", "Recompress Webp"},
{RewriteOptions::kRemoveComments, "rc", "Remove Comments"},
{RewriteOptions::kRemoveQuotes, "rq", "Remove Quotes"},
{RewriteOptions::kResizeImages, "ri", "Resize Images"},
{RewriteOptions::kResizeMobileImages, "rm", "Resize Mobile Images"},
{RewriteOptions::kResizeToRenderedImageDimensions, "ir",
"Resize to Rendered Image Dimensions"},
{RewriteOptions::kResponsiveImages, "rx", "Responsive Images"},
{RewriteOptions::kResponsiveImagesZoom, "rz", "Responsive Images Zoom"},
{RewriteOptions::kRewriteCss, RewriteOptions::kCssFilterId,
"Rewrite Css"},
{RewriteOptions::kRewriteDomains, "rd", "Rewrite Domains"},
{RewriteOptions::kRewriteJavascriptExternal,
RewriteOptions::kJavascriptMinId, "Rewrite External Javascript"},
{RewriteOptions::kRewriteJavascriptInline, "jj",
"Rewrite Inline Javascript"},
{RewriteOptions::kRewriteStyleAttributes, "cs",
"Rewrite Style Attributes"},
{RewriteOptions::kRewriteStyleAttributesWithUrl, "cu",
"Rewrite Style Attributes With Url"},
{RewriteOptions::kServeDeprecationNotice, "sd",
"Serve Deprecation Notice"},
{RewriteOptions::kSplitHtml, "sh", "Deprecated"},
{RewriteOptions::kSplitHtmlHelper, "se", "Deprecated"},
{RewriteOptions::kSpriteImages, RewriteOptions::kImageCombineId,
"Sprite Images"},
{RewriteOptions::kStripImageColorProfile, "cp",
"Strip Image Color Profiles"},
{RewriteOptions::kStripImageMetaData, "md", "Strip Image Meta Data"},
{RewriteOptions::kStripScripts, "ss", "Strip Scripts"},
};
const RewriteOptions::Filter kImagePreserveUrlDisabledFilters[] = {
// TODO(jkarlin): Remove kResizeImages from the forbid list and allow image
// squashing prefetching in HTML path (but don't allow resizing based on
// HTML attributes).
RewriteOptions::kDelayImages,
RewriteOptions::kExtendCacheImages,
RewriteOptions::kInlineImages,
RewriteOptions::kLazyloadImages,
RewriteOptions::kResizeImages,
RewriteOptions::kResizeToRenderedImageDimensions,
RewriteOptions::kResponsiveImages,
RewriteOptions::kSpriteImages};
const RewriteOptions::Filter kJsPreserveUrlDisabledFilters[] = {
RewriteOptions::kCanonicalizeJavascriptLibraries,
RewriteOptions::kCombineJavascript,
RewriteOptions::kDeferJavascript,
RewriteOptions::kExtendCacheScripts,
RewriteOptions::kInlineJavascript,
RewriteOptions::kOutlineJavascript};
const RewriteOptions::Filter kCssPreserveUrlDisabledFilters[] = {
RewriteOptions::kCombineCss, RewriteOptions::kExtendCacheCss,
RewriteOptions::kInlineCss, RewriteOptions::kInlineGoogleFontCss,
RewriteOptions::kInlineImportToLink, RewriteOptions::kLeftTrimUrls,
RewriteOptions::kOutlineCss};
#ifndef NDEBUG
void CheckFilterSetOrdering(const RewriteOptions::Filter* filters, int num) {
for (int i = 1; i < num; ++i) {
DCHECK_GT(filters[i], filters[i - 1]);
}
}
#endif
// Table of properties for each filter to make it faster to check whether the
// a filter is a member of a rewrite level or needs to be disabled when a
// configuration is set to preserve resource URLs. The table is initialized
// once in RewriteOptions::Initialize.
struct FilterProperties {
uint8 level_core : 1;
uint8 level_optimize_for_bandwidth : 1;
uint8 level_mobilize : 1;
uint8 level_test : 1;
uint8 level_dangerous : 1;
uint8 preserve_image_urls : 1;
uint8 preserve_js_urls : 1;
uint8 preserve_css_urls : 1;
};
FilterProperties filter_properties[RewriteOptions::kEndOfFilters];
bool IsInSet(const RewriteOptions::Filter* filters, int num,
RewriteOptions::Filter filter) {
const RewriteOptions::Filter* end = filters + num;
return std::binary_search(filters, end, filter);
}
// Strips the "ets=" query param (if present) from the end of url and strips all
// query params from url and assigns to url_no_query_param.
void StripBeaconUrlQueryParam(GoogleString* url,
GoogleString* url_no_query_param) {
if (StringPiece(*url).ends_with("ets=")) {
// Strip the ? or & in front of ets= as well.
int chars_to_strip = STATIC_STRLEN("ets=") + 1;
url->resize(url->size() - chars_to_strip);
}
StringPieceVector url_split;
SplitStringUsingSubstr(*url, "?", &url_split);
url_split[0].CopyToString(url_no_query_param);
}
// Maps the deprecated options to the new names.
struct RenamedOptionMap {
static bool LessThan(const RenamedOptionMap& option_map, StringPiece arg) {
return StringCaseCompare(option_map.deprecated_option_name, arg) < 0;
}
const char* deprecated_option_name;
const char* new_option_name;
};
const RenamedOptionMap kRenamedOptionNameData[] = {
{"ImageWebpRecompressionQuality", "WebpRecompressionQuality"},
{"ImageWebpRecompressionQualityForSmallScreens",
"WebpRecompressionQualityForSmallScreens"}};
// Will be initialized to a sorted list of headers not allowed in
// AddResourceHeader.
const StringPieceVector* fixed_resource_headers = nullptr;
bool http_header_separators[256] = {false};
} // namespace
const char* RewriteOptions::FilterName(Filter filter) {
int i = static_cast<int>(filter);
int n = arraysize(kFilterVectorStaticInitializer);
if (i >= 0 && i < n) {
return kFilterVectorStaticInitializer[i].filter_name;
}
LOG(DFATAL) << "Unknown filter: " << filter;
return "Unknown Filter";
}
const char* RewriteOptions::FilterId(Filter filter) {
int i = static_cast<int>(filter);
int n = arraysize(kFilterVectorStaticInitializer);
if (i >= 0 && i < n) {
return kFilterVectorStaticInitializer[i].filter_id;
}
LOG(DFATAL) << "Unknown filter code: " << filter;
return "UF";
}
int RewriteOptions::NumFilterIds() {
return arraysize(kFilterVectorStaticInitializer);
}
bool RewriteOptions::ParseRewriteLevel(const StringPiece& in,
RewriteLevel* out) {
bool ret = false;
if (!in.empty()) {
if (StringCaseEqual(in, "CoreFilters")) {
*out = kCoreFilters;
ret = true;
} else if (StringCaseEqual(in, "PassThrough")) {
*out = kPassThrough;
ret = true;
} else if (StringCaseEqual(in, "OptimizeForBandwidth")) {
*out = kOptimizeForBandwidth;
ret = true;
} else if (StringCaseEqual(in, "MobilizeFilters")) {
*out = kMobilizeFilters;
ret = true;
} else if (StringCaseEqual(in, "TestingCoreFilters")) {
*out = kTestingCoreFilters;
ret = true;
} else if (StringCaseEqual(in, "AllFilters")) {
*out = kAllFilters;
ret = true;
}
}