Class Request
- java.lang.Object
-
- co.elastic.apm.agent.impl.context.Request
-
- All Implemented Interfaces:
Recyclable
public class Request extends java.lang.Object implements Recyclable
RequestIf a log record was generated as a result of a http request, the http interface can be used to collect this information.
-
-
Constructor Summary
Constructors Constructor Description Request()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RequestaddCookie(java.lang.String cookieName, java.lang.String cookieValue)RequestaddFormUrlEncodedParameter(java.lang.String key, java.lang.String value)RequestaddFormUrlEncodedParameters(java.lang.String key, java.lang.String[] values)RequestaddHeader(java.lang.String headerName, java.lang.String headerValue)Adds a request header.RequestaddHeader(java.lang.String headerName, java.util.Enumeration<java.lang.String> headerValues)voidcopyFrom(Request other)voidendOfBufferInput()java.lang.ObjectgetBody()Data should only contain the request body (not the query string).java.nio.CharBuffergetBodyBuffer()Returns the associated pooledCharBufferto record the request body.java.lang.CharSequencegetBodyBufferForSerialization()Returns the body buffer if it was written to and writing to it was finished throughendOfBufferInput()PotentiallyMultiValuedMapgetCookies()A parsed key-value object of cookiesPotentiallyMultiValuedMapgetFormUrlEncodedParameters()PotentiallyMultiValuedMapgetHeaders()Should include any headers sent by the requester.java.lang.StringgetHttpVersion()HTTP version.java.lang.StringgetMethod()HTTP method.java.lang.StringgetRawBody()SocketgetSocket()UrlgetUrl()A complete Url, with scheme, host and path.booleanhasContent()voidredactBody()voidresetState()resets pooled object state so it can be reusedvoidsetRawBody(java.lang.String rawBody)Sets the body as a raw string and removes any previously setpostParamsorbodyBuffer.java.nio.CharBufferwithBodyBuffer()Gets a pooledCharBufferto record the request body and associates it with this instance.RequestwithHttpVersion(java.lang.String httpVersion)RequestwithMethod(java.lang.String method)
-
-
-
Method Detail
-
getBody
@Nullable public java.lang.Object getBody()
Data should only contain the request body (not the query string). It can either be a dictionary (for standard HTTP requests) or a raw request body.
-
getRawBody
@Nullable public java.lang.String getRawBody()
-
setRawBody
public void setRawBody(java.lang.String rawBody)
Sets the body as a raw string and removes any previously setpostParamsorbodyBuffer.- Parameters:
rawBody- the body as a raw string
-
redactBody
public void redactBody()
-
addFormUrlEncodedParameter
public Request addFormUrlEncodedParameter(java.lang.String key, java.lang.String value)
-
addFormUrlEncodedParameters
public Request addFormUrlEncodedParameters(java.lang.String key, java.lang.String[] values)
-
withBodyBuffer
public java.nio.CharBuffer withBodyBuffer()
Gets a pooledCharBufferto record the request body and associates it with this instance.Note: you may not hold a reference to the returned
CharBufferas it will be reused.Note: this method is not thread safe
Note: In order for the value written to the body buffer to be used, you must call
endOfBufferInput(), which is the only valid way to invokeCharBuffer.flip()on the body buffer.- Returns:
- a
CharBufferto record the request body
-
endOfBufferInput
public void endOfBufferInput()
-
getBodyBuffer
@Nullable public java.nio.CharBuffer getBodyBuffer()
Returns the associated pooledCharBufferto record the request body.Note: returns
nullunlesswithBodyBuffer()has previously been called- Returns:
- a
CharBufferto record the request body, ornull
-
getBodyBufferForSerialization
@Nullable public java.lang.CharSequence getBodyBufferForSerialization()
Returns the body buffer if it was written to and writing to it was finished throughendOfBufferInput()- Returns:
- body buffer if it was written to and writing was finished; returns
nullotherwise.
-
getFormUrlEncodedParameters
public PotentiallyMultiValuedMap getFormUrlEncodedParameters()
-
addHeader
public Request addHeader(java.lang.String headerName, @Nullable java.lang.String headerValue)
Adds a request header.- Parameters:
headerName- The name of the header.headerValue- The value of the header.- Returns:
this, for fluent method chaining
-
addHeader
public Request addHeader(java.lang.String headerName, @Nullable java.util.Enumeration<java.lang.String> headerValues)
-
getHeaders
public PotentiallyMultiValuedMap getHeaders()
Should include any headers sent by the requester.
-
getHttpVersion
@Nullable public java.lang.String getHttpVersion()
HTTP version.
-
withHttpVersion
public Request withHttpVersion(@Nullable java.lang.String httpVersion)
-
getMethod
@Nullable public java.lang.String getMethod()
HTTP method. (Required)
-
withMethod
public Request withMethod(@Nullable java.lang.String method)
-
getSocket
public Socket getSocket()
-
getUrl
public Url getUrl()
A complete Url, with scheme, host and path. (Required)
-
addCookie
public Request addCookie(java.lang.String cookieName, java.lang.String cookieValue)
-
getCookies
public PotentiallyMultiValuedMap getCookies()
A parsed key-value object of cookies
-
resetState
public void resetState()
Description copied from interface:Recyclableresets pooled object state so it can be reused- Specified by:
resetStatein interfaceRecyclable
-
copyFrom
public void copyFrom(Request other)
-
hasContent
public boolean hasContent()
-
-