sling-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amrit Verma <amrve...@adobe.com.INVALID>
Subject Rewriting CSS files (delivered using Output Stream) using rewriter pipeline
Date Fri, 26 May 2017 06:28:05 GMT
Hi,

I have a use case(explained below) where I want to rewrite the URLs present in a CSS file
being returned in servlet response. I had a look at the current sling rewriter pipeline but
I was not able to rewrite CSS files using that even if I provided a Generator(to parse the
CSS file) and a Serializer(to write CSS to response). I did some debugging and found that
RewriterResponse from ContentDispositionFilter [1] doesn't initiate the rewriting pipeline
as is done by the RewriterResponse [2] used by RewriterFilter [3]. RewriterResponse from ContentDispositionFilter
gets called if file is delivered using OutputStream instead of Writer.

I added a method getOutputStream to RewriterResponse in ContentDispositionFilter and initiated
the pipeline (by calling getProcessor) in that method just as done in getWriter method of
RewriterResponse [2] and I was able to get my Generator working. I have a commit [4] showing
the changes in I did in sling. Can someone have a look at it and check if we can incorporate
such a change in sling?
It's only a draft and is missing on Javadocs. Also there are some changes related to annotations.
Please ignore them. I had to do that because of sling issue [5] which is fixed now.

Use Case - Using a CDN to deliver secure content from our Application Server
Rewriter pipeline is being used to rewrite internal links to CSS files in html response delivered
from Application Server. The rewritten links point to a CDN server and contain a signature
as query parameter. When browser requests a CSS file from CDN for the first time, there is
cache miss on CDN and it forwards the request along with the signature to our application
server. The signature is validated and the app server returns CSS file to CDN which is delivered
to browser.
Now, if the CSS file contains links to resources, for example a URL to image in background-image
property, that image would be requested from CDN and CDN would forward it to app server but
app server wouldn't return the image unless the signature is passed in request parameter.
So we want to rewrite the CSS file being returned by app server so that all the URLs are rewritten
to contain the signature parameter.

Thanks
Amrit

[1]: https://github.com/apache/sling/blob/trunk/contrib/extensions/security/src/main/java/org/apache/sling/security/impl/ContentDispositionFilter.java
[2]: https://github.com/apache/sling/blob/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterResponse.java
[3]: https://github.com/apache/sling/blob/trunk/contrib/extensions/rewriter/src/main/java/org/apache/sling/rewriter/impl/RewriterFilter.java
[4]: https://github.com/averma21/sling/commit/c2e0464510407b4384f9079192943e87599566d9
[5]: https://issues.apache.org/jira/browse/SLING-6879





Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message