@@ -129,9 +129,7 @@ public class ElasticsearchException extends RuntimeException implements ToXConte
129129 @ SuppressWarnings ("this-escape" )
130130 public ElasticsearchException (Throwable cause ) {
131131 super (cause );
132- if (isTimeout ()) {
133- headers .put (TIMED_OUT_HEADER , List .of ("true" ));
134- }
132+ maybePutTimeoutHeader ();
135133 }
136134
137135 /**
@@ -146,9 +144,7 @@ public ElasticsearchException(Throwable cause) {
146144 @ SuppressWarnings ("this-escape" )
147145 public ElasticsearchException (String msg , Object ... args ) {
148146 super (LoggerMessageFormat .format (msg , args ));
149- if (isTimeout ()) {
150- headers .put (TIMED_OUT_HEADER , List .of ("true" ));
151- }
147+ maybePutTimeoutHeader ();
152148 }
153149
154150 /**
@@ -165,9 +161,7 @@ public ElasticsearchException(String msg, Object... args) {
165161 @ SuppressWarnings ("this-escape" )
166162 public ElasticsearchException (String msg , Throwable cause , Object ... args ) {
167163 super (LoggerMessageFormat .format (msg , args ), cause );
168- if (isTimeout ()) {
169- headers .put (TIMED_OUT_HEADER , List .of ("true" ));
170- }
164+ maybePutTimeoutHeader ();
171165 }
172166
173167 @ SuppressWarnings ("this-escape" )
@@ -178,6 +172,13 @@ public ElasticsearchException(StreamInput in) throws IOException {
178172 metadata .putAll (in .readMapOfLists (StreamInput ::readString ));
179173 }
180174
175+ private void maybePutTimeoutHeader () {
176+ if (isTimeout ()) {
177+ // see https://www.rfc-editor.org/rfc/rfc8941.html#section-4.1.9 for booleans in structured headers
178+ headers .put (TIMED_OUT_HEADER , List .of ("?1" ));
179+ }
180+ }
181+
181182 /**
182183 * Adds a new piece of metadata with the given key.
183184 * If the provided key is already present, the corresponding metadata will be replaced
0 commit comments