org.eclipse.jetty.server.Request.getHttpFields()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.eclipse.jetty.server.Request.getHttpFields方法的一些代码示例,展示了Request.getHttpFields的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getHttpFields方法的具体详情如下:
包路径:org.eclipse.jetty.server.Request
类名称:Request
方法名:getHttpFields

Request.getHttpFields介绍

暂无

代码示例

代码示例来源:origin: gocd/gocd

private String acceptHeaderValue(Request baseRequest) {
  List<String> qualityCSV = baseRequest.getHttpFields().getQualityCSV(HttpHeader.ACCEPT);
  return qualityCSV.isEmpty() ? MimeTypes.Type.TEXT_HTML.asString() : qualityCSV.get(0);
}

代码示例来源:origin: gocd/gocd

private MockResponse request(String target, String acceptHeaderValue) throws Exception {
  Request baseRequest = mock(Request.class);
  HttpFields httpFields = new HttpFields();
  if (acceptHeaderValue != null) {
    httpFields.add("Accept", acceptHeaderValue);
  }
  when(baseRequest.getHttpFields()).thenReturn(httpFields);
  HttpServletRequest servletRequest = mock(HttpServletRequest.class);
  HttpServletResponse servletResponse = mock(HttpServletResponse.class);
  PrintWriter printWriter = mock(PrintWriter.class);
  when(servletResponse.getWriter()).thenReturn(printWriter);
  handler.getHandler().handle(target, baseRequest, servletRequest, servletResponse);
  return new MockResponse(servletResponse, printWriter);
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldAddDefaultHeadersForRootContext() throws Exception {
  jetty9Server.configure();
  jetty9Server.startHandlers();
  HttpServletResponse response = mock(HttpServletResponse.class);
  when(response.getWriter()).thenReturn(mock(PrintWriter.class));
  HttpServletRequest request = mock(HttpServletRequest.class);
  Request baseRequest = mock(Request.class);
  when(baseRequest.getDispatcherType()).thenReturn(DispatcherType.REQUEST);
  when(baseRequest.getHttpFields()).thenReturn(mock(HttpFields.class));
  ContextHandler rootPathHandler = getLoadedHandlers().get(GoServerLoadingIndicationHandler.class);
  rootPathHandler.setServer(server);
  rootPathHandler.start();
  rootPathHandler.handle("/something", baseRequest, request, response);
  verify(response).setHeader("X-XSS-Protection", "1; mode=block");
  verify(response).setHeader("X-Content-Type-Options", "nosniff");
  verify(response).setHeader("X-Frame-Options", "SAMEORIGIN");
  verify(response).setHeader("X-UA-Compatible", "chrome=1");
}

代码示例来源:origin: apache/nifi

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
  throws IOException, ServletException {
  baseRequest.setHandled(true);
  if(method.name().equals(request.getMethod())) {
    if(this.expectedContentType.isEmpty()) {
      Assert.assertNull(request.getHeader("Content-Type"));
    } else {
      assertEquals(this.expectedContentType,request.getHeader("Content-Type"));
    }
    final String body = request.getReader().readLine();
    this.trackedHeaderValue = baseRequest.getHttpFields().get(headerToTrack);
    if(this.expectedContentType.isEmpty()) {
      Assert.assertNull(body);
    } else {
      assertEquals("Hello", body);
    }
  } else {
    response.setStatus(404);
    response.setContentType("text/plain");
    response.setContentLength(0);
  }
}

代码示例来源:origin: jenkinsci/winstone

private String getXForwardedFor(Request request)
{
  // Get the right most XForwarded-For for value.
  // This is the value from the closest proxy and the only one that
  // can be trusted.
  String forwarded_for = null;
  HttpFields httpFields = request.getHttpFields();
  for (HttpField field : httpFields)
    if (_forwardedHeader.equalsIgnoreCase(field.getName()))
      forwarded_for = field.getValue();
  
  if (forwarded_for==null || forwarded_for.isEmpty())
    return null;
  
  int comma = forwarded_for.lastIndexOf(',');
  return (comma>=0)?forwarded_for.substring(comma+1).trim():forwarded_for;
}

代码示例来源:origin: com.teradata.airlift/http-server

@Override
  public Deflater getDeflater(Request request, long content_length)
  {
    // GzipHandler incorrectly skips this check for HTTP/2
    HttpField accept = request.getHttpFields().getField(HttpHeader.ACCEPT_ENCODING);
    if ((accept == null) || !accept.contains("gzip")) {
      return null;
    }
    return super.getDeflater(request, content_length);
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server

@Override
public Deflater getDeflater(Request request, long content_length)
  String ua = request.getHttpFields().get(HttpHeader.USER_AGENT);
  if (ua!=null && !isAgentGzipable(ua))
  HttpField accept = request.getHttpFields().getField(HttpHeader.ACCEPT_ENCODING);

代码示例来源:origin: jenkinsci/winstone

private String getForwarded(Request request)
{
  // Get the right most Forwarded for value.
  // This is the value from the closest proxy and the only one that
  // can be trusted.
  RFC7239 rfc7239 = new RFC7239();
  HttpFields httpFields = request.getHttpFields();
  for (HttpField field : httpFields)
    if (_forwardedHeader.equalsIgnoreCase(field.getName()))
      rfc7239.addValue(field.getValue());
  
  if (rfc7239.getFor()!=null)
    return new HostPortHttpField(rfc7239.getFor()).getHost();
  
  return null;
}

代码示例来源:origin: jenkinsci/winstone

throws IOException
List<String> acceptable=baseRequest.getHttpFields().getQualityCSV(HttpHeader.ACCEPT);
if (acceptable.isEmpty() && !baseRequest.getHttpFields().contains(HttpHeader.ACCEPT))

代码示例来源:origin: com.teradata.airlift/http-client

@Override
  public Deflater getDeflater(org.eclipse.jetty.server.Request request, long content_length)
  {
    // GzipHandler incorrectly skips this check for HTTP/2
    HttpField accept = request.getHttpFields().getField(HttpHeader.ACCEPT_ENCODING);
    if ((accept == null) || !accept.contains("gzip")) {
      return null;
    }
    return super.getDeflater(request, content_length);
  }
}

代码示例来源:origin: jenkinsci/winstone

@Override
public Deflater getDeflater(Request request, long content_length)
{
  String ua = request.getHttpFields().get(HttpHeader.USER_AGENT);
  if (ua!=null && !isAgentGzipable(ua))
  {
    LOG.debug("{} excluded user agent {}",this,request);
    return null;
  }
  
  if (content_length>=0 && content_length<_minGzipSize)
  {
    LOG.debug("{} excluded minGzipSize {}",this,request);
    return null;
  }
  // check the accept encoding header
  HttpField accept = request.getHttpFields().getField(HttpHeader.ACCEPT_ENCODING);
  if (accept==null)
  {
    LOG.debug("{} excluded !accept {}",this,request);
    return null;
  }
  boolean gzip = accept.contains("gzip");
  if (!gzip)
  {
    LOG.debug("{} excluded not gzip accept {}",this,request);
    return null;
  }
  return _deflaterPool.acquire();
}

代码示例来源:origin: org.apache.camel/camel-jetty9

jettyRequest.getHttpFields().remove(Exchange.CONTENT_ENCODING);

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server

public void handle(HttpChannel connection) throws IOException, ServletException
{
  final String target=connection.getRequest().getPathInfo();
  final Request request=connection.getRequest();
  final Response response=connection.getResponse();
  if (LOG.isDebugEnabled())
    LOG.debug("{} on {}{}{} {} {}{}{}", request.getDispatcherType(), connection, System.lineSeparator(),
        request.getMethod(), target, request.getProtocol(), System.lineSeparator(), request.getHttpFields());
  if (HttpMethod.OPTIONS.is(request.getMethod()) || "*".equals(target))
  {
    if (!HttpMethod.OPTIONS.is(request.getMethod()))
      response.sendError(HttpStatus.BAD_REQUEST_400);
    handleOptions(request,response);
    if (!request.isHandled())
      handle(target, request, request, response);
  }
  else
    handle(target, request, request, response);
  if (LOG.isDebugEnabled())
    LOG.debug("RESPONSE for {} h={}{}{} {}{}{}", target, request.isHandled(), System.lineSeparator(),
        response.getStatus(), response.getReason(), System.lineSeparator(), response.getHttpFields());
}

代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9

_fields.clear();
String connection = _channel.getRequest().getHttpFields().getStringField(HttpHeader.CONNECTION);
if (connection != null)

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

_fields.clear();
String connection = _channel.getRequest().getHttpFields().getStringField(HttpHeader.CONNECTION);
if (connection != null)

代码示例来源:origin: com.ovea.tajin.server/tajin-server-jetty9

persistent = getRequest().getHttpFields().contains(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.asString());
if (!persistent)
  persistent = HttpMethod.CONNECT.is(getRequest().getMethod());
persistent = !getRequest().getHttpFields().contains(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString());
if (!persistent)
  persistent = HttpMethod.CONNECT.is(getRequest().getMethod());

代码示例来源:origin: com.ovea.tajin.servers/tajin-server-jetty9

persistent = getRequest().getHttpFields().contains(HttpHeader.CONNECTION, HttpHeaderValue.KEEP_ALIVE.asString());
if (!persistent)
  persistent = HttpMethod.CONNECT.is(getRequest().getMethod());
persistent = !getRequest().getHttpFields().contains(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString());
if (!persistent)
  persistent = HttpMethod.CONNECT.is(getRequest().getMethod());

代码示例来源:origin: Nextdoor/bender

_fields.clear();
String connection = _channel.getRequest().getHttpFields().getStringField(HttpHeader.CONNECTION);
if (connection != null)

代码示例来源:origin: jenkinsci/winstone

private void extractContentParameters()
  if (_metaData!=null && getHttpFields().contains(HttpHeader.CONTENT_ENCODING))
    throw new BadMessageException(HttpStatus.NOT_IMPLEMENTED_501,"Unsupported Content-Encoding");

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.jetty.server

/**
 * <p>Pushes a secondary resource identified by this dispatcher.</p>
 *
 * @param request the primary request
 * @deprecated Use {@link Request#getPushBuilder()} instead
 */
@Deprecated
public void push(ServletRequest request)
{
  Request baseRequest = Request.getBaseRequest(request);
  HttpFields fields = new HttpFields(baseRequest.getHttpFields());
  String query=baseRequest.getQueryString();
  if (_uri.hasQuery())
  {
    if (query==null)
      query=_uri.getQuery();
    else
      query=query+"&"+_uri.getQuery(); // TODO is this correct semantic?
  }
  HttpURI uri = HttpURI.createHttpURI(request.getScheme(),request.getServerName(),request.getServerPort(),_uri.getPath(),baseRequest.getHttpURI().getParam(),query,null);
  MetaData.Request push = new MetaData.Request(HttpMethod.GET.asString(),uri,baseRequest.getHttpVersion(),fields);
  baseRequest.getHttpChannel().getHttpTransport().push(push);
}

相关文章

Request类方法