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

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

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

Request.getHeaders介绍

暂无

代码示例

代码示例来源:origin: jphp-group/jphp

@Signature
public Memory headers(boolean lowerKeys) {
  Enumeration<String> headerNames = request.getHeaderNames();
  ArrayMemory result = ArrayMemory.createHashed(15);
  while (headerNames.hasMoreElements()) {
    String key = headerNames.nextElement();
    if (lowerKeys) {
      key = key.toLowerCase();
    }
    ArrayMemory value = ArrayMemory.ofStringEnumeration(request.getHeaders(key));
    if (value.size() == 0) {
      result.putAsKeyString(key, Memory.NULL);
    } else if (value.size() == 1) {
      result.putAsKeyString(key, value.shift());
    } else {
      result.putAsKeyString(key, value);
    }
  }
  return result.toConstant();
}

代码示例来源:origin: org.keycloak/spring-boot-container-bundle

@Override
public List<String> getHeaders(String name) {
  Enumeration<String> headers = request.getHeaders(name);
  if (headers == null) return null;
  List<String> list = new ArrayList<String>();
  while (headers.hasMoreElements()) {
    list.add(headers.nextElement());
  }
  return list;
}

代码示例来源:origin: org.keycloak/keycloak-jetty-adapter-spi

@Override
public List<String> getHeaders(String name) {
  Enumeration<String> headers = request.getHeaders(name);
  if (headers == null) return null;
  List<String> list = new ArrayList<String>();
  while (headers.hasMoreElements()) {
    list.add(headers.nextElement());
  }
  return list;
}

代码示例来源:origin: apache/maven-wagon

public void handle( String target, Request baseRrequest, HttpServletRequest request,
  HttpServletResponse response ) throws IOException, ServletException
{
  headers = new HashMap<String, String>();
  for ( Enumeration<String> e = baseRrequest.getHeaderNames(); e.hasMoreElements(); )
  {
    String name = e.nextElement();
    Enumeration headerValues = baseRrequest.getHeaders( name );
    // as per HTTP spec http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
    // multiple values for the same header key are concatenated separated by comma
    // otherwise we wouldn't notice headers with same key added multiple times
    StringBuffer combinedHeaderValue = new StringBuffer();
    for ( int i = 0; headerValues.hasMoreElements(); i++ )
    {
      if ( i > 0 )
      {
        combinedHeaderValue.append( "," );
      }
      combinedHeaderValue.append( headerValues.nextElement() );
    }
    headers.put( name, combinedHeaderValue.toString() );
  }
  response.setContentType( "text/plain" );
  response.setStatus( HttpServletResponse.SC_OK );
  response.getWriter().print( "Hello, World!" );
  handlerRequestResponses.add(
    new HandlerRequestResponse( baseRrequest.getMethod(), ( (Response) response ).getStatus(),
                  baseRrequest.getRequestURI() ) );
  baseRrequest.setHandled( true );
}

代码示例来源:origin: org.apache.maven.wagon/wagon-provider-test

public void handle( String target, Request baseRrequest, HttpServletRequest request,
  HttpServletResponse response ) throws IOException, ServletException
{
  headers = new HashMap<String, String>();
  for ( Enumeration<String> e = baseRrequest.getHeaderNames(); e.hasMoreElements(); )
  {
    String name = e.nextElement();
    Enumeration headerValues = baseRrequest.getHeaders( name );
    // as per HTTP spec http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html
    // multiple values for the same header key are concatenated separated by comma
    // otherwise we wouldn't notice headers with same key added multiple times
    StringBuffer combinedHeaderValue = new StringBuffer();
    for ( int i = 0; headerValues.hasMoreElements(); i++ )
    {
      if ( i > 0 )
      {
        combinedHeaderValue.append( "," );
      }
      combinedHeaderValue.append( headerValues.nextElement() );
    }
    headers.put( name, combinedHeaderValue.toString() );
  }
  response.setContentType( "text/plain" );
  response.setStatus( HttpServletResponse.SC_OK );
  response.getWriter().print( "Hello, World!" );
  handlerRequestResponses.add(
    new HandlerRequestResponse( baseRrequest.getMethod(), ( (Response) response ).getStatus(),
                  baseRrequest.getRequestURI() ) );
  baseRrequest.setHandled( true );
}

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

@Test
  public void testXForwardedForSkipPrivateAddresses()
      throws Exception
  {
    final Request request = mock(Request.class);
    final Response response = mock(Response.class);
    final String clientIp = "1.1.1.1";

    when(request.getRemoteAddr()).thenReturn("9.9.9.9");
    when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of(clientIp, "192.168.1.2, 172.16.0.1", "169.254.1.2, 127.1.2.3", "10.1.2.3")));

    InMemoryEventClient eventClient = new InMemoryEventClient();
    DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, Long.MAX_VALUE, null, eventClient);
    logger.log(request, response);
    logger.stop();

    List<Object> events = eventClient.getEvents();
    Assert.assertEquals(events.size(), 1);
    HttpRequestEvent event = (HttpRequestEvent) events.get(0);

    Assert.assertEquals(event.getClientAddress(), clientIp);
  }
}

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

@Test
  public void testXForwardedForSkipPrivateAddresses()
      throws Exception
  {
    Request request = mock(Request.class);
    Response response = mock(Response.class);
    String clientIp = "1.1.1.1";

    when(request.getRemoteAddr()).thenReturn("9.9.9.9");
    when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of(clientIp, "192.168.1.2, 172.16.0.1", "169.254.1.2, 127.1.2.3", "10.1.2.3")));
    when(request.getHttpVersion()).thenReturn(HTTP_2);

    InMemoryEventClient eventClient = new InMemoryEventClient();
    DelimitedRequestLog logger = new DelimitedRequestLog(file.getAbsolutePath(), 1, 256, Long.MAX_VALUE, null, eventClient, false);
    logger.log(request, response, 0, 0, 0, new DoubleSummaryStats(new DoubleSummaryStatistics()));
    logger.stop();

    List<Object> events = eventClient.getEvents();
    assertEquals(events.size(), 1);
    HttpRequestEvent event = (HttpRequestEvent) events.get(0);

    assertEquals(event.getClientAddress(), clientIp);
  }
}

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

builder.add(request.getRemoteAddr());
for (Enumeration<String> e = request.getHeaders("X-FORWARDED-FOR"); e != null && e.hasMoreElements(); ) {
  String forwardedFor = e.nextElement();
  builder.addAll(Splitter.on(',').trimResults().omitEmptyStrings().split(forwardedFor));

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

builder.add(request.getRemoteAddr());
for (Enumeration<String> e = request.getHeaders("X-FORWARDED-FOR"); e != null && e.hasMoreElements(); ) {
  String forwardedFor = e.nextElement();
  builder.addAll(Splitter.on(',').trimResults().omitEmptyStrings().split(forwardedFor));

代码示例来源:origin: com.nesscomputing.components/ness-tracking

reqHeaders.put(headerName, headers);
for (Enumeration<String> v = request.getHeaders(headerName); v.hasMoreElements(); ) {
  String headerValue = v.nextElement();
  HttpClientHeader header = new HttpClientHeader(headerName, headerValue);

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

when(request.getHeader("Referer")).thenReturn(referrer);
when(request.getRemoteAddr()).thenReturn("9.9.9.9");
when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of("1.1.1.1, 2.2.2.2", "3.3.3.3, " + ip)));
when(request.getProtocol()).thenReturn("unknown");
when(request.getHeader("X-FORWARDED-PROTO")).thenReturn(protocol);

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

when(request.getHeader("Referer")).thenReturn(referrer);
when(request.getRemoteAddr()).thenReturn("9.9.9.9");
when(request.getHeaders("X-FORWARDED-FOR")).thenReturn(Collections.enumeration(ImmutableList.of("1.1.1.1, 2.2.2.2", "3.3.3.3, " + ip)));
when(request.getProtocol()).thenReturn("unknown");
when(request.getHeader("X-FORWARDED-PROTO")).thenReturn(protocol);

相关文章

Request类方法