本文整理了Java中org.mockserver.model.HttpRequest.withHeaders()
方法的一些代码示例,展示了HttpRequest.withHeaders()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.withHeaders()
方法的具体详情如下:
包路径:org.mockserver.model.HttpRequest
类名称:HttpRequest
方法名:withHeaders
[英]The headers to match on as a list of Header objects where the values or keys of each header can be either a string or a regex (for more details of the supported regex syntax see http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
[中]要匹配的标题作为标题对象列表,其中每个标题的值或键可以是字符串或正则表达式(有关支持的正则表达式语法的更多详细信息,请参阅http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html)
代码示例来源:origin: jamesdbloom/mockserver
private void setHeaders(HttpRequest httpRequest, HttpServletRequest httpServletRequest) {
Headers headers = new Headers();
Enumeration<String> headerNames = httpServletRequest.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
List<String> mappedHeaderValues = new ArrayList<String>();
Enumeration<String> headerValues = httpServletRequest.getHeaders(headerName);
while (headerValues.hasMoreElements()) {
mappedHeaderValues.add(headerValues.nextElement());
}
headers.withEntry(new Header(headerName, mappedHeaderValues.toArray(new String[mappedHeaderValues.size()])));
}
httpRequest.withHeaders(headers);
}
代码示例来源:origin: jamesdbloom/mockserver
public HttpRequest onRequest(HttpRequest request) {
if (request != null) {
List<String> headersToRemove = Arrays.asList(
"proxy-connection",
"connection",
"keep-alive",
"transfer-encoding",
"te",
"trailer",
"proxy-authorization",
"proxy-authenticate",
"upgrade"
);
Headers headers = new Headers();
for (Header header : request.getHeaderList()) {
if (!headersToRemove.contains(header.getName().getValue().toLowerCase(Locale.ENGLISH))) {
headers.withEntry(header);
}
}
HttpRequest clonedRequest = request.clone();
if (!headers.isEmpty()) {
clonedRequest.withHeaders(headers);
}
return clonedRequest;
} else {
return null;
}
}
}
代码示例来源:origin: jamesdbloom/mockserver
private void setHeaders(HttpRequest httpRequest, FullHttpRequest fullHttpResponse) {
Headers headers = new Headers();
HttpHeaders httpHeaders = fullHttpResponse.headers();
for (String headerName : httpHeaders.names()) {
headers.withEntry(new Header(headerName, httpHeaders.getAll(headerName)));
}
httpRequest.withHeaders(headers);
}
代码示例来源: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 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
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header(not("requestHeaderNameOne"), string("requestHeaderValueOne")),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header("OTHERrequestHeaderNameOne", "requestHeaderValueOne"),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
代码示例来源:origin: jamesdbloom/mockserver
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header(not("requestHeaderNameOne"), not("requestHeaderValueOne")),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header("requestHeaderNameOne", "requestHeaderValueOne"),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header("requestHeaderNameOne", "requestHeaderValueOne"),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
代码示例来源:origin: jamesdbloom/mockserver
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header(string("requestHeaderNameOne"), not("requestHeaderValueOne")),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header("requestHeaderNameOne", "OTHERrequestHeaderValueOne"),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
代码示例来源:origin: jamesdbloom/mockserver
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header(not("requestHeaderNameOne"), not("requestHeaderValueOne")),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header("OTHERrequestHeaderNameOne", "requestHeaderValueOne"),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
.withMethod("GET")
.withPath(calculatePath("some_pathRequest"))
.withHeaders(
header("requestHeaderNameOne", "OTHERrequestHeaderValueOne"),
header("requestHeaderNameTwo", "requestHeaderValueTwo")
代码示例来源:origin: jamesdbloom/mockserver
.withHeaders(header("headerName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue"))
.withHeaders(header("headerOtherName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue")),
headersToIgnore)
.withHeaders(header("headerOtherName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
.withHeaders(header("headerName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue"))
.withHeaders(header("headerName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue")),
headersToIgnore)
.withHeaders(header("headerName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
.withHeaders(header("headerName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue"))
.withHeaders(header("headerName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue")),
headersToIgnore)
.withHeaders(header("headerName", "headerValue"))
.withCookies(cookie("cookieName", "cookieValue")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
.withPath(calculatePath("echo"))
.withMethod("POST")
.withHeaders(
header("x-test", "test_headers_and_body")
.withPath(calculatePath("echo"))
.withMethod("POST")
.withHeaders(
header("x-test", "test_headers_and_body")
代码示例来源:origin: jamesdbloom/mockserver
param("queryStringParameterTwoName", "queryStringParameterTwoValue")
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
param("queryStringParameterTwoName", "queryStringParameterTwoValue")
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
param("bodyParameterTwoName", "Parameter Two")
))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
"&bodyParameterOneName=Parameter+One+Value+Two" +
"&bodyParameterTwoName=Parameter+Two"))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
param("bodyParameterTwoName", "Parameter Two")
))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
"&bodyParameterOneName=Parameter+One+Value+Two" +
"&bodyParameterTwoName=Parameter+Two"))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
param("bodyParameterTwoName", "Parameter Two")
))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
"&OTHERBodyParameterOneName=Parameter+One+Value+Two" +
"&bodyParameterTwoName=Parameter+Two"))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
param("bodyParameterTwoName", "Parameter Two")
))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
"&bodyParameterOneName=OTHER Parameter+One+Value+Two" +
"&bodyParameterTwoName=Parameter+Two"))
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
.withHeaders(header("headerNameRequest", "headerValueRequest"))
.withCookies(cookie("cookieNameRequest", "cookieValueRequest")),
headersToIgnore)
代码示例来源:origin: jamesdbloom/mockserver
.withHeaders(
header("headerNameRequest", "headerValueRequest")
内容来源于网络,如有侵权,请联系作者删除!