All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.inverno.mod.http.server.internal.http1x.Http1xRequest Maven / Gradle / Ivy

There is a newer version: 1.11.0
Show newest version
/*
 * Copyright 2020 Jeremy KUHN
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.inverno.mod.http.server.internal.http1x;

import io.inverno.mod.base.converter.ObjectConverter;
import io.inverno.mod.base.net.URIBuilder;
import io.inverno.mod.base.net.URIs;
import io.inverno.mod.http.base.InboundRequestHeaders;
import io.inverno.mod.http.base.Method;
import io.inverno.mod.http.base.Parameter;
import io.inverno.mod.http.base.header.Headers;
import io.inverno.mod.http.server.Part;
import io.inverno.mod.http.server.Request;
import io.inverno.mod.http.server.internal.AbstractRequest;
import io.inverno.mod.http.server.internal.multipart.MultipartDecoder;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.HttpRequest;
import io.netty.handler.ssl.SslHandler;
import java.util.Optional;
import reactor.core.publisher.Sinks.Many;

/**
 * 

* HTTP1.x {@link Request} implementation. *

* * @author Jeremy Kuhn * @since 1.0 */ class Http1xRequest extends AbstractRequest { private final HttpRequest underlyingRequest; private URIBuilder pathBuilder; private Method method; private String scheme; private String authority; /** *

* Creates a HTTP1.x server request. *

* * @param context the channel handler context * @param httpRequest the underlying HTTP request * @param requestHeaders the HTTP1.x request headers * @param parameterConverter a string object converter * @param urlEncodedBodyDecoder the application/x-www-form-urlencoded body decoder * @param multipartBodyDecoder the multipart/form-data body decoder */ public Http1xRequest(ChannelHandlerContext context, HttpRequest httpRequest, InboundRequestHeaders requestHeaders, ObjectConverter parameterConverter, MultipartDecoder urlEncodedBodyDecoder, MultipartDecoder multipartBodyDecoder) { super(context, requestHeaders, parameterConverter, urlEncodedBodyDecoder, multipartBodyDecoder); this.underlyingRequest = httpRequest; } HttpRequest getUnderlyingRequest() { return underlyingRequest; } @Override protected URIBuilder getPrimaryPathBuilder() { if(this.pathBuilder == null) { this.pathBuilder = URIs.uri(this.underlyingRequest.uri(), false, URIs.Option.NORMALIZED); } return this.pathBuilder; } @Override public Optional> data() { // In order to support pipelining we must always create the data sink even if // it might not be consumed by the exchange handler // This comes from the fact that the exchange is only started after the previous // exchange has completed, which means we can receive data before we actually // invoke the exchange handler which is supposed to create the body this.body(); return super.data(); } @Override public Method getMethod() { if(this.method == null) { try { this.method = Method.valueOf(this.underlyingRequest.method().name()); } catch (IllegalArgumentException e) { this.method = Method.UNKNOWN; } } return method; } @Override public String getScheme() { if(this.scheme == null) { this.scheme = this.context.pipeline().get(SslHandler.class) != null ? "https" : "http"; } return this.scheme; } @Override public String getAuthority() { if(this.authority == null) { this.authority = this.requestHeaders.get((CharSequence)Headers.NAME_HOST).orElse(null); } return this.authority; } @Override public String getPath() { return this.underlyingRequest.uri(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy