when to set base_url for domain_rewriter_filter?

11 views
Skip to first unread message

Alex Wu

unread,
Feb 11, 2017, 9:14:00 AM2/11/17
to pagespeed-dev
scan_filter.cc set base url when it sees base tag. If base tag is not seen, or the last one in the <head> section, the base_url is invalid, so the link inside the <head> section is not rewritten by domain_rewrite_filter. If we have text/html response, where is the proper place to initialize driver's base url?

Otto van der Schaaf

unread,
Feb 13, 2017, 5:32:32 PM2/13/17
to Alex Wu, pagespeed-dev
I am not sure I understand your question, so I suspect I maybe answering a question you did not intend to ask :-) 

You can (need to) pass the document url in via RewriteDriver::StartParse().
Until a parsed base tag overrides what you passed in there, the document url will be used to resolve relative urls.
Does that answer your question? 

Did you expect the base tag to apply to html elements declared before it too, instead of only to html elements declared after it?  

Otto


On Sat, Feb 11, 2017 at 3:14 PM Alex Wu <yw9...@gmail.com> wrote:
scan_filter.cc set base url when it sees base tag. If base tag is not seen, or the last one in the <head> section, the base_url is invalid, so the link inside the <head> section is not rewritten by domain_rewrite_filter. If we have text/html response, where is the proper place to initialize driver's base url?

--
You received this message because you are subscribed to the Google Groups "pagespeed-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pagespeed-de...@googlegroups.com.
To post to this group, send email to pagesp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pagespeed-dev/95fa13d7-0761-4ebe-bc07-23a6c256f60d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Alex Wu

unread,
Feb 13, 2017, 6:30:44 PM2/13/17
to pagespeed-dev, yw9...@gmail.com
The problem is base tag (<base>) is at the end of the head section. so the links ahead of base tag is ignored. With a thought, turning on the option of preserving url relativity so that domain rewrite should not depend base tag. so here is a fix:

diff --git a/mod_pagespeed/src-11-21/net/instaweb/rewriter/domain_rewrite_filter.cc b/mod_pagespeed/src-11-21/net/instaweb/re
index be54c87..f1ec3aa 100644
--- a/mod_pagespeed/src-11-21/net/instaweb/rewriter/domain_rewrite_filter.cc
+++ b/mod_pagespeed/src-11-21/net/instaweb/rewriter/domain_rewrite_filter.cc
@@ -394,9 +394,10 @@ void DomainRewriteFilter::ParseSetCookieAttributes(
 }
 
 void DomainRewriteFilter::StartElementImpl(HtmlElement* element) {
+  const RewriteOptions* options = driver()->options();
   // The base URL is used to rewrite the attribute URL, which is all this
   // method does; if it isn't valid we can't so there's no point in going on.
-  if (!BaseUrlIsValid()) {
+  if (!options->preserve_url_relativity() && !BaseUrlIsValid()) {
     // The base URL is used to rewrite the attribute URL, which is all this
     // method does; if it isn't valid we can't so there's no point in going on.
     //
@@ -408,7 +409,6 @@ void DomainRewriteFilter::StartElementImpl(HtmlElement* element) {
   // Make sure domain rewriting of this element has not been forbidden.  Right
   // now we must not rewrite the src url of the iframe created by the
   // iframe_fetcher.
-  const RewriteOptions* options = driver()->options();
   if (options->mob_iframe() &&
       (StringPiece(element->EscapedAttributeValue(HtmlName::kId)) ==
        IframeFetcher::kIframeId) &&

Alex
Reply all
Reply to author
Forward
0 new messages