本文整理汇总了Java中javax.servlet.http.HttpServletResponse.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServletResponse.getHeader方法的具体用法?Java HttpServletResponse.getHeader怎么用?Java HttpServletResponse.getHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.HttpServletResponse
的用法示例。
在下文中一共展示了HttpServletResponse.getHeader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResponseHeaders
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private static Map<String, String> getResponseHeaders(HttpServletResponse response) {
Map<String, String> headers = new LinkedHashMap<>();
for (String header : response.getHeaderNames()) {
String value = response.getHeader(header);
headers.put(header.toLowerCase(), value);
}
headers.remove("set-cookie");
return headers;
}
示例2: channelRead
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object e) throws Exception {
if (e instanceof ServletResponse) {
logger.info("Handler async task...");
HttpServletResponse response = (HttpServletResponse) e;
Runnable task = ThreadLocalAsyncExecutor.pollTask(response);
task.run();
// write response...
ChannelFuture future = ctx.channel().writeAndFlush(response);
String keepAlive = response.getHeader(CONNECTION.toString());
if (null != keepAlive && HttpHeaderValues.KEEP_ALIVE.toString().equalsIgnoreCase(keepAlive)) {
future.addListener(ChannelFutureListener.CLOSE);
}
} else {
ctx.fireChannelRead(e);
}
}
示例3: doFilter
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
throw new ServletException("Just supports HTTP requests");
}
HttpServletRequest httpRequest = (HttpServletRequest) request;
HttpServletResponse httpResponse = (HttpServletResponse) response;
int cacheTime = 0;
for(Pattern pattern : TIME_FOR_URL.keySet()) {
if(pattern.matcher(httpRequest.getRequestURI()).matches()) {
cacheTime = TIME_FOR_URL.get(pattern);
}
}
httpResponse.setHeader(HttpHeaders.CACHE_CONTROL, "max-age="+cacheTime+", must-revalidate");
httpRequest.getRequestURI();
String key = httpRequest.getPathTranslated();
if(cache.containsKey(key)) {
String expectedEtag = httpRequest.getHeader(HttpHeaders.IF_NONE_MATCH);
String currentEtag = cache.get(key);
if(expectedEtag != null && expectedEtag.equals(currentEtag)) {
httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
}
filter.doFilter(request, response, chain);
String etag = httpResponse.getHeader(HttpHeaders.ETAG);
cache.put(key, etag);
}
示例4: hasNoHeaderValue
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private boolean hasNoHeaderValue(HttpServletResponse response, String header, String value) {
String headerValue = response.getHeader(header);
if (StringUtils.isNotBlank(headerValue)) {
return !headerValue.contains(value);
}
return true;
}
示例5: getContentLength
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
private Optional<Integer> getContentLength(HttpServletResponse response) {
String contentLengthString = response.getHeader("Content-Length");
if (null != contentLengthString && !contentLengthString.isEmpty()) {
try {
return Optional.of(Integer.parseInt(contentLengthString));
} catch (NumberFormatException nfe) {
logger.debug("Unable to parse Content-Length header from HttpServletResponse.", nfe);
}
}
return Optional.empty();
}
示例6: isEligibleForEtag
import javax.servlet.http.HttpServletResponse; //导入方法依赖的package包/类
/**
* Indicates whether the given request and response are eligible for ETag generation.
* <p>The default implementation returns {@code true} if all conditions match:
* <ul>
* <li>response status codes in the {@code 2xx} series</li>
* <li>request method is a GET</li>
* <li>response Cache-Control header is not set or does not contain a "no-store" directive</li>
* </ul>
* @param request the HTTP request
* @param response the HTTP response
* @param responseStatusCode the HTTP response status code
* @param responseBody the response body
* @return {@code true} if eligible for ETag generation; {@code false} otherwise
*/
protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletResponse response,
int responseStatusCode, byte[] responseBody) {
if (responseStatusCode >= 200 && responseStatusCode < 300 &&
HttpMethod.GET.name().equals(request.getMethod())) {
String cacheControl = response.getHeader(HEADER_CACHE_CONTROL);
if (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE)) {
return true;
}
}
return false;
}