java.lang.Object
org.elasticsearch.rest.RestRequest
- All Implemented Interfaces:
Traceable
,ToXContent.Params
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static enum
-
Field Summary
FieldsModifier and TypeFieldDescriptionInternal request parameters used as markers to indicate various operations modes such as serverless mode, or operator mode.static final String
Internal marker request parameter to indicate that a request was made by an operator user.static final String
Internal marker request parameter to indicate that a request was made in serverless mode. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
RestRequest
(RestRequest other) protected
RestRequest
(XContentParserConfiguration parserConfig, Map<String, String> params, String rawPath, Map<String, List<String>> headers, HttpRequest httpRequest, HttpChannel httpChannel) -
Method Summary
Modifier and TypeMethodDescriptionfinal void
applyContentParser
(boolean includeSourceOnError, CheckedConsumer<XContentParser, IOException> applyParser) If there is any content then callapplyParser
with the parser modified byincludeSourceOnError
, otherwise do nothing.final void
applyContentParser
(CheckedConsumer<XContentParser, IOException> applyParser) If there is any content then callapplyParser
with the parser, otherwise do nothing.content()
Returns a direct reference to the network buffer containing the request body.int
Get the content of the request or the contents of thesource
param or throw an exception if both are missing.final XContentParser
A parser for the contents of this request if it has contents, otherwise a parser for thesource
parameter if there is one, otherwise throws anElasticsearchParseException
.final XContentParser
A parser for the contents of this request if there is a body, otherwise throws anElasticsearchParseException
.Get the configuration that should be used to createXContentParser
from this request.getAllHeaderValues
(String name) Get all values for the header ornull
if the header was not foundGet all of the headers and values associated with the headers.final long
The requested version of the REST API.A consistent id for the span.final XContentType
TheXContentType
that was parsed from theContent-Type
header.boolean
final boolean
Does this request have content or asource
parameter? Use this instead ofhasContent()
if this RestHandler treats thesource
parameter like the body content.boolean
final boolean
final String
Get the value of the header ornull
if not found.boolean
boolean
boolean
SeeOPERATOR_REQUEST
boolean
boolean
void
SeeOPERATOR_REQUEST
void
method()
Returns the HTTP method used in the REST request.final String
final String
boolean
paramAsBoolean
(String key, boolean defaultValue) paramAsBoolean
(String key, Boolean defaultValue) double
paramAsDouble
(String key, double defaultValue) float
paramAsFloat
(String key, float defaultValue) int
paramAsInt
(String key, int defaultValue) long
paramAsLong
(String key, long defaultValue) paramAsSize
(String key, ByteSizeValue defaultValue) String[]
paramAsStringArray
(String key, String[] defaultValue) String[]
paramAsTime
(String key, TimeValue defaultValue) params()
static XContentType
parseContentType
(List<String> header) Parses the given content type string for the media type.final String
path()
The path part of the URI (without the query string), decoded.rawPath()
The non decoded, raw path provided.static RestRequest
request
(XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.static RestRequest
requestWithoutParameters
(XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.Returns reference to the network buffer of HTTP content or throw an exception if the body or content type is missing.uri()
The uri of the rest request, with the query string.final void
Call a consumer with the parser for the contents of this request if it has contents, otherwise with a parser for thesource
parameter if there is one, otherwise withnull
.
-
Field Details
-
SERVERLESS_REQUEST
Internal marker request parameter to indicate that a request was made in serverless mode. Use this parameter, together withOPERATOR_REQUEST
if you need to toggle behavior for serverless, for example to enforce partial API restrictions (prevent request fields, omit response fields) for an API. Requests not made in serverless mode, will *not* have this parameter set. Given a request instance, you can useisServerlessRequest()
to determine if the parameter is set or not. This is also available fromToXContent.Params
. For example:params.paramAsBoolean(RestRequest.SERVERLESS_REQUEST, false)
- See Also:
-
OPERATOR_REQUEST
Internal marker request parameter to indicate that a request was made by an operator user. Requests made by regular users (users without operator privileges), will *not* have this parameter set. Given a request instance, you can useisOperatorRequest()
to determine if the parameter is set or not. This is also available fromToXContent.Params
. For example:params.paramAsBoolean(RestRequest.OPERATOR_REQUEST, false)
- See Also:
-
INTERNAL_MARKER_REQUEST_PARAMETERS
Internal request parameters used as markers to indicate various operations modes such as serverless mode, or operator mode. These can never be set directly by end-users. Instead, they are set internally by Elasticsearch and must be supported by all request handlers.
-
-
Constructor Details
-
RestRequest
protected RestRequest(XContentParserConfiguration parserConfig, Map<String, String> params, String rawPath, Map<String, List<String>> headers, HttpRequest httpRequest, HttpChannel httpChannel) -
RestRequest
-
-
Method Details
-
isContentConsumed
public boolean isContentConsumed() -
request
public static RestRequest request(XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request.- Throws:
RestRequest.BadParameterException
- if the parameters can not be decodedRestRequest.MediaTypeHeaderException
- if the Content-Type or Accept header can not be parsed
-
requestWithoutParameters
public static RestRequest requestWithoutParameters(XContentParserConfiguration parserConfig, HttpRequest httpRequest, HttpChannel httpChannel) Creates a new REST request. The path is not decoded so this constructor will not throw aRestRequest.BadParameterException
.- Throws:
RestRequest.MediaTypeHeaderException
- if the Content-Type or Accept header can not be parsed
-
method
Returns the HTTP method used in the REST request.- Returns:
- the
RestRequest.Method
used in the REST request - Throws:
IllegalArgumentException
- if the HTTP method is invalid
-
uri
The uri of the rest request, with the query string. -
rawPath
The non decoded, raw path provided. -
path
The path part of the URI (without the query string), decoded. -
hasContent
public boolean hasContent() -
contentLength
public int contentLength() -
isFullContent
public boolean isFullContent() -
content
Returns a direct reference to the network buffer containing the request body. The HTTP layers will release their references to this buffer as soon as they have finished the synchronous steps of processing the request on the network thread, which will by default release the buffer back to the pool where it may be re-used for another request. If you need to keep the buffer alive past the end of these synchronous steps, acquire your own reference to this buffer and release it once it's no longer needed. -
isStreamedContent
public boolean isStreamedContent() -
contentStream
-
requiredContent
Returns reference to the network buffer of HTTP content or throw an exception if the body or content type is missing. Seecontent()
. -
header
Get the value of the header ornull
if not found. This method only retrieves the first header value if multiple values are sent. Use ofgetAllHeaderValues(String)
should be preferred -
getAllHeaderValues
Get all values for the header ornull
if the header was not found -
getHeaders
Get all of the headers and values associated with the headers. Modifications of this map are not supported. -
getRequestId
public final long getRequestId() -
getXContentType
TheXContentType
that was parsed from theContent-Type
header. This value will benull
in the case of a request without a validContent-Type
header, a request without content (hasContent()
, or a plain text request -
getHttpChannel
-
getHttpRequest
-
hasParam
-
param
- Specified by:
param
in interfaceToXContent.Params
-
param
- Specified by:
param
in interfaceToXContent.Params
-
params
-
paramAsFloat
-
paramAsDouble
-
paramAsInt
-
paramAsLong
-
paramAsBoolean
- Specified by:
paramAsBoolean
in interfaceToXContent.Params
-
paramAsBoolean
- Specified by:
paramAsBoolean
in interfaceToXContent.Params
-
paramAsTime
-
paramAsSize
-
paramAsStringArray
-
paramAsStringArrayOrEmptyIfAll
-
contentParserConfig
Get the configuration that should be used to createXContentParser
from this request. -
contentParser
A parser for the contents of this request if there is a body, otherwise throws anElasticsearchParseException
. UseapplyContentParser(CheckedConsumer)
if you want to gracefully handle when the request doesn't have any contents. UsecontentOrSourceParamParser()
for requests that support specifying the request body in thesource
param.- Throws:
IOException
-
applyContentParser
public final void applyContentParser(boolean includeSourceOnError, CheckedConsumer<XContentParser, IOException> applyParser) throws IOExceptionIf there is any content then callapplyParser
with the parser modified byincludeSourceOnError
, otherwise do nothing.- Throws:
IOException
-
applyContentParser
public final void applyContentParser(CheckedConsumer<XContentParser, IOException> applyParser) throws IOExceptionIf there is any content then callapplyParser
with the parser, otherwise do nothing.- Throws:
IOException
-
hasContentOrSourceParam
public final boolean hasContentOrSourceParam()Does this request have content or asource
parameter? Use this instead ofhasContent()
if this RestHandler treats thesource
parameter like the body content. -
contentOrSourceParamParser
A parser for the contents of this request if it has contents, otherwise a parser for thesource
parameter if there is one, otherwise throws anElasticsearchParseException
. UsewithContentOrSourceParamParserOrNull(CheckedConsumer)
instead if you need to handle the absence request content gracefully.- Throws:
IOException
-
withContentOrSourceParamParserOrNull
public final void withContentOrSourceParamParserOrNull(CheckedConsumer<XContentParser, IOException> withParser) throws IOExceptionCall a consumer with the parser for the contents of this request if it has contents, otherwise with a parser for thesource
parameter if there is one, otherwise withnull
. UsecontentOrSourceParamParser()
if you should throw an exception back to the user when there isn't request content.- Throws:
IOException
-
contentOrSourceParam
Get the content of the request or the contents of thesource
param or throw an exception if both are missing. PrefercontentOrSourceParamParser()
orwithContentOrSourceParamParserOrNull(CheckedConsumer)
if you need a parser. -
getParsedAccept
-
getParsedContentType
-
parseContentType
Parses the given content type string for the media type. This method currently ignores parameters. -
getRestApiVersion
The requested version of the REST API. -
hasExplicitRestApiVersion
public boolean hasExplicitRestApiVersion() -
markAsServerlessRequest
public void markAsServerlessRequest() -
isServerlessRequest
public boolean isServerlessRequest() -
markAsOperatorRequest
public void markAsOperatorRequest()SeeOPERATOR_REQUEST
-
isOperatorRequest
public boolean isOperatorRequest()SeeOPERATOR_REQUEST
-
getSpanId
Description copied from interface:Traceable
A consistent id for the span. Should be structured "[short-name]-[unique-id]" ie "request-abc1234"
-