Strict-Transport-Security无法正常运行或测试错误?

时间:2018-04-13 01:35:24

标签: apache security webserver jetty embedded-jetty

我在https://www.globalsign.com/en/blog/what-is-hsts-and-how-do-i-use-it/读了一篇关于HTTP标头的文章,我试图看看我们的生产Jetty服务器是否可以使用它。在修改生产代码之前,我编写了一个简单的Java代码,它运行Jetty并添加了标题,curl脚本也会转储标题,但在我的浏览器中,我总是可以通过HTTP访问我的网页。 这是我写的示例代码

public class BlockingServlet extends HttpServlet{

    protected void doGet(
            HttpServletRequest request,
            HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("application/json");
        response.setStatus(HttpServletResponse.SC_OK);
        response.addHeader("X-Xss-Protection", "1; mode=block");
        response.addHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains; preload");
        response.getWriter().println("{ \"status\": \"ok\"}");
    }
}

现在这是我的curl调用和输出:

curl http://localhost:8090/status -I
HTTP/1.1 200 OK
Date: Fri, 13 Apr 2018 01:28:20 GMT
Content-Type: application/json
X-Xss-Protection: 1; mode=block
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Content-Length: 18
Server: Jetty(9.4.3.v20170317)

此外,当我在浏览器中输入http://localhost:8090/status时,我可以看到填充标题后的JSON输出不能正常工作,因为我的服务器根本没有运行https,因为如果我明确键入https我无法访问网址。

我的理解有什么问题?

0 个答案:

没有答案