com.linecorp.armeria.common.HttpRequest.headers()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(100)

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

HttpRequest.headers介绍

[英]Returns the initial HTTP/2 headers of this request.
[中]返回此请求的初始HTTP/2头。

代码示例

代码示例来源:origin: line/armeria

/**
 * Returns the scheme of this request. This method is a shortcut of {@code headers().scheme()}.
 */
default String scheme() {
  return headers().scheme();
}

代码示例来源:origin: line/armeria

/**
 * Sets the method of this request. This method is a shortcut of {@code headers().method(...)}.
 *
 * @return {@code this}
 */
default HttpRequest method(HttpMethod method) {
  headers().method(method);
  return this;
}

代码示例来源:origin: line/armeria

/**
 * Sets the authority of this request. This method is a shortcut of {@code headers().authority(...)}.
 *
 * @return {@code this}
 */
default HttpRequest authority(String authority) {
  headers().authority(authority);
  return this;
}

代码示例来源:origin: line/armeria

/**
 * Returns the method of this request. This method is a shortcut of {@code headers().method()}.
 */
default HttpMethod method() {
  return headers().method();
}

代码示例来源:origin: line/armeria

/**
 * Returns the path of this request. This method is a shortcut of {@code headers().path()}.
 */
default String path() {
  return headers().path();
}

代码示例来源:origin: line/armeria

/**
 * Sets the scheme of this request. This method is a shortcut of {@code headers().scheme(...)}.
 *
 * @return {@code this}
 */
default HttpRequest scheme(String scheme) {
  headers().scheme(scheme);
  return this;
}

代码示例来源:origin: line/armeria

/**
 * Sets the path of this request. This method is a shortcut of {@code headers().path(...)}.
 *
 * @return {@code this}
 */
default HttpRequest path(String path) {
  headers().path(path);
  return this;
}

代码示例来源:origin: line/armeria

/**
 * Returns the authority of this request. This method is a shortcut of {@code headers().authority()}.
 */
default String authority() {
  return headers().authority();
}

代码示例来源:origin: line/armeria

/**
 * Returns whether the request should be aggregated.
 */
static boolean aggregationRequired(AggregationStrategy strategy, HttpRequest req) {
  requireNonNull(strategy, "strategy");
  switch (strategy) {
    case ALWAYS:
      return true;
    case FOR_FORM_DATA:
      return isFormData(req.headers().contentType());
  }
  return false;
}

代码示例来源:origin: line/armeria

@Override
protected AggregatedHttpMessage onSuccess(HttpData content) {
  return AggregatedHttpMessage.of(request.headers(), content, trailingHeaders);
}

代码示例来源:origin: line/armeria

/**
 * Returns {@code true} if the specified {@code request} is a CORS preflight request.
 */
public static boolean isCorsPreflightRequest(com.linecorp.armeria.common.HttpRequest request) {
  requireNonNull(request, "request");
  return request.method() == HttpMethod.OPTIONS &&
      request.headers().contains(HttpHeaderNames.ORIGIN) &&
      request.headers().contains(HttpHeaderNames.ACCESS_CONTROL_REQUEST_METHOD);
}

代码示例来源:origin: line/armeria

@Nullable
static HttpEncodingType getWrapperForRequest(HttpRequest request) {
  final String acceptEncoding = request.headers().get(HttpHeaderNames.ACCEPT_ENCODING);
  if (acceptEncoding == null) {
    return null;
  }
  return determineEncoding(acceptEncoding);
}

代码示例来源:origin: line/armeria

@Override
protected MultiValueMap<String, HttpCookie> initCookies() {
  final MultiValueMap<String, HttpCookie> cookies = new LinkedMultiValueMap<>();
  final List<String> values = req.headers().getAll(HttpHeaderNames.COOKIE);
  values.stream()
     .map(ServerCookieDecoder.LAX::decode)
     .flatMap(Collection::stream)
     .forEach(c -> cookies.add(c.name(), new HttpCookie(c.name(), c.value())));
  return cookies;
}

代码示例来源:origin: line/armeria

private static boolean validateAcceptHeaders(HttpRequest req, SerializationFormat serializationFormat) {
  // If accept header is present, make sure it is sane. Currently, we do not support accept
  // headers with a different format than the content type header.
  final List<String> acceptHeaders = req.headers().getAll(HttpHeaderNames.ACCEPT);
  if (!acceptHeaders.isEmpty() &&
    !serializationFormat.mediaTypes().matchHeaders(acceptHeaders).isPresent()) {
    return false;
  }
  return true;
}

代码示例来源:origin: line/armeria

@Override
protected HttpResponse doExecute(ClientRequestContext ctx, HttpRequest req) throws Exception {
  final boolean hasInitialAuthority = !isNullOrEmpty(req.headers().authority());
  final CompletableFuture<HttpResponse> responseFuture = new CompletableFuture<>();
  final HttpResponse res = HttpResponse.from(responseFuture);
  final HttpRequestDuplicator reqDuplicator = new HttpRequestDuplicator(req, 0, ctx.eventLoop());
  doExecute0(ctx, reqDuplicator, req, res, responseFuture, hasInitialAuthority);
  return res;
}

代码示例来源:origin: line/armeria

@Override
public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
  final HttpEncodingType encodingType = HttpEncoders.getWrapperForRequest(req);
  final HttpResponse delegateResponse = delegate().serve(ctx, req);
  if (encodingType == null || !encodableRequestHeadersPredicate.test(req.headers())) {
    return delegateResponse;
  }
  return new HttpEncodedResponse(
      delegateResponse,
      encodingType,
      encodableContentTypePredicate,
      minBytesToForceChunkedAndEncoding);
}

代码示例来源:origin: line/armeria

ArmeriaServerHttpRequest(ServiceRequestContext ctx,
             HttpRequest req,
             DataBufferFactoryWrapper<?> factoryWrapper) {
  super(URI.create(requireNonNull(req, "req").path()),
     null,
     fromArmeriaHttpHeaders(req.headers()));
  this.ctx = requireNonNull(ctx, "ctx");
  this.req = req;
  body = Flux.from(req).cast(HttpData.class).map(factoryWrapper::toDataBuffer)
        // Guarantee that the context is accessible from a controller method
        // when a user specify @RequestBody in order to convert a request body into an object.
        .publishOn(Schedulers.fromExecutor(ctx.contextAwareExecutor()));
}

代码示例来源:origin: line/armeria

HttpParameters httpParameters() {
  HttpParameters result = httpParameters;
  if (result == null) {
    synchronized (this) {
      result = httpParameters;
      if (result == null) {
        httpParameters = result = httpParametersOf(context.query(),
                              request.headers().contentType(),
                              message);
      }
    }
  }
  return result;
}

代码示例来源:origin: line/armeria

@Override
  public HttpResponse execute(ClientRequestContext ctx, HttpRequest req) throws Exception {
    if (req.headers().contains(HttpHeaderNames.ACCEPT_ENCODING)) {
      // Client specified encoding, so we don't do anything automatically.
      return delegate().execute(ctx, req);
    }
    req.headers().set(HttpHeaderNames.ACCEPT_ENCODING, acceptEncodingHeader);
    final HttpResponse res = delegate().execute(ctx, req);
    return new HttpDecodedResponse(res, decoderFactories);
  }
}

代码示例来源:origin: line/armeria

@Override
  public CompletionStage<Boolean> authorize(ServiceRequestContext ctx, HttpRequest req) {
    final String value = req.headers().get(HttpHeaderNames.COOKIE);
    if (value == null) {
      return CompletableFuture.completedFuture(false);
    }
    // Authentication will be succeeded only if both the specified cookie name and value are matched.
    final Set<Cookie> cookies = ServerCookieDecoder.STRICT.decode(value);
    final boolean result = cookies.stream().anyMatch(
        cookie -> cookieName.equals(cookie.name()) && cookieValue.equals(cookie.value()));
    return CompletableFuture.completedFuture(result);
  }
}

相关文章