7 Replies Latest reply on Jul 28, 2015 1:21 PM by jaikiran

    WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1

    pawel.predki

      We are running Wildfly 8.1.0 and we wanted to set up a directory for static files to be served directly by Undertow. This is what how we set up our standalone.xml:

       

      <subsystem xmlns="urn:jboss:domain:undertow:1.1">

                  <buffer-cache name="default"/>

                  <server name="default-server">

                      <http-listener name="default" socket-binding="http"/>

                      <https-listener name="defaultssl" socket-binding="https" security-realm="SSLRealm"/>

                      <host name="default-host" alias="localhost">

                          <location name="/" handler="welcome-content"/>

                          <location name="/playlist" handler="playlist"/>

                          <filter-ref name="server-header"/>

                          <filter-ref name="x-powered-by-header"/>

                          <filter-ref name="access-control-allow-origin-header"/>

                          <filter-ref name="content-mp4" predicate="path-suffix['.mp4']"/>

                          <filter-ref name="content-m3u8" predicate="path-suffix['.m3u8']"/>

                          <filter-ref name="content-jpg" predicate="path-suffix['.jpg'] or path-suffix['.jpeg']"/>

                      </host>

                  </server>

                  <servlet-container name="default" default-encoding="UTF-8">

                      <jsp-config/>

                  </servlet-container>

                  <handlers>

                      <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>

                      <file name="playlist" path="/home/wildfly/playlist" directory-listing="true"/>

                  </handlers>

                  <filters>

                      <response-header name="content-mp4" header-name="Content-Type" header-value="video/mp4"/>

                      <response-header name="content-m3u8" header-name="Content-Type" header-value="application/x-mpegurl"/>

                      <response-header name="content-jpg" header-name="Content-Type" header-value="image/jpeg"/>

                      <response-header name="server-header" header-name="Server" header-value="WildFly/8"/>

                      <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>

                      <response-header name="access-control-allow-origin-header" header-name="Access-Control-Allow-Origin" header-value="*"/>

                  </filters>

              </subsystem>

       

      Unfortunately, the content-x filters are ignored or overwritten and for all m3u8 and mp4 files we always get Content-Type=application/octet-stream. For the .jpg files the content type is correct.

       

      The question is if it's at all possible to apply the Content-Type header filter to such requests or if there's any other way to force the correct content type for particular files? I tried looking into the Undertow extension code and I found the SharedWebMetaDataBuilder.java class which includes the mp4 MIME type but it is not applied to the requests we make (wildfly/SharedWebMetaDataBuilder.java at bfc41360196f5183a005101bf7ac2d7bfa1389c0 · wildfly/wildfly · GitHub).

       

      Any help would be very appreciated.

        • 1. Re: WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1
          ctomc

          try something like this:

           

          <location name="/playlist" handler="playlist">

                              <filter-ref name="access-control-allow-origin-header"/>

                              <filter-ref name="content-mp4" predicate="path-suffix['.mp4']"/>

                              <filter-ref name="content-m3u8" predicate="path-suffix['.m3u8']"/>

                              <filter-ref name="content-jpg" predicate="path-suffix['.jpg'] or path-suffix['.jpeg']"/>

          </location>

          • 2. Re: WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1
            pawel.predki

            Hello Tomaz and thanks for such a quick reply. Unfortunately, this solution didn't help. It seems like there's something 'special' about the Content-Type header (and maybe others) because other headers we used/tested, also using the predicates, did work. If I substitue 'Content-Type' with 'X-Content-Type' I get the proper header, depending on the extension of the file. Is it possible that this header is overwritten somewhere along the line? Is it possible to see this behavior in logs somewhere? Thanks again.

            • 3. Re: Re: WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1
              swd847

              The issue is that the default servlet will set a content-type header, so your content-type will be overwritten. I will add a check for an existing content type header to the servlet to stop this happening [UNDERTOW-302] Default Servlet should check for existing content type header - JBoss Issue Tracker.

               

              If you want to set a content type you can use the mime-mapping facility in web.xml:

               

              <mime-mapping> 
                <extension>mp4</extension>
                <mime-type>video/mp4</mime-type> 
              </mime-mapping>
              
              1 of 1 people found this helpful
              • 4. Re: Re: WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1
                pawel.predki

                Thanks for the reply, Stuart. It's kind of good to know that the issue is not on our side. Having a web.xml file still requires us to deploy a web app which could be avoided with the static file handler. Thanks for adding the task to the bug tracker.

                 

                Right now we decided to use a servlet where we manually serve the files from the hard drive and set the content type based on the extension. Do you think this affects the performance much compared to the web.xml approach? Wouldn't we need to define a static handler in the web app anyway for the web.xml file to work?

                Cheers

                Pawel

                • 5. Re: WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1
                  swd847

                  Ah, sorry I did not notice that you were using the file handler. I have updated Undertow upstream so it will no longer set the content type.

                  • 6. Re: WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1
                    brenmcguire

                    I am using Wildfly 8.2 and have still the same problem. I would like to add a new content type "text/cache-manifest" for appcache files with ending ".manifest". InternetExplorer requires to get this content type, otherwise the app cache mechanism does not recognize the manifest and the mechanism will not work.


                    It seems that the Content-Type setting does not have any effect, I am always getting the Content-Type "application/octet-stream" for "*.manifest"-files.

                    As commented by Stuart in a post above, it seems the Content-Type will be still overridden.


                    When specifying any other header-name value (other than "Content-Type") then the response header setting below works, when setting "Content-Type" as header-name, the value is not set.

                     

                    Is there a mistake in the setting below or any other possibility in wildfly to add a (new) content-type (other possibility then using web.xml, as we do not use it in an JEE environment)?


                            <subsystem xmlns="urn:jboss:domain:undertow:1.2">

                                <buffer-cache name="default"/>

                                <server name="default-server">

                                    <ajp-listener name="ajp" socket-binding="ajp"/>

                                    <http-listener name="default" socket-binding="http"/>

                                    <host name="default-host" alias="localhost">

                                        <location name="/" handler="welcome-content">

                                            <filter-ref name="content-manifest" predicate="path-suffix['.manifest']"/>

                                        </location>

                                        <filter-ref name="server-header"/>

                                        <filter-ref name="x-powered-by-header"/>

                                        <filter-ref name="Cache-Control"/>

                                        <filter-ref name="content-manifest" predicate="path-suffix['.manifest']"/>

                                        <filter-ref name="myfilter"/>

                                    </host>

                                </server>

                                <servlet-container name="default">

                                    <jsp-config/>

                                    <websockets/>

                                </servlet-container>

                                <handlers>

                                    <file name="welcome-content" path="${jboss.home.dir}/welcome-content"/>

                                </handlers>

                                <filters>

                                    <response-header name="content-manifest" header-name="Content-Type" header-value="text/cache-manifest"/>

                                    <response-header name="server-header" header-name="Server" header-value="WildFly/8"/>

                                    <response-header name="x-powered-by-header" header-name="X-Powered-By" header-value="Undertow/1"/>

                                    <response-header name="myfilter" header-name="agagag" header-value="agaga"/>

                                    <response-header name="Cache-Control" header-name="Cache-Control" header-value="no-cache, must-revalidate"/>

                                </filters>

                            </subsystem>

                     

                    By the way the other filters "Cache-Control" and "myfilter" are working.

                    • 7. Re: WIldfly 8.1.0 'Content-Type' response header filter ignored by Undertow 1.1
                      jaikiran

                      Bren, can you try this against the recently released WildFly 8.2.1.Final http://wildfly.org/downloads/ and see if it's working there?