io.restassured.http.Header类的使用及代码示例

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

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

Header介绍

[英]Represents a HTTP header
[中]表示HTTP标头

代码示例

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

private static String toString(Headers headers) {
  if (!headers.exist()) {
    return "";
  }
  final StringBuilder builder = new StringBuilder();
  for (Header header : headers) {
    builder.append(header.getName())
        .append(HEADER_NAME_AND_VALUE_SEPARATOR)
        .append(header.getValue())
        .append(SystemUtils.LINE_SEPARATOR);
  }
  builder.delete(builder.length() - SystemUtils.LINE_SEPARATOR.length(), builder.length());
  return builder.toString();
}

代码示例来源: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 static List<Header> removeMergedHeadersIfNeeded(List<Header> headerList, HeaderConfig headerConfig) {
  List<Header> filteredList = new ArrayList<Header>();
  for (Header header : headerList) {
    String headerName = header.getName();
    if (headerConfig.shouldOverwriteHeaderWithName(headerName)) {
      int index = -1;
      for (int i = 0; i < filteredList.size(); i++) {
        Header filteredHeader = filteredList.get(i);
        if (filteredHeader.hasSameNameAs(header)) {
          index = i;
          break;
        }
      }
      if (index != -1) {
        filteredList.remove(index);
      }
    }
    filteredList.add(header);
  }
  return filteredList;
}

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

public String getRequestContentType() {
  Header header = requestHeaders.get(CONTENT_TYPE);
  if (header != null) {
    return header.getValue();
  }
  return null;
}

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

public boolean hasSameNameAs(Header header) {
  AssertParameter.notNull(header, Header.class);
  return this.name.equalsIgnoreCase(header.getName());
}

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

public static String getRequestContentType(Headers requestHeaders) {
  Header header = requestHeaders.get(CONTENT_TYPE);
  if (header != null) {
    return header.getValue();
  }
  return null;
}

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

private void addRequestElements(HttpMethod method, String requestContentType, WebTestClient.RequestBodySpec requestBodySpec) {
  verifyNoBodyAndMultipartTogether();
  if (isNotBlank(requestContentType)) {
    requestBodySpec.contentType(parseMediaType(requestContentType));
  }
  applyRequestBody(requestBodySpec);
  applyMultipartBody(method, requestBodySpec);
  applyAttributes(requestBodySpec);
  headers.forEach(header -> requestBodySpec.header(header.getName(), header.getValue()));
  cookies.asList().forEach(cookie -> requestBodySpec.cookie(cookie.getName(), cookie.getValue()));
}

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

public String getRequestContentType() {
  Header header = requestHeaders.get(CONTENT_TYPE);
  if (header != null) {
    return header.getValue();
  }
  return null;
}

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

private static List<Header> removeMergedHeadersIfNeeded(List<Header> headerList, HeaderConfig headerConfig) {
  List<Header> filteredList = new ArrayList<Header>();
  for (Header header : headerList) {
    String headerName = header.getName();
    if (headerConfig.shouldOverwriteHeaderWithName(headerName)) {
      int index = -1;
      for (int i = 0; i < filteredList.size(); i++) {
        Header filteredHeader = filteredList.get(i);
        if (filteredHeader.hasSameNameAs(header)) {
          index = i;
          break;
        }
      }
      if (index != -1) {
        filteredList.remove(index);
      }
    }
    filteredList.add(header);
  }
  return filteredList;
}

代码示例来源: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

request.header(header.getName(), header.getValue());

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

public static String getRequestContentType(Headers requestHeaders) {
  Header header = requestHeaders.get(CONTENT_TYPE);
  if (header != null) {
    return header.getValue();
  }
  return null;
}

代码示例来源: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: spring-projects/spring-restdocs

private boolean isAllMediaTypesAcceptHeader(Header header) {
  return HttpHeaders.ACCEPT.equals(header.getName())
      && "*/*".equals(header.getValue());
}

代码示例来源:origin: com.hotels/heat-core-utils

isCheckOk &= assertionHandler.assertion(isBlocking, "assertTrue", logUtils.getTestCaseDetails() + "check on header '" + headerName
        + "' The expected value is '" + expectedHeader + "' - The returned values are " + headers + "-- ",
    headers.stream().anyMatch(header -> header.getValue().equals(expectedHeader))
  );

代码示例来源: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: spring-projects/spring-restdocs

private HttpHeaders extractHeaders(Response response) {
  HttpHeaders httpHeaders = new HttpHeaders();
  for (Header header : response.getHeaders()) {
    httpHeaders.add(header.getName(), header.getValue());
  }
  return httpHeaders;
}

代码示例来源:origin: HotelsDotCom/heat

isCheckOk &= assertionHandler.assertion(isBlocking, "assertTrue", logUtils.getTestCaseDetails() + "check on header '" + headerName
        + "' The expected value is '" + expectedHeader + "' - The returned values are " + headers + "-- ",
    headers.stream().anyMatch(header -> header.getValue().equals(expectedHeader))
  );

代码示例来源: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: spring-projects/spring-restdocs

private HttpHeaders extractHeaders(FilterableRequestSpecification requestSpec) {
  HttpHeaders httpHeaders = new HttpHeaders();
  for (Header header : requestSpec.getHeaders()) {
    if (!isAllMediaTypesAcceptHeader(header)) {
      httpHeaders.add(header.getName(), header.getValue());
    }
  }
  return httpHeaders;
}

相关文章