Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-50680

WSRP ProxyServlet should preserve certain headers like "Cache-Control"

    Details

      Description

      HTTP responses for static resources in case of a WSRP portlet are missing certain headers and correct status code sent by the origin server.

      To demonstrate the behavior, I'm modifying the built-in "Unit Converter" portlet which can be used as a Producer/Consumer by default (branch: https://github.com/lipusz/liferay-portal/tree/LPS-50680)
      1- Modify its definition in liferay-portlet.xml

      	<portlet>
      		<portlet-name>27</portlet-name>
      		<icon>/html/icons/unit_converter.png</icon>
      		<struts-path>unit_converter</struts-path>
      		<remoteable>true</remoteable>
      		<private-request-attributes>false</private-request-attributes>
      		<private-session-attributes>false</private-session-attributes>
      		<render-weight>50</render-weight>
      		<footer-portlet-javascript>/html/portlet/unit_converter/js/main.js</footer-portlet-javascript>
      		<css-class-wrapper>portlet-unit-converter</css-class-wrapper>
      	</portlet>
      

      Notice the newly added <footer-portlet-javascript> element.

      2- Create a dummy JS file as main.js:

      /html/portlet/unit_converter/js/main.js
      AUI.add(
      	'unit-converter',
      	function(A) {
      	}
      );
      

      3- Deploy the changes (or build the portal)
      4- Deploy WSRP portlet
      5- Create a new Producer using the "Unit Converter" portlet
      6- Create a new Consumer using the producer you have just created
      7- Add "Unit Converter" portlet to the consumer
      8- Add this consumer portlet to a page
      9- Open firebug and select Net panel

      10- Reload the page
      11- Look for the following URL:

      http://localhost:8080/wsrp-portlet/proxy?url=http%3A%2F%2Flocalhost%3A8080%2Fhtml%2Fportlet%2Funit_converter%2Fjs%2Fmain.js%3Ft%3D1412766688000
      

      12- Check the headers of the Request and the Response

      Request
      GET /wsrp-portlet/proxy?url=http%3A%2F%2Flocalhost%3A8080%2Fhtml%2Fportlet%2Funit_converter%2Fjs%2Fmain.js%3Ft%3D1412766688000 HTTP/1.1
      Host: localhost:8080
      User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:32.0) Gecko/20100101 Firefox/32.0
      Accept: */*
      Accept-Language: en-US,en;q=0.5
      Accept-Encoding: gzip, deflate
      Referer: http://localhost:8080/
      Cookie: JSESSIONID=1628D283E6FF5A6338435267D34AFC22; COOKIE_SUPPORT=true; GUEST_LANGUAGE_ID=en_US; _ga=GA1.1.67914619.1412347507; JSESSIONID=DAF9C2126342023A372C5F342D4C5561; LFR_SESSION_STATE_10157=1412775440161; USER_UUID="2JTOGKSsO25UQpF7qtYnDYnKgA6xxD2LB2vVwBJWwyc="; LFR_SESSION_STATE_10199=1412776387904; LFR_SESSION_STATE_10158=1412692057671; LFR_SESSION_STATE_10196=1412614954482; COMPANY_ID=10153; ID=796e57524a476e4d505a3270394265363567765558413d3d
      Connection: keep-alive
      Cache-Control: max-age=0
      
      Response
      HTTP/1.1 200 OK
      Server: Apache-Coyote/1.1
      X-Content-Type-Options: nosniff
      X-Frame-Options: SAMEORIGIN
      X-XSS-Protection: 1
      Content-Type: text/javascript
      Content-Length: 85
      Date: Wed, 08 Oct 2014 13:53:12 GMT
      

      Result Header "Cache-Control" is missing, and the status code is set to "HTTP 200 OK" even if the resource was served by the origin server as "HTTP 304 Not Modified"

      After adding the appropriate header to the response in ProxyServlet the response looks like:

      Response
      HTTP/1.1 304 Not Modified
      X-Content-Type-Options: nosniff
      X-Frame-Options: SAMEORIGIN
      X-XSS-Protection: 1
      Date: Wed, 08 Oct 2014 13:55:57 GMT
      Vary: Accept-Encoding
      Last-Modified: Wed, 08 Oct 2014 11:11:28 GMT
      Server: Apache-Coyote/1.1
      Cache-Control: max-age=315360000, public
      

        Attachments

        1. fixed.png
          fixed.png
          29 kB
        2. reproduced.png
          reproduced.png
          16 kB

          Activity

            People

            • Assignee:
              yvonne.han Yvonne Han
              Reporter:
              tibor.lipusz Tibor Lipusz
              Participants of an Issue:
              Recent user:
              Esther Sanz
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Due:
                Created:
                Updated:
                Resolved:
                Days since last comment:
                5 years, 3 weeks, 5 days ago

                Packages

                Version Package
                6.0.X EE
                6.1.X EE
                6.2.X EE
                7.0.0 M2