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

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

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

Request.getHeaders介绍

暂无

代码示例

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

private static Map<String, String> writeOutBoundHeaders(final MultivaluedMap<String, Object> headers, final Request request) {
  final Map<String, String> stringHeaders = HeaderUtils.asStringHeadersSingleValue(headers);
  // remove User-agent header set by Jetty; Jersey already sets this in its request (incl. Jetty version)
  request.getHeaders().remove(HttpHeader.USER_AGENT);
  for (final Map.Entry<String, String> e : stringHeaders.entrySet()) {
    request.getHeaders().add(e.getKey(), e.getValue());
  }
  return stringHeaders;
}

代码示例来源:origin: apache/incubator-druid

byte[] bytes = objectMapper.writeValueAsBytes(query);
proxyRequest.content(new BytesContentProvider(bytes));
proxyRequest.getHeaders().put(HttpHeader.CONTENT_LENGTH, String.valueOf(bytes.length));

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

@Nullable
  private static String getHeader(Request request, String header)
  {
    requireNonNull(header, "header is null");
    HttpFields headers = request.getHeaders();
    if (headers != null) {
      return headers.get(header);
    }
    return null;
  }
}

代码示例来源:origin: census-instrumentation/opencensus-java

@Override
public String getUserAgent(Request request) {
 return request.getHeaders().get("User-Agent");
}

代码示例来源:origin: labsai/EDDI

public IRequest setHttpHeader(String headerName, String value) {
  request.getHeaders().add(headerName, value);
  return this;
}

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

public Map<String, Collection<String>> getRequestHeaders() {
  return getFieldsAsMap(request.getHeaders());
}

代码示例来源:origin: org.glassfish.jersey.connectors/jersey-jetty-connector

private static Map<String, String> writeOutBoundHeaders(final MultivaluedMap<String, Object> headers, final Request request) {
  final Map<String, String> stringHeaders = HeaderUtils.asStringHeadersSingleValue(headers);
  // remove User-agent header set by Jetty; Jersey already sets this in its request (incl. Jetty version)
  request.getHeaders().remove(HttpHeader.USER_AGENT);
  for (final Map.Entry<String, String> e : stringHeaders.entrySet()) {
    request.getHeaders().add(e.getKey(), e.getValue());
  }
  return stringHeaders;
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

private void copyIfAbsent(HttpRequest oldRequest, Request newRequest, HttpHeader header)
{
  HttpField field = oldRequest.getHeaders().getField(header);
  if (field != null && !newRequest.getHeaders().contains(header))
    newRequest.getHeaders().put(field);
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

protected boolean expects100Continue(Request request)
{
  return request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
}

代码示例来源:origin: labsai/EDDI

@Override
public IRequest setBasicAuthentication(String username, String password, String realm, boolean preemptive) {
  if (preemptive) {
    request.getHeaders().add("Authorization", "Basic " + Base64.getEncoder().
        encodeToString((username + ":" + password).getBytes()));
  } else {
    AuthenticationStore auth = httpClient.getAuthenticationStore();
    auth.addAuthentication(new BasicAuthentication(uri, realm, username, password));
  }
  return this;
}

代码示例来源:origin: org.eclipse.jetty/jetty-proxy

protected void copyRequestHeaders(HttpServletRequest clientRequest, Request proxyRequest)
{
  // First clear possibly existing headers, as we are going to copy those from the client request.
  proxyRequest.getHeaders().clear();
  Set<String> headersToRemove = findConnectionHeaders(clientRequest);
  for (Enumeration<String> headerNames = clientRequest.getHeaderNames(); headerNames.hasMoreElements();)
  {
    String headerName = headerNames.nextElement();
    String lowerHeaderName = headerName.toLowerCase(Locale.ENGLISH);
    if (HttpHeader.HOST.is(headerName) && !_preserveHost)
      continue;
    // Remove hop-by-hop headers.
    if (HOP_HEADERS.contains(lowerHeaderName))
      continue;
    if (headersToRemove != null && headersToRemove.contains(lowerHeaderName))
      continue;
    for (Enumeration<String> headerValues = clientRequest.getHeaders(headerName); headerValues.hasMoreElements();)
    {
      String headerValue = headerValues.nextElement();
      if (headerValue != null)
        proxyRequest.header(headerName, headerValue);
    }
  }
  // Force the Host header if configured
  if (_hostHeader != null)
    proxyRequest.header(HttpHeader.HOST, _hostHeader);
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

@Override
public boolean accept(Request request, Response response)
{
  boolean is100 = response.getStatus() == HttpStatus.CONTINUE_100;
  boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
  boolean handled100 = request.getAttributes().containsKey(ATTRIBUTE);
  return (is100 || expect100) && !handled100;
}

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

@Override
public boolean accept(Request request, Response response)
{
  boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
  HttpConversation conversation = client.getConversation(request.getConversationID(), false);
  boolean handled100 = conversation != null && conversation.getAttribute(ATTRIBUTE) != null;
  return expect100 && !handled100;
}

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

@Override
public boolean accept(Request request, Response response)
{
  boolean expect100 = request.getHeaders().contains(HttpHeader.EXPECT, HttpHeaderValue.CONTINUE.asString());
  HttpConversation conversation = client.getConversation(request.getConversationID(), false);
  boolean handled100 = conversation != null && conversation.getAttribute(ATTRIBUTE) != null;
  return expect100 && !handled100;
}

代码示例来源:origin: org.eclipse.jetty/jetty-client

protected boolean beginToHeaders(HttpExchange exchange)
{
  if (!updateRequestState(RequestState.BEGIN, RequestState.TRANSIENT))
    return false;
  Request request = exchange.getRequest();
  if (LOG.isDebugEnabled())
    LOG.debug("Request headers {}{}{}", request, System.lineSeparator(), request.getHeaders().toString().trim());
  RequestNotifier notifier = getHttpChannel().getHttpDestination().getRequestNotifier();
  notifier.notifyHeaders(request);
  if (updateRequestState(RequestState.TRANSIENT, RequestState.HEADERS))
    return true;
  terminateRequest(exchange);
  return false;
}

代码示例来源:origin: com.playtika.reactivefeign/feign-reactor-jetty

@Override
public Mono<ReactiveHttpResponse> executeRequest(ReactiveHttpRequest request) {
  Request jettyRequest = httpClient.newRequest(request.uri()).method(request.method());
  setUpHeaders(request, jettyRequest.getHeaders());
  if(requestTimeout > 0){
    jettyRequest.timeout(requestTimeout, TimeUnit.MILLISECONDS);
    jettyRequest.getHeaders().put(ACCEPT_ENCODING.asString(), singletonList(GZIP));
  } else {
    jettyRequest.getHeaders().remove(ACCEPT_ENCODING.asString());

代码示例来源:origin: census-instrumentation/opencensus-java

@Test
 public void testExtraction() {
  HttpFields fields = new HttpFields();
  fields.add(new HttpField("User-Agent", "Test 1.0"));

  Request request = mock(Request.class);
  Response response = mock(Response.class);
  OcJettyHttpClientExtractor extractor = new OcJettyHttpClientExtractor();
  when(request.getHost()).thenReturn("localhost");
  when(request.getMethod()).thenReturn("GET");
  when(request.getHeaders()).thenReturn(fields);
  when(request.getPath()).thenReturn("/test");
  when(request.getURI()).thenReturn(uri);
  when(response.getStatus()).thenReturn(0);

  assertThat(extractor.getHost(request)).contains("localhost");
  assertThat(extractor.getMethod(request)).contains("GET");
  assertThat(extractor.getPath(request)).contains("/test");
  assertThat(extractor.getUrl(request)).contains(URI_STR);
  assertThat(extractor.getRoute(request)).contains("");
  assertThat(extractor.getUserAgent(request)).contains("Test 1.0");
  assertThat(extractor.getStatusCode(response)).isEqualTo(0);
 }
}

代码示例来源:origin: kptfh/feign-reactive

@Override
public Mono<ReactiveHttpResponse> executeRequest(ReactiveHttpRequest request) {
  Request jettyRequest = httpClient.newRequest(request.uri()).method(request.method());
  setUpHeaders(request, jettyRequest.getHeaders());
  if(requestTimeout > 0){
    jettyRequest.timeout(requestTimeout, TimeUnit.MILLISECONDS);
  }
  ReactiveRequest.Builder requestBuilder = ReactiveRequest.newBuilder(jettyRequest);
  if(bodyActualClass != null){
    ReactiveRequest.Content content = provideBody(request);
    requestBuilder.content(content);
    jettyRequest.getHeaders().put(CONTENT_TYPE.asString(), singletonList(content.getContentType()));
  }
  return Mono.<ReactiveHttpResponse>from(requestBuilder.build().response((response, content) -> Mono.just(
      new JettyReactiveHttpResponse(response.getResponse(),
          postProcess(content,
              (contentChunk, throwable) -> {
                if(throwable != null){
                  contentChunk.callback.failed(throwable);
                } else {
                  contentChunk.callback.succeeded();
                }
              }),
          returnPublisherClass, returnActualClass,
          jsonFactory, responseReader))
  )).onErrorMap(ex -> ex instanceof java.util.concurrent.TimeoutException,
      ReadTimeoutException::new);
}

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

protected Request copyRequest(Request oldRequest, URI newURI)
{
  Request newRequest = new HttpRequest(this, oldRequest.getConversationID(), newURI);
  newRequest.method(oldRequest.getMethod())
      .version(oldRequest.getVersion())
      .content(oldRequest.getContent());
  for (HttpField header : oldRequest.getHeaders())
  {
    // We have a new URI, so skip the host header if present
    if (HttpHeader.HOST == header.getHeader())
      continue;
    // Remove expectation headers
    if (HttpHeader.EXPECT == header.getHeader())
      continue;
    // Remove cookies
    if (HttpHeader.COOKIE == header.getHeader())
      continue;
    // Remove authorization headers
    if (HttpHeader.AUTHORIZATION == header.getHeader() ||
        HttpHeader.PROXY_AUTHORIZATION == header.getHeader())
      continue;
    newRequest.header(header.getName(), header.getValue());
  }
  return newRequest;
}

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

protected Request copyRequest(Request oldRequest, URI newURI)
{
  Request newRequest = new HttpRequest(this, oldRequest.getConversationID(), newURI);
  newRequest.method(oldRequest.getMethod())
      .version(oldRequest.getVersion())
      .content(oldRequest.getContent());
  for (HttpField header : oldRequest.getHeaders())
  {
    // We have a new URI, so skip the host header if present
    if (HttpHeader.HOST == header.getHeader())
      continue;
    // Remove expectation headers
    if (HttpHeader.EXPECT == header.getHeader())
      continue;
    // Remove cookies
    if (HttpHeader.COOKIE == header.getHeader())
      continue;
    // Remove authorization headers
    if (HttpHeader.AUTHORIZATION == header.getHeader() ||
        HttpHeader.PROXY_AUTHORIZATION == header.getHeader())
      continue;
    newRequest.header(header.getName(), header.getValue());
  }
  return newRequest;
}

相关文章