如何将Jetty配置为带有到期标头的css/js文件服务器? [英] How to configure jetty as css/js file server with expires header?

查看:110
本文介绍了如何将Jetty配置为带有到期标头的css/js文件服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<Configure class="org.eclipse.jetty.server.handler.ContextHandler">
  <Set name="contextPath">/</Set>
  <Set name="resourceBase"><SystemProperty name="jetty.home" default="."/>/webapps/foo</Set>
  <Set name="handler">
    <New class="org.eclipse.jetty.server.handler.ResourceHandler">
      <Set name="cacheControl">max-age=3600,public</Set>
    </New>
  </Set>
<Set name="virtualHosts">
    <Array type="java.lang.String">
          <Item>foo.bar</Item>
    </Array>
</Set>
</Configure>

这是我的配置,但是没有过期标头可以添加到http响应中.

This is my configuration, but no expires header can be added to the http response.

因为在中没有与expires标头相关的属性 ResourceHandler.

Because there is no property related to expires header in ResourceHandler.

我发现MovedContexHandler具有此属性,我应该使用它吗?

I found MovedContexHandler have this property, shall i use that?

推荐答案

我做了一个愚蠢的技巧来完成这项工作!如果您有更好的解决方案,请告诉我.

I make a silly hack to get this work done! If you have a better solution, tell me.

package org.eclipse.jetty.server.handler;

import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.HttpHeaders;
import org.eclipse.jetty.util.resource.Resource;
/**
 * @author jilen.zhang@gmail.com
 * @date 12-7-6
 */
public class StaticResourceHandler extends ResourceHandler{
    private String expires = "xxx";

    @Override
    protected void doResponseHeaders(HttpServletResponse response, Resource resource, String mimeType) {
        super.doResponseHeaders(response, resource, mimeType);
        response.setHeader(HttpHeaders.EXPIRES, expires);
    }
}

这篇关于如何将Jetty配置为带有到期标头的css/js文件服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆