Concrete MediaType check in StringHttpMessageConverter

Closes gh-23287
This commit is contained in:
Rossen Stoyanchev
2020-01-07 14:00:27 +00:00
parent c480a99a77
commit 9d963abb7d
3 changed files with 20 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -131,4 +131,16 @@ public class StringHttpMessageConverterTests {
assertThat(headers.getAcceptCharset().isEmpty()).isTrue();
}
@Test // gh-24283
public void writeWithWildCardMediaType() throws IOException {
String body = "Hello World";
this.converter.write(body, MediaType.ALL, this.outputMessage);
HttpHeaders headers = this.outputMessage.getHeaders();
assertThat(this.outputMessage.getBodyAsString(StandardCharsets.US_ASCII)).isEqualTo(body);
assertThat(headers.getContentType()).isEqualTo(new MediaType("text", "plain", StandardCharsets.ISO_8859_1));
assertThat(headers.getContentLength()).isEqualTo(body.getBytes().length);
assertThat(headers.getAcceptCharset().isEmpty()).isTrue();
}
}