當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpServletResponse.getHeader方法代碼示例

本文整理匯總了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;
}
 
開發者ID:xm-online,項目名稱:xm-commons,代碼行數:10,代碼來源:TimelineEventProducer.java

示例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);
    }
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:20,代碼來源:AsyncHttpServletHandler.java

示例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);
}
 
開發者ID:BBVA,項目名稱:mirrorgate,代碼行數:36,代碼來源:OneTimeETagGenerationFilter.java

示例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;
}
 
開發者ID:e-gov,項目名稱:TARA-Server,代碼行數:8,代碼來源:ResponseHeadersEnforcementFilter.java

示例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();
}
 
開發者ID:aws,項目名稱:aws-xray-sdk-java,代碼行數:12,代碼來源:AWSXRayServletFilter.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:ShallowEtagHeaderFilter.java


注:本文中的javax.servlet.http.HttpServletResponse.getHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。