Package org.elasticsearch.common.logging
Class HeaderWarning
org.elasticsearch.common.logging.HeaderWarning
public class HeaderWarning
extends
This is a simplistic logger that adds warning messages to HTTP headers.
Use
HeaderWarning.addWarning(message,params)
. Message will be formatted according to RFC7234.
The result will be returned as HTTP response headers.-
Field Summary
Modifier and TypeFieldDescriptionstatic
Regular expression to test if a string matches the RFC7234 specification for warning headers.static
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
message, ... params)
static
s)
Escape and encode a string as a valid RFC 7230 quoted-string.static
s, boolean stripXContentPosition)
Extracts the warning value from the value of a warning header that is formatted according to RFC 7234.static
s)
Format a warning string in the proper warning format by prepending a warn code, warn agent, wrapping the warning string in quotes, and appending the RFC 7231 date.static
static void
removeThreadContext(ThreadContext threadContext)
Remove theThreadContext
used to add warning headers to network responses.static void
setThreadContext(ThreadContext threadContext)
Set theThreadContext
used to add warning headers to network responses.Methods inherited from class java.lang.
, , , , , , , , , ,
-
Field Details
-
WARNING_HEADER_PATTERN
public static final WARNING_HEADER_PATTERNRegular expression to test if a string matches the RFC7234 specification for warning headers. This pattern assumes that the warn code is always 299. Further, this pattern assumes that the warn agent represents a version of Elasticsearch including the build hash. -
WARNING_XCONTENT_LOCATION_PATTERN
public static final WARNING_XCONTENT_LOCATION_PATTERN
-
-
Constructor Details
-
HeaderWarning
public HeaderWarning()
-
-
Method Details
-
setThreadContext
Set theThreadContext
used to add warning headers to network responses.This is expected to only be invoked by the
Node
's constructor (therefore once outside of tests).- Parameters:
threadContext
- The thread context owned by theThreadPool
(and implicitly aNode
)- Throws:
- if this
threadContext
has already been set
-
removeThreadContext
Remove theThreadContext
used to add warning headers to network responses.This is expected to only be invoked by the
Node
'sclose
method (therefore once outside of tests).- Parameters:
threadContext
- The thread context owned by theThreadPool
(and implicitly aNode
)- Throws:
- if this
threadContext
is unknown (and presumably already unset before)
-
extractWarningValueFromWarningHeader
public static extractWarningValueFromWarningHeader( s, boolean stripXContentPosition)Extracts the warning value from the value of a warning header that is formatted according to RFC 7234. That is, given a string299 Elasticsearch-6.0.0 "warning value"
, the return value of this method would bewarning value
.- Parameters:
s
- the value of a warning header formatted according to RFC 7234.- Returns:
- the extracted warning value
-
formatWarning
public static formatWarning( s)Format a warning string in the proper warning format by prepending a warn code, warn agent, wrapping the warning string in quotes, and appending the RFC 7231 date.- Parameters:
s
- the warning string to format- Returns:
- a warning value formatted according to RFC 7234
-
escapeAndEncode
public static escapeAndEncode( s)Escape and encode a string as a valid RFC 7230 quoted-string.- Parameters:
s
- the string to escape and encode- Returns:
- the escaped and encoded string
-
getXOpaqueId
public static getXOpaqueId() -
addWarning
public static void addWarning( message, ... params)
-