本文整理匯總了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;
}