本文整理了Java中io.micronaut.http.HttpRequest.getContentType()
方法的一些代码示例,展示了HttpRequest.getContentType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.getContentType()
方法的具体详情如下:
包路径:io.micronaut.http.HttpRequest
类名称:HttpRequest
方法名:getContentType
暂无
代码示例来源:origin: micronaut-projects/micronaut-core
@Override
public Optional<MediaType> getContentType() {
MediaType contentType = this.mediaType;
if (contentType == null) {
synchronized (this) { // double check
contentType = this.mediaType;
if (contentType == null) {
contentType = HttpRequest.super.getContentType().orElse(null);
this.mediaType = contentType;
}
}
}
return Optional.ofNullable(contentType);
}
代码示例来源:origin: micronaut-projects/micronaut-core
/**
* Return whether the given request features {@link MediaType#APPLICATION_FORM_URLENCODED} or
* {@link MediaType#MULTIPART_FORM_DATA}.
*
* @param request The request
* @return True if it is form data
*/
public static boolean isFormData(HttpRequest<?> request) {
Optional<MediaType> opt = request.getContentType();
if (opt.isPresent()) {
MediaType contentType = opt.get();
return (contentType.equals(MediaType.APPLICATION_FORM_URLENCODED_TYPE) || contentType.equals(MediaType.MULTIPART_FORM_DATA_TYPE));
}
return false;
}
代码示例来源:origin: micronaut-projects/micronaut-core
private <I> void prepareHttpHeaders(URI requestURI, io.micronaut.http.HttpRequest<I> request, io.netty.handler.codec.http.HttpRequest nettyRequest, boolean permitsBody, boolean closeConnection) {
HttpHeaders headers = nettyRequest.headers();
headers.set(HttpHeaderNames.HOST, getHostHeader(requestURI));
if (closeConnection) {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
} else {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
if (permitsBody) {
Optional<I> body = request.getBody();
if (body.isPresent()) {
if (!headers.contains(HttpHeaderNames.CONTENT_TYPE)) {
MediaType mediaType = request.getContentType().orElse(MediaType.APPLICATION_JSON_TYPE);
headers.set(HttpHeaderNames.CONTENT_TYPE, mediaType);
}
if (nettyRequest instanceof FullHttpRequest) {
FullHttpRequest fullHttpRequest = (FullHttpRequest) nettyRequest;
headers.set(HttpHeaderNames.CONTENT_LENGTH, fullHttpRequest.content().readableBytes());
} else {
headers.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
}
} else {
headers.set(HttpHeaderNames.CONTENT_LENGTH, 0);
}
}
}
代码示例来源:origin: micronaut-projects/micronaut-core
private <I> NettyRequestWriter prepareRequest(io.micronaut.http.HttpRequest<I> request, URI requestURI) throws HttpPostRequestEncoder.ErrorDataEncoderException {
MediaType requestContentType = request
.getContentType()
.orElse(MediaType.APPLICATION_JSON_TYPE);
boolean permitsBody = io.micronaut.http.HttpMethod.permitsRequestBody(request.getMethod());
NettyClientHttpRequest clientHttpRequest = (NettyClientHttpRequest) request;
NettyRequestWriter requestWriter = buildNettyRequest(clientHttpRequest, requestURI, requestContentType, permitsBody);
io.netty.handler.codec.http.HttpRequest nettyRequest = requestWriter.getNettyRequest();
prepareHttpHeaders(requestURI, request, nettyRequest, permitsBody, true);
return requestWriter;
}
代码示例来源:origin: micronaut-projects/micronaut-core
Optional<MediaType> contentType = source.getContentType();
HttpContentProcessor<?> processor = contentType
.flatMap(type -> beanLocator.findBean(HttpContentSubscriberFactory.class, new ConsumesMediaTypeQualifier<>(type)))
代码示例来源:origin: micronaut-projects/micronaut-core
URI requestURI = finalRequest.getUri();
MediaType requestContentType = finalRequest
.getContentType()
.orElse(MediaType.APPLICATION_JSON_TYPE);
代码示例来源:origin: micronaut-projects/micronaut-core
Flowable<HttpContent> httpContentFlowable = Flowable.fromPublisher(nettyStreamedHttpResponse.getNettyResponse());
boolean isJsonStream = request.getContentType().map(mediaType -> mediaType.equals(MediaType.APPLICATION_JSON_STREAM_TYPE)).orElse(false);
boolean streamArray = !Iterable.class.isAssignableFrom(type.getType()) && !isJsonStream;
JacksonProcessor jacksonProcessor = new JacksonProcessor(mediaTypeCodec.getObjectMapper().getFactory(), streamArray) {
代码示例来源:origin: micronaut-projects/micronaut-core
io.netty.handler.codec.http.HttpRequest nativeRequest = nettyHttpRequest.getNativeRequest();
if (nativeRequest instanceof StreamedHttpRequest) {
Optional<MediaType> contentType = source.getContentType();
Argument<?> targetType = context.getFirstTypeVariable().orElse(Argument.OBJECT_ARGUMENT);
HttpContentProcessor<?> processor = contentType
代码示例来源:origin: micronaut-projects/micronaut-core
MediaType contentType = request.getContentType().orElse(null);
if (contentType != null) {
if (!existingRouteConsumes.contains(contentType)) {
代码示例来源:origin: micronaut-projects/micronaut-core
if (poolMap != null && !MediaType.MULTIPART_FORM_DATA_TYPE.equals(request.getContentType().orElse(null))) {
ChannelPool channelPool = poolMap.get(new RequestKey(requestURI));
Future<Channel> channelFuture = channelPool.acquire();
代码示例来源:origin: io.micronaut/micronaut-http
/**
* Return whether the given request features {@link MediaType#APPLICATION_FORM_URLENCODED} or
* {@link MediaType#MULTIPART_FORM_DATA}.
*
* @param request The request
* @return True if it is form data
*/
public static boolean isFormData(HttpRequest<?> request) {
Optional<MediaType> opt = request.getContentType();
if (opt.isPresent()) {
MediaType contentType = opt.get();
return (contentType.equals(MediaType.APPLICATION_FORM_URLENCODED_TYPE) || contentType.equals(MediaType.MULTIPART_FORM_DATA_TYPE));
}
return false;
}
代码示例来源:origin: io.micronaut/http-client
private <I> void prepareHttpHeaders(URI requestURI, io.micronaut.http.HttpRequest<I> request, io.netty.handler.codec.http.HttpRequest nettyRequest, boolean permitsBody, boolean closeConnection) {
HttpHeaders headers = nettyRequest.headers();
headers.set(HttpHeaderNames.HOST, requestURI.getHost());
if (closeConnection) {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
} else {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
if (permitsBody) {
Optional<I> body = request.getBody();
if (body.isPresent()) {
if (!headers.contains(HttpHeaderNames.CONTENT_TYPE)) {
MediaType mediaType = request.getContentType().orElse(MediaType.APPLICATION_JSON_TYPE);
headers.set(HttpHeaderNames.CONTENT_TYPE, mediaType);
}
if (nettyRequest instanceof FullHttpRequest) {
FullHttpRequest fullHttpRequest = (FullHttpRequest) nettyRequest;
headers.set(HttpHeaderNames.CONTENT_LENGTH, fullHttpRequest.content().readableBytes());
} else {
headers.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
}
}
}
}
代码示例来源:origin: io.micronaut/micronaut-http-client
private <I> void prepareHttpHeaders(URI requestURI, io.micronaut.http.HttpRequest<I> request, io.netty.handler.codec.http.HttpRequest nettyRequest, boolean permitsBody, boolean closeConnection) {
HttpHeaders headers = nettyRequest.headers();
headers.set(HttpHeaderNames.HOST, getHostHeader(requestURI));
if (closeConnection) {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
} else {
headers.set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
if (permitsBody) {
Optional<I> body = request.getBody();
if (body.isPresent()) {
if (!headers.contains(HttpHeaderNames.CONTENT_TYPE)) {
MediaType mediaType = request.getContentType().orElse(MediaType.APPLICATION_JSON_TYPE);
headers.set(HttpHeaderNames.CONTENT_TYPE, mediaType);
}
if (nettyRequest instanceof FullHttpRequest) {
FullHttpRequest fullHttpRequest = (FullHttpRequest) nettyRequest;
headers.set(HttpHeaderNames.CONTENT_LENGTH, fullHttpRequest.content().readableBytes());
} else {
headers.set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
}
} else {
headers.set(HttpHeaderNames.CONTENT_LENGTH, 0);
}
}
}
代码示例来源:origin: io.micronaut/http-client
private <I> NettyRequestWriter prepareRequest(io.micronaut.http.HttpRequest<I> request, URI requestURI) throws HttpPostRequestEncoder.ErrorDataEncoderException {
MediaType requestContentType = request
.getContentType()
.orElse(MediaType.APPLICATION_JSON_TYPE);
boolean permitsBody = io.micronaut.http.HttpMethod.permitsRequestBody(request.getMethod());
NettyClientHttpRequest clientHttpRequest = (NettyClientHttpRequest) request;
NettyRequestWriter requestWriter = buildNettyRequest(clientHttpRequest, requestURI, requestContentType, permitsBody);
io.netty.handler.codec.http.HttpRequest nettyRequest = requestWriter.getNettyRequest();
prepareHttpHeaders(requestURI, request, nettyRequest, permitsBody, true);
return requestWriter;
}
代码示例来源:origin: io.micronaut/micronaut-http-client
private <I> NettyRequestWriter prepareRequest(io.micronaut.http.HttpRequest<I> request, URI requestURI) throws HttpPostRequestEncoder.ErrorDataEncoderException {
MediaType requestContentType = request
.getContentType()
.orElse(MediaType.APPLICATION_JSON_TYPE);
boolean permitsBody = io.micronaut.http.HttpMethod.permitsRequestBody(request.getMethod());
NettyClientHttpRequest clientHttpRequest = (NettyClientHttpRequest) request;
NettyRequestWriter requestWriter = buildNettyRequest(clientHttpRequest, requestURI, requestContentType, permitsBody);
io.netty.handler.codec.http.HttpRequest nettyRequest = requestWriter.getNettyRequest();
prepareHttpHeaders(requestURI, request, nettyRequest, permitsBody, true);
return requestWriter;
}
代码示例来源:origin: io.micronaut/http-client
io.micronaut.http.HttpRequest<I> finalRequest = requestWrapper.get();
MediaType requestContentType = finalRequest
.getContentType()
.orElse(MediaType.APPLICATION_JSON_TYPE);
代码示例来源:origin: io.micronaut/micronaut-http-client
URI requestURI = finalRequest.getUri();
MediaType requestContentType = finalRequest
.getContentType()
.orElse(MediaType.APPLICATION_JSON_TYPE);
代码示例来源:origin: io.micronaut/micronaut-http-client
Flowable<HttpContent> httpContentFlowable = Flowable.fromPublisher(nettyStreamedHttpResponse.getNettyResponse());
boolean isJsonStream = request.getContentType().map(mediaType -> mediaType.equals(MediaType.APPLICATION_JSON_STREAM_TYPE)).orElse(false);
boolean streamArray = !Iterable.class.isAssignableFrom(type.getType()) && !isJsonStream;
JacksonProcessor jacksonProcessor = new JacksonProcessor(mediaTypeCodec.getObjectMapper().getFactory(), streamArray) {
代码示例来源:origin: io.micronaut/http-client
Flowable<HttpContent> httpContentFlowable = Flowable.fromPublisher(nettyStreamedHttpResponse.getNettyResponse());
boolean isJsonStream = request.getContentType().map(mediaType -> mediaType.equals(MediaType.APPLICATION_JSON_STREAM_TYPE)).orElse(false);
boolean streamArray = !Iterable.class.isAssignableFrom(type.getType()) && !isJsonStream;
JacksonProcessor jacksonProcessor = new JacksonProcessor(mediaTypeCodec.getObjectMapper().getFactory(), streamArray) {
代码示例来源:origin: io.micronaut/http-client
if (poolMap != null && !MediaType.MULTIPART_FORM_DATA_TYPE.equals(request.getContentType().orElse(null))) {
ChannelPool channelPool = poolMap.get(new RequestKey(requestURI));
Future<Channel> channelFuture = channelPool.acquire();
内容来源于网络,如有侵权,请联系作者删除!