[英]Using Servlet API, how to determine if request was HTTP/1.0 or HTTP/1.1?
I'm fixing a bug that is only evidenced when the client is using HTTP/1.0 (and is secretly, Internet Explorer proxying behind a firewall). 我正在修复一个只在客户端使用HTTP / 1.0时才会证明的错误(并且秘密地,Internet Explorer代理在防火墙后面)。 Details are here: https://issues.apache.org/jira/browse/TAP5-1880 详情请访问: https : //issues.apache.org/jira/browse/TAP5-1880
In any case, the right solution is to turn off a feature (GZip content compression) when the request is HTTP/1.0. 在任何情况下,正确的解决方案是在请求为HTTP / 1.0时关闭功能(GZip内容压缩)。 However, after scouring the Servlet API documentation, and even the Jetty source, I can't find any place where this information is exposed. 但是,在搜索了Servlet API文档,甚至是Jetty源代码之后,我找不到任何公开此信息的地方。
So, is there a way to determine this? 那么,有没有办法确定这个? I'm using Servlet API 2.5. 我正在使用Servlet API 2.5。
Thanks in advance! 提前致谢!
request.getProtocol() will return "HTTP/1.0" or "HTTP/1.1"
Here is the example, execute in your local tomcat 下面是示例,在您的本地tomcat中执行
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class ShowRequestHeaders extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Servlet Example: Showing Request Headers";
out.println(ServletUtilities.headWithTitle(title) +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1 ALIGN=CENTER>" + title + "</H1>\n" +
"<B>Request Method: </B>" +
request.getMethod() + "<BR>\n" +
"<B>Request URI: </B>" +
request.getRequestURI() + "<BR>\n" +
"<B>Request Protocol: </B>" +
request.getProtocol() + "<BR><BR>\n" +
"<TABLE BORDER=1 ALIGN=CENTER>\n" +
"<TR BGCOLOR=\"#FFAD00\">\n" +
"<TH>Header Name<TH>Header Value");
Enumeration headerNames = request.getHeaderNames();
while(headerNames.hasMoreElements()) {
String headerName = (String)headerNames.nextElement();
out.println("<TR><TD>" + headerName);
out.println(" <TD>" + request.getHeader(headerName));
}
out.println("</TABLE>\n</BODY></HTML>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.