Skip to content

Commit 7eb388d

Browse files
committed
feedback
1 parent 50674a5 commit 7eb388d

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

server/src/main/java/org/elasticsearch/ElasticsearchException.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

server/src/test/java/org/elasticsearch/ElasticsearchExceptionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ public void testTimeout() throws IOException {
15781578
"reason": "some timeout",
15791579
"timed_out": true,
15801580
"header": {
1581-
"X-Timed-Out": "true"
1581+
"X-Timed-Out": "?1"
15821582
}
15831583
}""";
15841584
assertEquals(XContentHelper.stripWhitespace(expected), Strings.toString(builder));

0 commit comments

Comments
 (0)