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

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

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

Request.getPushBuilder介绍

[英]Get a PushBuilder associated with this request initialized as follows:

  • The method is initialized to "GET"

  • The headers from this request are copied to the Builder, except for:

  • Conditional headers (eg. If-Modified-Since)

    • Range headers
    • Expect headers
    • Authorization headers
    • Referrer headers
  • If the request was Authenticated, an Authorization header will be set with a container generated token that will result in equivalent Authorization

  • The query string from #getQueryString()

  • The #getRequestedSessionId() value, unless at the time of the call #getSession(boolean)has previously been called to create a new HttpSession, in which case the new session ID will be used as the PushBuilders requested session ID.

  • The source of the requested session id will be the same as for this request

  • The builders Referer header will be set to #getRequestURL()plus any #getQueryString()

  • If HttpServletResponse#addCookie(Cookie) has been called on the associated response, then a corresponding Cookie header will be added to the PushBuilder, unless the Cookie#getMaxAge() is <=0, in which case the Cookie will be removed from the builder.

  • If this request has has the conditional headers If-Modified-Since or If-None-Match then the PushBuilderImpl#isConditional() header is set to true.

Each call to getPushBuilder() will return a new instance of a PushBuilder based off this Request. Any mutations to the returned PushBuilder are not reflected on future returns.
[中]获取与此请求关联的PushBuilder,初始化如下:
*该方法初始化为“GET”
*此请求的标题将复制到生成器,但以下情况除外:
*条件标题(例如,如果自
*范围标题
*预期标题
*授权标头
*推荐人标题
*如果请求经过身份验证,将使用容器生成的令牌设置授权标头,该令牌将产生等效授权
*#getQueryString()中的查询字符串
*#getRequestedSessionId()值,除非在调用时#getSession(布尔值)之前已被调用以创建新的HttpSession,在这种情况下,新的会话ID将用作PushBuilders请求的会话ID。
*请求的会话id的来源将与此请求的相同
*builders Referer头将设置为#getRequestURL()加上任何#getQueryString()
*如果对关联的响应调用了HttpServletResponse#addCookie(Cookie),则相应的Cookie头将添加到PushBuilder,除非Cookie#getMaxAge()小于等于0,在这种情况下,Cookie将从生成器中删除。
*如果此请求具有条件头(如果修改自),或者如果不匹配,则PushBuilderImpl#isConditional()头将设置为true。
每次调用getPushBuilder()都会根据该请求返回一个PushBuilder的新实例。返回的PushBuilder的任何突变都不会反映在未来的返回中。

代码示例

代码示例来源:origin: jooby-project/jooby

@Override
public void push(final String method, final String path, final Map<String, Object> headers) {
 PushBuilder pb = req.getPushBuilder()
   .path(path)
   .method(method);
 headers.forEach((n, v) -> pb.addHeader(n, v.toString()));
 pb.push();
}

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

@Override
public void push(final String method, final String path, final Map<String, Object> headers) {
 PushBuilder pb = req.getPushBuilder()
   .path(path)
   .method(method);
 headers.forEach((n, v) -> pb.addHeader(n, v.toString()));
 pb.push();
}

代码示例来源:origin: fstab/http2-examples

private void push(HttpServletRequest req) {
  Request baseRequest = Request.getBaseRequest(req);
  if (baseRequest.isPushSupported()) {
    baseRequest
        .getPushBuilder()
        .method("GET")
        .path("/data")
        .push();
  }
}

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

@Override
  public void push(HttpServletRequest httpServletRequest, PushItem... pushItems)
  {
    Request request = RequestCycle.get().getRequest();
    HttpServletRequest httpRequest = (HttpServletRequest) request.getContainerRequest();
    final org.eclipse.jetty.server.PushBuilder pushBuilder = org.eclipse.jetty.server.Request.getBaseRequest(httpRequest).getPushBuilder();
    if (pushBuilder != null)
    {
      for (PushItem pushItem : pushItems)
      {
        pushBuilder.path(pushItem.getUrl());
        pushItem.getHeaders().entrySet().stream().forEach(pushHeader -> {
          String key = pushHeader.getKey();
          PushItemHeaderValue value = pushHeader.getValue();
          if(value.getOperation() == HeaderOperation.ADD){
            pushBuilder.addHeader(key, value.getValue());
          }else{
            pushBuilder.setHeader(key, value.getValue());
          }
        });
        pushBuilder.push();
      }
    }
    else
    {
      LOG.warn("Attempted to use HTTP2 Push but it is not supported for the current request: {}!",
          httpRequest);
    }
  }
}

相关文章

Request类方法