本文整理了Java中com.linecorp.armeria.common.HttpRequest.of()
方法的一些代码示例,展示了HttpRequest.of()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.of()
方法的具体详情如下:
包路径:com.linecorp.armeria.common.HttpRequest
类名称:HttpRequest
方法名:of
[英]Converts the AggregatedHttpMessage into a new HttpRequest and closes the stream.
[中]将AggregatedHttpMessage转换为新的HttpRequest并关闭流。
代码示例来源:origin: line/armeria
/**
* Creates a new {@link HttpRequest} and closes the stream.
*/
static HttpRequest of(HttpHeaders headers, HttpData content) {
return of(headers, content, HttpHeaders.EMPTY_HEADERS);
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP request and closes the stream.
*
* @param method the HTTP method of the request
* @param path the path of the request
* @param mediaType the {@link MediaType} of the request content
* @param content the content of the request
*/
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, HttpData content) {
return of(method, path, mediaType, content, HttpHeaders.EMPTY_HEADERS);
}
代码示例来源:origin: line/armeria
/**
* Creates a new {@link HttpRequest} with empty content and closes the stream.
*/
static HttpRequest of(HttpHeaders headers) {
return of(headers, HttpData.EMPTY_DATA);
}
代码示例来源:origin: line/armeria
/**
* Converts this message into a new complete {@link HttpRequest}.
*
* @deprecated Use {@link HttpRequest#of(AggregatedHttpMessage)}.
*/
@Deprecated
default HttpRequest toHttpRequest() {
return HttpRequest.of(this);
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP request with empty content and closes the stream.
*
* @param method the HTTP method of the request
* @param path the path of the request
*/
static HttpRequest of(HttpMethod method, String path) {
requireNonNull(method, "method");
requireNonNull(path, "path");
return of(HttpHeaders.of(method, path));
}
代码示例来源:origin: line/armeria
HttpResponse execute(@Nullable EventLoop eventLoop, AggregatedHttpMessage aggregatedReq) {
return execute(eventLoop, HttpRequest.of(aggregatedReq));
}
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP request and closes the stream.
*
* @param method the HTTP method of the request
* @param path the path of the request
* @param mediaType the {@link MediaType} of the request content
* @param content the content of the request
*/
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, byte[] content) {
requireNonNull(content, "content");
return of(method, path, mediaType, HttpData.of(content));
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP request and closes the stream.
*
* @param method the HTTP method of the request
* @param path the path of the request
* @param mediaType the {@link MediaType} of the request content
* @param content the content of the request
*/
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, String content) {
requireNonNull(content, "content");
requireNonNull(mediaType, "mediaType");
return of(method, path,
mediaType, content.getBytes(mediaType.charset().orElse(StandardCharsets.UTF_8)));
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP request and closes the stream.
*
* @param method the HTTP method of the request
* @param path the path of the request
* @param mediaType the {@link MediaType} of the request content
* @param content the content of the request
* @param offset the start offset of {@code content}
* @param length the length of {@code content}
*/
static HttpRequest of(
HttpMethod method, String path, MediaType mediaType, byte[] content, int offset, int length) {
requireNonNull(content, "content");
return of(method, path, mediaType, HttpData.of(content, offset, length));
}
代码示例来源:origin: line/armeria
private Mono<Void> write(Flux<? extends DataBuffer> body) {
return doCommit(execute(() -> HttpRequest.of(headers, body.map(factoryWrapper::toHttpData))));
}
代码示例来源:origin: line/armeria
/**
* Creates a new HTTP request and closes the stream.
*
* @param method the HTTP method of the request
* @param path the path of the request
* @param mediaType the {@link MediaType} of the request content
* @param content the content of the request
* @param trailingHeaders the trailing HTTP headers
*/
static HttpRequest of(HttpMethod method, String path, MediaType mediaType, HttpData content,
HttpHeaders trailingHeaders) {
requireNonNull(method, "method");
requireNonNull(path, "path");
requireNonNull(mediaType, "mediaType");
return of(HttpHeaders.of(method, path).contentType(mediaType), content, trailingHeaders);
}
代码示例来源:origin: line/armeria
@Override
public Mono<Void> setComplete() {
return isCommitted() ? Mono.empty()
: doCommit(execute(() -> HttpRequest.of(headers)));
}
代码示例来源:origin: line/armeria
/**
* Converts the {@link AggregatedHttpMessage} into a new {@link HttpRequest} and closes the stream.
*/
static HttpRequest of(AggregatedHttpMessage message) {
return of(message.headers(), message.content(), message.trailingHeaders());
}
代码示例来源:origin: line/armeria
private AggregatedHttpMessage sendViaHttpPostBindingProtocol(
String path, String paramName, SignableSAMLObject sinableObj) throws Exception {
final String encoded = toSignedBase64(sinableObj, idpCredential, signatureAlgorithm);
final QueryStringEncoder encoder = new QueryStringEncoder("/");
encoder.addParam(paramName, encoded);
final HttpRequest req = HttpRequest.of(HttpMethod.POST, path, MediaType.FORM_DATA,
encoder.toUri().getRawQuery());
return client.execute(req).aggregate().join();
}
代码示例来源:origin: line/armeria
@Test
public void getCookies() {
final HttpRequest httpRequest = HttpRequest.of(HttpHeaders.of(HttpMethod.POST, "/")
.add(HttpHeaderNames.COOKIE, "a=1;b=2"));
final ServiceRequestContext ctx = newRequestContext(httpRequest);
final ArmeriaServerHttpRequest req = request(ctx);
// Check cached.
final MultiValueMap<String, HttpCookie> cookie1 = req.getCookies();
final MultiValueMap<String, HttpCookie> cookie2 = req.getCookies();
assertThat(cookie1 == cookie2).isTrue();
assertThat(cookie1.get("a")).containsExactly(new HttpCookie("a", "1"));
assertThat(cookie1.get("b")).containsExactly(new HttpCookie("b", "2"));
}
代码示例来源:origin: line/armeria
@Test
public void missingContentType() throws Exception {
final HttpRequest req = HttpRequest.of(HttpMethod.POST, "/grpc.testing.TestService.UnaryCall");
final ServiceRequestContext ctx = ServiceRequestContext.of(req);
final HttpResponse response = grpcService.doPost(ctx, req);
assertThat(response.aggregate().get()).isEqualTo(AggregatedHttpMessage.of(
HttpHeaders.of(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
.contentType(MediaType.PLAIN_TEXT_UTF_8)
.setInt(HttpHeaderNames.CONTENT_LENGTH, 39),
HttpData.ofUtf8("Missing or invalid Content-Type header.")));
}
代码示例来源:origin: line/armeria
private AggregatedHttpMessage sendViaHttpRedirectBindingProtocol(
String path, String paramName, SAMLObject samlObject) throws Exception {
final QueryStringEncoder encoder = new QueryStringEncoder("/");
encoder.addParam(paramName, toDeflatedBase64(samlObject));
encoder.addParam(SIGNATURE_ALGORITHM, signatureAlgorithm);
final String input = encoder.toUri().getRawQuery();
final String output = generateSignature(idpCredential, signatureAlgorithm, input);
encoder.addParam(SIGNATURE, output);
final HttpRequest req = HttpRequest.of(HttpMethod.POST, path, MediaType.FORM_DATA,
encoder.toUri().getRawQuery());
return client.execute(req).aggregate().join();
}
}
代码示例来源:origin: line/armeria
@Test
public void badContentType() throws Exception {
final HttpRequest req = HttpRequest.of(
HttpHeaders.of(HttpMethod.POST, "/grpc.testing.TestService.UnaryCall")
.contentType(MediaType.JSON_UTF_8));
final ServiceRequestContext ctx = ServiceRequestContext.of(req);
final HttpResponse response = grpcService.doPost(ctx, req);
assertThat(response.aggregate().get()).isEqualTo(AggregatedHttpMessage.of(
HttpHeaders.of(HttpStatus.UNSUPPORTED_MEDIA_TYPE)
.contentType(MediaType.PLAIN_TEXT_UTF_8)
.setInt(HttpHeaderNames.CONTENT_LENGTH, 39),
HttpData.ofUtf8("Missing or invalid Content-Type header.")));
}
代码示例来源:origin: line/armeria
@Before
public void setUp() {
request = HttpRequest.of(HttpMethod.POST,
"/armeria.grpc.testing.TestService/EmptyCall",
MediaType.JSON_UTF_8, "{}");
ctx = ServiceRequestContextBuilder.of(request).eventLoop(eventLoop.get()).build();
}
代码示例来源:origin: line/armeria
@Test
public void pathMissingSlash() throws Exception {
final HttpRequest req = HttpRequest.of(
HttpHeaders.of(HttpMethod.POST, "/grpc.testing.TestService.UnaryCall")
.set(HttpHeaderNames.CONTENT_TYPE, "application/grpc+proto"));
final PathMappingResult pathMappingResult = PathMappingResult.of("grpc.testing.TestService.UnaryCall");
final ServiceRequestContext ctx = ServiceRequestContextBuilder.of(req)
.pathMappingResult(pathMappingResult)
.build();
final HttpResponse response = grpcService.doPost(ctx, req);
assertThat(response.aggregate().get()).isEqualTo(AggregatedHttpMessage.of(
HttpHeaders.of(HttpStatus.BAD_REQUEST)
.contentType(MediaType.PLAIN_TEXT_UTF_8)
.setInt(HttpHeaderNames.CONTENT_LENGTH, 13),
HttpData.ofUtf8("Invalid path.")));
}
内容来源于网络,如有侵权,请联系作者删除!