当前位置: 首页>>代码示例>>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;未经允许,请勿转载。