当前位置: 首页>>代码示例>>Java>>正文


Java HttpHeaders类代码示例

本文整理汇总了Java中org.eclipse.jetty.http.HttpHeaders的典型用法代码示例。如果您正苦于以下问题:Java HttpHeaders类的具体用法?Java HttpHeaders怎么用?Java HttpHeaders使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpHeaders类属于org.eclipse.jetty.http包,在下文中一共展示了HttpHeaders类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleFavicon

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
private boolean handleFavicon(HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (checkFavicon(request)) {
        if (request.getDateHeader(HttpHeaders.IF_MODIFIED_SINCE)== faviconModified)
            response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        else
        {
            response.setStatus(HttpServletResponse.SC_OK);
            response.setContentType("image/x-icon");
            response.setContentLength(favicon.length);
            response.setDateHeader(HttpHeaders.LAST_MODIFIED, faviconModified);
            response.setHeader(HttpHeaders.CACHE_CONTROL,"max-age=360000,public");
            response.getOutputStream().write(favicon);
        }
        return true;
    }
    return false;
}
 
开发者ID:ShotaOd,项目名称:carbon,代码行数:18,代码来源:StaticHandler.java

示例2: onResponseHeader

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Override
public void onResponseHeader( Buffer name, Buffer value )
    throws IOException
{
    if (_redirected)
    {
        int header = HttpHeaders.CACHE.getOrdinal(name);
        switch (header)
        {
            case HttpHeaders.LOCATION_ORDINAL:
                _location = value.toString();
                break;
        }
    }
    super.onResponseHeader(name,value);
}
 
开发者ID:TimelyPick,项目名称:HtmlSpeed,代码行数:17,代码来源:RedirectListener.java

示例3: handle

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
  baseRequest.setHandled(true);
  String method = request.getMethod();
  if (!method.equals(HttpMethods.GET) && !method.equals(HttpMethods.POST) && !method.equals(HttpMethods.HEAD)) {
    return;
  }
  response.setContentType(MimeTypes.TEXT_PLAIN_8859_1);
  response.setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
  ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer(4096);
  handleErrorPage(request, writer, baseRequest.getResponse().getStatus(), baseRequest.getResponse().getReason());
  writer.flush();
  response.setContentLength(writer.size());
  writer.writeTo(response.getOutputStream());
  writer.destroy();
}
 
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:17,代码来源:PlainTextErrorHandler.java

示例4: logExtended

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
protected void logExtended(Request request, 
                           Response response, 
                           Writer writer) throws IOException 
{
    String referer = request.getHeader(HttpHeaders.REFERER);
    if (referer == null) 
        writer.write("\"-\" ");
    else 
    {
        writer.write('"');
        writer.write(referer);
        writer.write("\" ");
    }
    
    String agent = request.getHeader(HttpHeaders.USER_AGENT);
    if (agent == null)
        writer.write("\"-\" ");
    else
    {
        writer.write('"');
        writer.write(agent);
        writer.write('"');
    }          
}
 
开发者ID:NoYouShutup,项目名称:CryptMeme,代码行数:25,代码来源:I2PRequestLog.java

示例5: doFilter

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
    final HttpServletRequest request = (HttpServletRequest) req;
    final String encoding = request.getHeader(HttpHeaders.CONTENT_ENCODING);
    final String alreadyFilteredAttributeName = getClass().getName() + ".FILTERED";
    if (request.getAttribute(alreadyFilteredAttributeName) != null) {
        // Proceed without invoking this filter...
        chain.doFilter(req, res);
    } else {
        // Do invoke this filter...
        request.setAttribute(alreadyFilteredAttributeName, Boolean.TRUE);
        try {
            if (GZIP.equalsIgnoreCase(encoding)) {
                super.doFilter(wrapGzippedRequest(removeContentEncodingHeader(request)), res, chain);
            } else if (DEFLATE.equalsIgnoreCase(encoding)) {
                super.doFilter(wrapDeflatedRequest(removeContentEncodingHeader(request)), res, chain);
            } else {
                super.doFilter(req, res, chain);
            }
        } finally {
            // Remove the "already filtered" request attribute for this request.
            request.removeAttribute(alreadyFilteredAttributeName);
        }
    }
}
 
开发者ID:wotifgroup,项目名称:grails-lightweight-deploy,代码行数:26,代码来源:BiDiGzipFilter.java

示例6: notFoundXml

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Test
public void notFoundXml() throws Exception {
  ContentExchange exchange = sendRequest(FEED_URL + "('Z')");
  exchange.waitForDone();
  assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
  assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
  assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_XML));
  assertThat(exchange.getResponseContent().length(), greaterThan(0));
  assertRegexMatches(exchange.getResponseContent(), ".*<code>NotFoundException</code>.*");
  assertRegexNotMatches(exchange.getResponseContent(), ".*<innererror>.+</innererror>.*");
}
 
开发者ID:teiid,项目名称:oreva,代码行数:12,代码来源:ErrorTest.java

示例7: notFoundJson

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Test
public void notFoundJson() throws Exception {
  ContentExchange exchange = sendRequest(FEED_URL + "('Z')?$format=jsonverbose");
  exchange.waitForDone();
  assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
  assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
  assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_JSON));
  assertThat(exchange.getResponseContent().length(), greaterThan(0));
  assertRegexMatches(exchange.getResponseContent(), ".*\"code\"\\s*:\\s*\"NotFoundException\".*");
  assertRegexNotMatches(exchange.getResponseContent(), ".*\"innererror\"\\s*:\\s*\".+\".*");
}
 
开发者ID:teiid,项目名称:oreva,代码行数:12,代码来源:ErrorTest.java

示例8: badRequestXmlWithInnerError

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Test
public void badRequestXmlWithInnerError() throws Exception {
  simulateErrorResponseExtension();
  ContentExchange exchange = sendRequest(FEED_URL + "(1.2)");
  exchange.waitForDone();
  assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
  assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
  assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_XML));
  assertThat(exchange.getResponseContent().length(), greaterThan(0));
  assertRegexMatches(exchange.getResponseContent(), ".*<code>NotFoundException</code>.*<innererror>.+</innererror>.*");
}
 
开发者ID:teiid,项目名称:oreva,代码行数:12,代码来源:ErrorTest.java

示例9: badRequestJsonWithInnerError

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Test
public void badRequestJsonWithInnerError() throws Exception {
  simulateErrorResponseExtension();
  ContentExchange exchange = sendRequest(FEED_URL + "(1.2)?$format=jsonverbose");
  exchange.waitForDone();
  assertThat(exchange.getStatus(), is(HttpExchange.STATUS_COMPLETED));
  assertThat(exchange.getResponseStatus(), is(HttpStatus.NOT_FOUND_404));
  assertThat(exchange.getResponseFields().getStringField(HttpHeaders.CONTENT_TYPE), containsString(MediaType.APPLICATION_JSON));
  assertThat(exchange.getResponseContent().length(), greaterThan(0));
  assertRegexMatches(exchange.getResponseContent(), ".*\"code\"\\s*:\\s*\"NotFoundException\".*\"innererror\"\\s*:\\s*\".+\".*");
}
 
开发者ID:teiid,项目名称:oreva,代码行数:12,代码来源:ErrorTest.java

示例10: log

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
/**
 * @see RequestLog#log(org.eclipse.jetty.server.Request, org.eclipse.jetty.server.Response)
 */
@Override
public void log(Request request, Response response) {
  StringBuilder buf = new StringBuilder();
  buf.append(request.getServerName());
  buf.append(" ");

  String addr = request.getHeader(HttpHeaders.X_FORWARDED_FOR);
  if (addr == null)
    addr = request.getRemoteAddr();
  buf.append(addr);

  buf.append(" - ");

  buf.append(getUserPrincipal(request));

  buf.append(" [").append(request.getTimeStampBuffer().toString()).append("] ");

  buf.append("\"");
  buf.append(request.getMethod());
  buf.append(' ');
  buf.append(request.getUri().toString());
  buf.append(' ');
  buf.append(request.getProtocol());
  buf.append("\" ");

  buf.append(getStatus(request, response));

  buf.append(" ").append(getResponseLength(response));

  logger.info(buf.toString());
}
 
开发者ID:stockholmuniversity,项目名称:cxf-server,代码行数:35,代码来源:CommonRequestLog.java

示例11: checkExchangeComplete

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
public boolean checkExchangeComplete()
    throws IOException
{
    if (_redirected && _requestComplete && _responseComplete)
    {
        if (_location != null)
        {
            if (_location.indexOf("://")>0)
            {
                _exchange.setURL(_location);
            }
            else
            {
                _exchange.setRequestURI(_location);
            }

            // destination may have changed
            boolean isHttps = HttpSchemes.HTTPS.equals(String.valueOf(_exchange.getScheme()));
            HttpDestination destination=_destination.getHttpClient().getDestination(_exchange.getAddress(),isHttps);

            if (_destination==destination)
            {
                _destination.resend(_exchange);
            }
            else
            {
                // unwrap to find ultimate listener.
                HttpEventListener listener=this;
                while(listener instanceof HttpEventListenerWrapper)
                {
                    listener=((HttpEventListenerWrapper)listener).getEventListener();
                }
                
                //reset the listener
                _exchange.getEventListener().onRetry();
                _exchange.reset();
                _exchange.setEventListener(listener);

                // Set the new Host header
                Address address = _exchange.getAddress();
                int port = address.getPort();
                StringBuilder hostHeader = new StringBuilder( 64 );
                hostHeader.append( address.getHost() );
                if( !( ( port == 80 && !isHttps ) || ( port == 443 && isHttps ) ) ) 
                {
                    hostHeader.append( ':' );
                    hostHeader.append( port );
                }
                
                _exchange.setRequestHeader( HttpHeaders.HOST, hostHeader.toString() );

                destination.send(_exchange);
            }

            return false;
        }
        else
        {
            setDelegationResult(false);
        }
    }

    return true;
}
 
开发者ID:TimelyPick,项目名称:HtmlSpeed,代码行数:65,代码来源:RedirectListener.java

示例12: handle

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException {
    baseRequest.setHandled(true);
    String method = request.getMethod();
    if(!method.equals(HttpMethods.HEAD) && !method.equals(HttpMethods.GET) &&
            !method.equals(HttpMethods.POST) && !method.equals(PATCH_METHOD) && !method.equals(HttpMethods.PUT) &&
             !method.equals(HttpMethods.DELETE)) {
        return;
    }

    final String message;
    final ErrorCode error;
    final String note;
    if(response.getStatus() == HttpServletResponse.SC_NOT_FOUND) {
        message = "Path not found";
        if (!request.getRequestURI().contains("/v1/")) {
            note = "try including /v1/ in the path";
        } else {
            note = null;
        }
        error = ErrorCode.MALFORMED_REQUEST;
    } else {
        if (response instanceof Response) {
            note = ((Response)response).getReason();
        } else {
            note = null;
        }
        message = HttpStatus.getMessage(response.getStatus());
        error = ErrorCode.INTERNAL_ERROR;
    }

    response.setContentType(MediaType.APPLICATION_JSON);
    response.setHeader(HttpHeaders.CACHE_CONTROL, getCacheControl());

    StringBuilder builder = new StringBuilder();
    RestResponseBuilder.formatJsonError(builder, error.getFormattedValue(), message, note);
    builder.append('\n');

    response.setContentLength(builder.length());
    OutputStream out = response.getOutputStream();
    out.write(builder.toString().getBytes());
    out.close();
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:44,代码来源:JsonErrorHandler.java

示例13: removeContentEncodingHeader

import org.eclipse.jetty.http.HttpHeaders; //导入依赖的package包/类
private HttpServletRequest removeContentEncodingHeader(final HttpServletRequest request) {
    return new RemoveHttpHeaderWrapper(request, HttpHeaders.CONTENT_ENCODING);
}
 
开发者ID:wotifgroup,项目名称:grails-lightweight-deploy,代码行数:4,代码来源:BiDiGzipFilter.java


注:本文中的org.eclipse.jetty.http.HttpHeaders类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。