Skip to content

Commit e8dfcde

Browse files
committed
cleanup
1 parent 6799a85 commit e8dfcde

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

server/src/main/java/org/elasticsearch/rest/RestRequest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ public HttpBody.Stream contentStream() {
332332
public void ensureContent() {
333333
if (hasContent() == false) {
334334
throw new ElasticsearchParseException("request body is required");
335+
} else if (xContentType.get() == null) {
336+
throwValidationException("unknown content type");
335337
}
336338
}
337339

@@ -341,9 +343,6 @@ public void ensureContent() {
341343
*/
342344
public ReleasableBytesReference requiredContent() {
343345
ensureContent();
344-
if (xContentType.get() == null) {
345-
throwValidationException("unknown content type");
346-
}
347346
return content();
348347
}
349348

test/framework/src/main/java/org/elasticsearch/test/rest/FakeRestRequest.java

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,12 @@ public HttpRequest removeHeader(String header) {
117117
return new FakeHttpRequest(method, uri, body, filteredHeaders, inboundException);
118118
}
119119

120-
public int contentLength() {
121-
return Integer.parseInt(headers.getOrDefault("Content-Length", List.of("0")).getFirst());
122-
}
123-
124-
public void setContentLength(int contentLength) {
125-
headers.put("Content-Length", List.of(String.valueOf(contentLength)));
126-
}
127-
128-
public void setContentLength(HttpBody body) {
129-
if (body.isFull()) {
130-
var len = body.asFull().bytes().length();
131-
if (len > 0) {
132-
setContentLength(body.asFull().bytes().length());
133-
}
134-
}
135-
}
136-
137120
@Override
138121
public boolean hasContent() {
139-
return contentLength() > 0;
122+
return switch (body) {
123+
case HttpBody.Full full -> full.bytes().length() > 0;
124+
case HttpBody.Stream stream -> stream instanceof HttpBody.NoopStream == false;
125+
};
140126
}
141127

142128
@Override
@@ -232,7 +218,7 @@ public Builder(NamedXContentRegistry registry) {
232218
}
233219

234220
public Builder withHeaders(Map<String, List<String>> headers) {
235-
this.headers = new HashMap<>(headers);
221+
this.headers = headers;
236222
return this;
237223
}
238224

@@ -276,7 +262,6 @@ public Builder withInboundException(Exception exception) {
276262

277263
public FakeRestRequest build() {
278264
FakeHttpRequest fakeHttpRequest = new FakeHttpRequest(method, path, content, headers, inboundException);
279-
fakeHttpRequest.setContentLength(content);
280265
return new FakeRestRequest(parserConfig, fakeHttpRequest, params, new FakeHttpChannel(address));
281266
}
282267
}

0 commit comments

Comments
 (0)