org.mockserver.model.HttpRequest.withSecure()方法的使用及代码示例

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

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

HttpRequest.withSecure介绍

[英]Match on whether the request was made over SSL (i.e. HTTPS)
[中]匹配是否通过SSL(即HTTPS)发出请求

代码示例

代码示例来源:origin: jamesdbloom/mockserver

public HttpForwardActionResult handle(HttpForward httpForward, HttpRequest httpRequest) {
  if (httpForward.getScheme().equals(HttpForward.Scheme.HTTPS)) {
    httpRequest.withSecure(true);
  } else {
    httpRequest.withSecure(false);
  }
  return sendRequest(httpRequest, new InetSocketAddress(httpForward.getHost(), httpForward.getPort()));
}

代码示例来源:origin: jamesdbloom/mockserver

private HttpResponse sendRequest(HttpRequest request) {
  try {
    if (secure != null) {
      request.withSecure(secure);

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest mapHttpServletRequestToMockServerRequest(HttpServletRequest httpServletRequest) {
  HttpRequest request = new HttpRequest();
  setMethod(request, httpServletRequest);
  setPath(request, httpServletRequest);
  setQueryString(request, httpServletRequest);
  setBody(request, httpServletRequest);
  setHeaders(request, httpServletRequest);
  setCookies(request, httpServletRequest);
  request.withKeepAlive(isKeepAlive(httpServletRequest));
  request.withSecure(httpServletRequest.isSecure());
  return request;
}

代码示例来源:origin: jamesdbloom/mockserver

@Override
  public HttpRequest handle(HttpRequest httpRequest) {
    return request()
      .withHeader("Host", "localhost:" + httpRequest.getFirstHeader("x-echo-server-port"))
      .withHeader("x-test", httpRequest.getFirstHeader("x-test"))
      .withBody("some_overridden_body")
      .withSecure(httpRequest.isSecure());
  }
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest buildObject() {
  return new HttpRequest()
    .withMethod(method)
    .withPath(path)
    .withQueryStringParameters(queryStringParameters)
    .withBody((body != null ? Not.not(body.buildObject(), body.getNot()) : null))
    .withHeaders(headers)
    .withCookies(cookies)
    .withSecure(secure)
    .withKeepAlive(keepAlive);
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest decode(FullHttpRequest fullHttpRequest) {
  HttpRequest httpRequest = new HttpRequest();
  if (fullHttpRequest != null) {
    setMethod(httpRequest, fullHttpRequest);
    setPath(httpRequest, fullHttpRequest);
    setQueryString(httpRequest, new QueryStringDecoder(fullHttpRequest.uri()));
    setHeaders(httpRequest, fullHttpRequest);
    setCookies(httpRequest, fullHttpRequest);
    setBody(httpRequest, fullHttpRequest);
    httpRequest.withKeepAlive(isKeepAlive(fullHttpRequest));
    httpRequest.withSecure(isSecure);
  }
  return httpRequest;
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest clone() {
  return not(request(), not)
    .withMethod(method)
    .withPath(path)
    .withQueryStringParameters(getQueryStringParameters().clone())
    .withBody(body)
    .withHeaders(getHeaders().clone())
    .withCookies(getCookies().clone())
    .withKeepAlive(keepAlive)
    .withSecure(secure);
}

代码示例来源:origin: jamesdbloom/mockserver

public HttpRequest update(HttpRequest replaceRequest) {
    if (!Strings.isNullOrEmpty(replaceRequest.getMethod().getValue())) {
      withMethod(replaceRequest.getMethod());
    }
    if (!Strings.isNullOrEmpty(replaceRequest.getPath().getValue())) {
      withPath(replaceRequest.getPath());
    }
    for (Header header : replaceRequest.getHeaderList()) {
      getHeaders().replaceEntry(header);
    }
    for (Cookie cookie : replaceRequest.getCookieList()) {
      withCookie(cookie);
    }
    for (Parameter parameter : replaceRequest.getQueryStringParameterList()) {
      getQueryStringParameters().replaceEntry(parameter);
    }
    if (replaceRequest.getBody() != null) {
      withBody(replaceRequest.getBody());
    }
    if (replaceRequest.isSecure() != null) {
      withSecure(replaceRequest.isSecure());
    }
    if (replaceRequest.isKeepAlive() != null) {
      withKeepAlive(replaceRequest.isKeepAlive());
    }
    return this;
  }
}

代码示例来源:origin: jamesdbloom/mockserver

@Test
public void shouldReturnResponseForRequestNotInSsl() {
  // when
  mockServerClient.when(request().withSecure(false)).respond(response().withBody("some_body"));
  // then
  // - in http
  assertEquals(
    response()
      .withStatusCode(OK_200.code())
      .withReasonPhrase(OK_200.reasonPhrase())
      .withBody("some_body"),
    makeRequest(
      request()
        .withPath(calculatePath("")),
      headersToIgnore)
  );
  // - in https
  assertEquals(
    response()
      .withStatusCode(HttpStatusCode.NOT_FOUND_404.code())
      .withReasonPhrase(HttpStatusCode.NOT_FOUND_404.reasonPhrase()),
    makeRequest(
      request()
        .withSecure(true)
        .withPath(calculatePath("")),
      headersToIgnore)
  );
}

代码示例来源:origin: jamesdbloom/mockserver

@Test
public void shouldReturnResponseForRequestInSsl() {
  // when
  mockServerClient.when(request().withSecure(true)).respond(response().withBody("some_body"));
  // then
  // - in http
  assertEquals(
    response()
      .withStatusCode(HttpStatusCode.NOT_FOUND_404.code())
      .withReasonPhrase(HttpStatusCode.NOT_FOUND_404.reasonPhrase()),
    makeRequest(
      request()
        .withPath(calculatePath("")),
      headersToIgnore)
  );
  // - in https
  assertEquals(
    response()
      .withStatusCode(OK_200.code())
      .withReasonPhrase(OK_200.reasonPhrase())
      .withBody("some_body"),
    makeRequest(
      request()
        .withSecure(true)
        .withPath(calculatePath("")),
      headersToIgnore)
  );
}

代码示例来源:origin: jamesdbloom/mockserver

@Test
public void shouldReturnResponseWithOnlyBody() {
  // when
  mockServerClient.when(request()).respond(response().withBody("some_body"));
  // then
  // - in http
  assertEquals(
    response()
      .withStatusCode(OK_200.code())
      .withReasonPhrase(OK_200.reasonPhrase())
      .withBody("some_body"),
    makeRequest(
      request()
        .withPath(calculatePath("")),
      headersToIgnore)
  );
  // - in https
  assertEquals(
    response()
      .withStatusCode(OK_200.code())
      .withReasonPhrase(OK_200.reasonPhrase())
      .withBody("some_body"),
    makeRequest(
      request()
        .withSecure(true)
        .withPath(calculatePath("")),
      headersToIgnore)
  );
}

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withPath(calculatePath("some_path"))
    .withMethod("POST"),

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withPath(calculatePath("some_path"))
    .withMethod("POST")

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withPath(calculatePath("")),
  headersToIgnore)

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withMethod("POST")
    .withPath(calculatePath("some_path"))

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withPath(calculatePath(""))
    .withBody(body, StandardCharsets.UTF_16),

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withPath(calculatePath("")),
  headersToIgnore)

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withPath(calculatePath("some_path")),
  headersToIgnore)

代码示例来源:origin: jamesdbloom/mockserver

makeRequest(
  request()
    .withSecure(true)
    .withPath(calculatePath("some_path")),
  headersToIgnore)

代码示例来源:origin: jamesdbloom/mockserver

request()
  .withHeader(CONTENT_TYPE.toString(), MediaType.create("text", "plain").withCharset(StandardCharsets.UTF_8).toString())
  .withSecure(true)
  .withPath(calculatePath(""))
  .withBody(body),

相关文章