io.inverno.mod.http.server.RequestBody Maven / Gradle / Ivy
Show all versions of inverno-http-server Show documentation
/*
* 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;
import io.inverno.mod.http.base.InboundData;
import io.inverno.mod.http.base.Parameter;
import io.netty.buffer.ByteBuf;
import java.util.Map;
import org.reactivestreams.Publisher;
import java.util.function.Function;
import reactor.core.publisher.Mono;
/**
*
* Represents the payload body of a client request in a server exchange.
*
*
*
* The request body basically provides multiple ways to consume the request payload depending on the request content type.
*
*
* @author Jeremy Kuhn
* @since 1.0
*
* @see Request
*/
public interface RequestBody {
/**
*
* Transforms the payload publisher.
*
*
*
* This can be used in an exchange interceptor in order to decorate the request data publisher.
*
*
* @param transformer a request payload publisher transformer
*
* @return the request body
*/
RequestBody transform(Function, Publisher> transformer);
/**
*
* Returns a raw payload consumer.
*
*
* @return the raw data
*
* @throws IllegalStateException if the payload has already been consumed using another decoder
*/
InboundData raw() throws IllegalStateException;
/**
*
* Returns a string payload consumer.
*
*
* @return the string data
*
* @throws IllegalStateException if the payload has already been consumed using another decoder
*/
InboundData string() throws IllegalStateException;
/**
*
* Returns a multipart/form-data payload consumer.
*
*
* @return body a multipart/form-data payload consumer
*
* @throws IllegalStateException if the payload has already been consumed using another decoder
*/
RequestBody.Multipart extends Part> multipart() throws IllegalStateException;
/**
*
* Returns an application/x-www-form-urlencoded payload consumer.
*
*
* @return body an application/x-www-form-urlencoded payload consumer
*
* @throws IllegalStateException if the payload has already been consumed using another decoder
*/
RequestBody.UrlEncoded urlEncoded() throws IllegalStateException;
/**
*
* A multipart/form-data consumer as defined by RFC 7578.
*
*
* @author Jeremy Kuhn
* @since 1.0
*
* @param the part type
*/
public static interface Multipart extends InboundData {
}
/**
*
* An application/x-www-form-urlencoded data consumer as defined by application/x-www-form-urlencoded.
*
*
*
* Note that, unlike other the body decoders, parameters publishers are cached and can be subscribed by mutliple subscribers.
*
*
* @author Jeremy Kuhn
* @since 1.0
*/
public static interface UrlEncoded extends InboundData {
/**
*
* Collects all parameters in a map that is emitted by the resulting Mono.
*
*
* @return a Mono of a map with parameter name as key and parameter as value
*/
Mono