io.restassured.http.Header.<init>()方法的使用及代码示例

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

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

Header.<init>介绍

[英]Create a new header with the given name and value.
[中]使用给定的名称和值创建新标题。

代码示例

代码示例来源:origin: rest-assured/rest-assured

private List<Header> assembleHeaders(HttpHeaders headers) {
  return headers.keySet().stream()
      .map(headerName -> headers.get(headerName).stream()
          .map(headerValue -> new Header(headerName, headerValue))
          .collect(Collectors.toList())).flatMap(Collection::stream).collect(Collectors.toList());
}

代码示例来源:origin: rest-assured/rest-assured

private Object assembleHeaders(MockHttpServletResponse response) {
  Collection<String> headerNames = response.getHeaderNames();
  List<Header> headers = new ArrayList<Header>();
  for (String headerName : headerNames) {
    List<String> headerValues = response.getHeaders(headerName);
    for (String headerValue : headerValues) {
      headers.add(new Header(headerName, headerValue));
    }
  }
  return new Headers(headers);
}

代码示例来源:origin: rest-assured/rest-assured

public static Headers headers(Headers requestHeaders, Map<String, ?> headers, SpecificationConfig config) {
  notNull(headers, "headers");
  List<Header> headerList = new ArrayList<Header>();
  if (requestHeaders.exist()) {
    for (Header requestHeader : requestHeaders) {
      headerList.add(requestHeader);
    }
  }
  for (Map.Entry<String, ?> stringEntry : headers.entrySet()) {
    Object value = stringEntry.getValue();
    if (value instanceof List) {
      List<?> values = (List<?>) value;
      for (Object headerValue : values) {
        headerList.add(new Header(stringEntry.getKey(), Serializer.serializeIfNeeded(headerValue,
            getRequestContentType(requestHeaders), config)));
      }
    } else {
      headerList.add(new Header(stringEntry.getKey(), Serializer.serializeIfNeeded(value,
          getRequestContentType(requestHeaders), config)));
    }
  }
  return new Headers(headerList);
}

代码示例来源:origin: rest-assured/rest-assured

private void setContentTypeToApplicationFormUrlEncoded() {
  String requestContentType = parseMediaType(HeaderHelper.buildApplicationFormEncodedContentType(config,
      APPLICATION_FORM_URLENCODED_VALUE)).toString();
  List<Header> newHeaders = new ArrayList<>(headers.asList());
  newHeaders.add(new Header(CONTENT_TYPE, requestContentType));
  headers = new Headers(newHeaders);
}

代码示例来源:origin: rest-assured/rest-assured

public static Headers headers(final Headers requestHeaders, final String headerName, final Object headerValue,
                 final SpecificationConfig config,
                 Object... additionalHeaderValues) {
    notNull(headerName, "Header name");
    notNull(headerValue, "Header value");

    List<Header> headerList = new ArrayList<Header>() {{
      add(new Header(headerName, Serializer.serializeIfNeeded(headerValue,
          getRequestContentType(requestHeaders), config)));
    }};

    if (additionalHeaderValues != null) {
      for (Object additionalHeaderValue : additionalHeaderValues) {
        headerList.add(new Header(headerName, Serializer.serializeIfNeeded(additionalHeaderValue,
            getRequestContentType(requestHeaders), config)));
      }
    }
    return new Headers(headerList);
  }
}

代码示例来源:origin: rest-assured/rest-assured

/**
 * Set a specific header
 *
 * @return The builder
 */
public ResponseBuilder setHeader(String name, String value) {
  notNull(name, "Header name");
  notNull(value, "Header value");
  List<Header> newHeaders = new ArrayList<Header>(restAssuredResponse.headers().asList());
  newHeaders.add(new Header(name, value));
  restAssuredResponse.setResponseHeaders(new Headers(newHeaders));
  if (trim(name).equalsIgnoreCase(CONTENT_TYPE)) {
    restAssuredResponse.setContentType(value);
  }
  return this;
}

代码示例来源:origin: rest-assured/rest-assured

private void setContentTypeToApplicationFormUrlEncoded(MockHttpServletRequestBuilder request) {
  MediaType mediaType = MediaType.parseMediaType(HeaderHelper.buildApplicationFormEncodedContentType(config, APPLICATION_FORM_URLENCODED_VALUE));
  request.contentType(mediaType);
  List<Header> newHeaders = new ArrayList<Header>(headers.asList());
  newHeaders.add(new Header(CONTENT_TYPE, mediaType.toString()));
  headers = new Headers(newHeaders);
}

代码示例来源:origin: io.rest-assured/spring-commons

public static Headers headers(Headers requestHeaders, Map<String, ?> headers, SpecificationConfig config) {
  notNull(headers, "headers");
  List<Header> headerList = new ArrayList<Header>();
  if (requestHeaders.exist()) {
    for (Header requestHeader : requestHeaders) {
      headerList.add(requestHeader);
    }
  }
  for (Map.Entry<String, ?> stringEntry : headers.entrySet()) {
    Object value = stringEntry.getValue();
    if (value instanceof List) {
      List<?> values = (List<?>) value;
      for (Object headerValue : values) {
        headerList.add(new Header(stringEntry.getKey(), Serializer.serializeIfNeeded(headerValue,
            getRequestContentType(requestHeaders), config)));
      }
    } else {
      headerList.add(new Header(stringEntry.getKey(), Serializer.serializeIfNeeded(value,
          getRequestContentType(requestHeaders), config)));
    }
  }
  return new Headers(headerList);
}

代码示例来源:origin: io.rest-assured/spring-commons

public static Headers headers(final Headers requestHeaders, final String headerName, final Object headerValue,
                 final SpecificationConfig config,
                 Object... additionalHeaderValues) {
    notNull(headerName, "Header name");
    notNull(headerValue, "Header value");

    List<Header> headerList = new ArrayList<Header>() {{
      add(new Header(headerName, Serializer.serializeIfNeeded(headerValue,
          getRequestContentType(requestHeaders), config)));
    }};

    if (additionalHeaderValues != null) {
      for (Object additionalHeaderValue : additionalHeaderValues) {
        headerList.add(new Header(headerName, Serializer.serializeIfNeeded(additionalHeaderValue,
            getRequestContentType(requestHeaders), config)));
      }
    }
    return new Headers(headerList);
  }
}

相关文章