本文整理汇总了Java中javax.servlet.http.HttpServletRequest.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletRequest.getHeaders方法的具体用法?Java HttpServletRequest.getHeaders怎么用?Java HttpServletRequest.getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletRequest
的用法示例。
在下文中一共展示了HttpServletRequest.getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHeaderInfo
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Returns a string containg all the HTTP request headers and their values.
*
* @param req HTTP request
* @return String containg all the HTTP request headers and their values
*/
public static String getHeaderInfo(HttpServletRequest req) {
StringBuilder builder = new StringBuilder("HTTP request headers :");
Enumeration<String> headerNames = req.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
builder.append("\n\"").append(headerName).append("\" => \"");
Enumeration<String> headers = req.getHeaders(headerName);
while (headers.hasMoreElements()) {
String headerValue = headers.nextElement();
builder.append(headerValue);
if (headers.hasMoreElements()) {
builder.append(",");
}
}
builder.append("\"");
}
return builder.toString();
}
示例2: MinijaxHttpHeaders
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public MinijaxHttpHeaders(final HttpServletRequest request) {
headers = new MultivaluedHashMap<>();
final Enumeration<String> ne = request.getHeaderNames();
while (ne.hasMoreElements()) {
final String name = ne.nextElement();
final Enumeration<String> ve = request.getHeaders(name);
while (ve.hasMoreElements()) {
headers.add(name, ve.nextElement());
}
}
cookies = CookieUtils.convertServletToJax(request.getCookies());
}
示例3: getRequestHeaderList
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@SuppressWarnings("rawtypes")
public static List<String> getRequestHeaderList(HttpServletRequest request) {
Enumeration headerNames = request.getHeaderNames();
List<String> resultList;
if (headerNames == null || !headerNames.hasMoreElements()) {
return Collections.emptyList();
}
resultList = new ArrayList<String>();
while (headerNames != null && headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement().toString();
String headerValue = "";
Enumeration header = request.getHeaders(headerName);
while (header != null && header.hasMoreElements()) {
headerValue = headerValue + "," + header.nextElement().toString();
}
if (headerValue.length() > 0) {
headerValue = headerValue.substring(1, headerValue.length());
}
resultList.add(headerName + "=" + headerValue);
}
return resultList;
}
示例4: servletHeadersToMultiMap
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
protected Map<String, List<String>> servletHeadersToMultiMap(HttpServletRequest httpServletRequest) {
Map<String, List<String>> headersResult = new HashMap<>();
Enumeration<String> headerNamesIt = httpServletRequest.getHeaderNames();
while (headerNamesIt.hasMoreElements()) {
String headerName = headerNamesIt.nextElement();
Enumeration<String> valuesIt = httpServletRequest.getHeaders(headerName);
List<String> valuesList = new ArrayList<>(1);
while (valuesIt.hasMoreElements()) {
valuesList.add(valuesIt.nextElement());
}
headersResult.put(headerName, valuesList);
}
return headersResult;
}
开发者ID:opentracing-contrib,项目名称:java-web-servlet-filter,代码行数:19,代码来源:HttpServletRequestExtractAdapter.java
示例5: isPage
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* isPage
*
* @param request
* @return
*/
private boolean isPage(HttpServletRequest request) {
/**
* Step 1: check if is html,htm,jsp
*/
String url = request.getRequestURL().toString();
if (MonitorServerUtil.isIncludeMonitorURLForPage(url)) {
return true;
}
/**
* Step 2: if has no extension, check if accept is a page style
*/
Enumeration<String> accepts = request.getHeaders("Accept");
while (accepts.hasMoreElements()) {
String accept = accepts.nextElement();
for (String mime : acceptMIME) {
if (accept.indexOf(mime) > -1) {
return true;
}
}
}
return false;
}
示例6: filter
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public String filter(HttpServletRequest request) {
if (!matchesHttpMethod(request)) {// don't apply filter unless HTTP
// method matches defined in
// settings
return null;
}
@SuppressWarnings("rawtypes")
Enumeration headers = request.getHeaders(settings.getHeaderName());
while (headers.hasMoreElements()) {
String header = (String) headers.nextElement();
if (headerPattern != null) {
Matcher m = headerPattern.matcher(header);
if (!m.matches())
continue;
if (settings.getExtractIndex() > 0)
return m.group(settings.getExtractIndex());
else
return m.group(0);
}
return header;
}
return null;
}
示例7: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Only interested in the request headers from a GET request
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// Just echo the header value back as plain text
resp.setContentType("text/plain");
PrintWriter out = resp.getWriter();
Enumeration<String> values = req.getHeaders("X-Bug48839");
while (values.hasMoreElements()) {
out.println(values.nextElement());
}
}
示例8: headerContainsToken
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private boolean headerContainsToken(HttpServletRequest req,
String headerName, String target) {
Enumeration<String> headers = req.getHeaders(headerName);
while (headers.hasMoreElements()) {
String header = headers.nextElement();
String[] tokens = header.split(",");
for (String token : tokens) {
if (target.equalsIgnoreCase(token.trim())) {
return true;
}
}
}
return false;
}
示例9: startRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
public void startRequest(HttpServletRequest theRequest) {
if (theRequest == null) {
return;
}
Set<String> headerNames = new TreeSet<String>();
for (Enumeration<String> enums = theRequest.getHeaderNames(); enums.hasMoreElements();) {
headerNames.add(enums.nextElement());
}
ourLog.debug("Request headers: {}", headerNames);
Enumeration<String> forwardedFors = theRequest.getHeaders("x-forwarded-for");
StringBuilder b = new StringBuilder();
for (Enumeration<String> enums = forwardedFors; enums != null && enums.hasMoreElements();) {
if (b.length() > 0) {
b.append(" / ");
}
b.append(enums.nextElement());
}
String forwardedFor = b.toString();
String ip = theRequest.getRemoteAddr();
if (StringUtils.isBlank(forwardedFor)) {
org.slf4j.MDC.put(REMOTE_ADDR, ip);
ourLog.debug("Request is from address: {}", ip);
} else {
org.slf4j.MDC.put(REMOTE_ADDR, forwardedFor);
ourLog.debug("Request is from forwarded address: {}", forwardedFor);
}
String userAgent = StringUtils.defaultString(theRequest.getHeader("user-agent"));
org.slf4j.MDC.put(REMOTE_UA, userAgent);
}
示例10: getTokensFromHeader
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private static List<String> getTokensFromHeader(HttpServletRequest req,
String headerName) {
List<String> result = new ArrayList<String>();
Enumeration<String> headers = req.getHeaders(headerName);
while (headers.hasMoreElements()) {
String header = headers.nextElement();
String[] tokens = header.split(",");
for (String token : tokens) {
result.add(token.trim());
}
}
return result;
}
示例11: saveRequest
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
/**
* Save the original request information into our session.
*
* @param request The request to be saved
* @param session The session to contain the saved information
*/
private void saveRequest(HttpRequest request, Session session) {
// Create and populate a SavedRequest object for this request
HttpServletRequest hreq = (HttpServletRequest) request.getRequest();
SavedRequest saved = new SavedRequest();
Cookie cookies[] = hreq.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++)
saved.addCookie(cookies[i]);
}
Enumeration names = hreq.getHeaderNames();
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
Enumeration values = hreq.getHeaders(name);
while (values.hasMoreElements()) {
String value = (String) values.nextElement();
saved.addHeader(name, value);
}
}
Enumeration locales = hreq.getLocales();
while (locales.hasMoreElements()) {
Locale locale = (Locale) locales.nextElement();
saved.addLocale(locale);
}
Map parameters = hreq.getParameterMap();
Iterator paramNames = parameters.keySet().iterator();
while (paramNames.hasNext()) {
String paramName = (String) paramNames.next();
String paramValues[] = (String[]) parameters.get(paramName);
saved.addParameter(paramName, paramValues);
}
saved.setMethod(hreq.getMethod());
saved.setQueryString(hreq.getQueryString());
saved.setRequestURI(hreq.getRequestURI());
// Stash the SavedRequest in our session for later use
session.setNote(Constants.FORM_REQUEST_NOTE, saved);
}
示例12: headerContainsToken
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private static boolean headerContainsToken(HttpServletRequest req, String headerName, String target) {
Enumeration<String> headers = req.getHeaders(headerName);
while (headers.hasMoreElements()) {
String header = headers.nextElement();
String[] tokens = header.split(",");
for (String token : tokens) {
if (target.equalsIgnoreCase(token.trim())) {
return true;
}
}
}
return false;
}
示例13: headerContainsToken
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private static boolean headerContainsToken(HttpServletRequest req,
String headerName, String target) {
Enumeration<String> headers = req.getHeaders(headerName);
while (headers.hasMoreElements()) {
String header = headers.nextElement();
String[] tokens = header.split(",");
for (String token : tokens) {
if (target.equalsIgnoreCase(token.trim())) {
return true;
}
}
}
return false;
}
示例14: doGet
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletOutputStream out = response.getOutputStream();
response.setContentType("text/plain");
Enumeration<String> e = request.getHeaders("Accept-Encoding");
while (e.hasMoreElements()) {
String name = e.nextElement();
out.println(name);
if (name.indexOf("gzip") != -1) {
out.println("gzip supported -- able to compress");
}
else {
out.println("gzip not supported");
}
}
out.println("Compression Filter Test Servlet");
out.println("Minimum content length for compression is 128 bytes");
out.println("********** 32 bytes **********");
out.println("********** 32 bytes **********");
out.println("********** 32 bytes **********");
out.println("********** 32 bytes **********");
out.close();
}
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:29,代码来源:CompressionFilterTestServlet.java
示例15: getTokensFromHeader
import javax.servlet.http.HttpServletRequest; //导入方法依赖的package包/类
private static List<String> getTokensFromHeader(HttpServletRequest req, String headerName) {
List<String> result = new ArrayList<String>();
Enumeration<String> headers = req.getHeaders(headerName);
while (headers.hasMoreElements()) {
String header = headers.nextElement();
String[] tokens = header.split(",");
for (String token : tokens) {
result.add(token.trim());
}
}
return result;
}