Skip to content

Commit 89cb890

Browse files
committed
refactor: Rename ContentTypeHeader.subtype to mediaType
The method returns the full media type (e.g. "application/json"), not the RFC 9110 subtype (e.g. "json"). Rename the method, its single caller's local variable, and the test method names to match what's actually returned.
1 parent 76049c8 commit 89cb890

3 files changed

Lines changed: 16 additions & 16 deletions

File tree

src/main/java/com/retailsvc/http/internal/ContentTypeHeader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ private ContentTypeHeader() {}
1212
* Returns the bare media type, stripping parameters and lower-casing for case-insensitive
1313
* matching (RFC 9110 / 2045). {@code null} → {@code application/json}.
1414
*/
15-
public static String subtype(String header) {
15+
public static String mediaType(String header) {
1616
if (header == null) {
1717
return "application/json";
1818
}

src/main/java/com/retailsvc/http/internal/RequestPreparationFilter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,15 @@ private Object validateAndParseBody(HttpExchange exchange, Operation op, byte[]
143143
return null;
144144
}
145145
String header = exchange.getRequestHeaders().getFirst("Content-Type");
146-
String subtype = ContentTypeHeader.subtype(header);
147-
MediaType mt = rb.get().content().get(subtype);
146+
String mediaType = ContentTypeHeader.mediaType(header);
147+
MediaType mt = rb.get().content().get(mediaType);
148148
if (mt == null) {
149149
throw new ValidationException(
150150
new ValidationError(
151-
"/body", "content-type", "unsupported content type: " + subtype, null));
151+
"/body", "content-type", "unsupported content type: " + mediaType, null));
152152
}
153153
Object parsed =
154-
switch (subtype) {
154+
switch (mediaType) {
155155
case "application/x-www-form-urlencoded" ->
156156
formParser.parseAndCoerce(body, header, mt.schema());
157157
case "text/plain" -> textParser.parse(body, header);

src/test/java/com/retailsvc/http/internal/ContentTypeHeaderTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,29 +7,29 @@
77
class ContentTypeHeaderTest {
88

99
@Test
10-
void subtypeReturnsBareMediaType() {
11-
assertThat(ContentTypeHeader.subtype("application/json")).isEqualTo("application/json");
10+
void mediaTypeReturnsBareValue() {
11+
assertThat(ContentTypeHeader.mediaType("application/json")).isEqualTo("application/json");
1212
}
1313

1414
@Test
15-
void subtypeStripsParameters() {
16-
assertThat(ContentTypeHeader.subtype("text/plain; charset=utf-8")).isEqualTo("text/plain");
15+
void mediaTypeStripsParameters() {
16+
assertThat(ContentTypeHeader.mediaType("text/plain; charset=utf-8")).isEqualTo("text/plain");
1717
}
1818

1919
@Test
20-
void subtypeTrimsWhitespace() {
21-
assertThat(ContentTypeHeader.subtype(" application/json ")).isEqualTo("application/json");
20+
void mediaTypeTrimsWhitespace() {
21+
assertThat(ContentTypeHeader.mediaType(" application/json ")).isEqualTo("application/json");
2222
}
2323

2424
@Test
25-
void subtypeDefaultsToApplicationJsonWhenNull() {
26-
assertThat(ContentTypeHeader.subtype(null)).isEqualTo("application/json");
25+
void mediaTypeDefaultsToApplicationJsonWhenNull() {
26+
assertThat(ContentTypeHeader.mediaType(null)).isEqualTo("application/json");
2727
}
2828

2929
@Test
30-
void subtypeLowerCasesMediaType() {
31-
assertThat(ContentTypeHeader.subtype("Application/JSON")).isEqualTo("application/json");
32-
assertThat(ContentTypeHeader.subtype("Text/Plain; charset=UTF-8")).isEqualTo("text/plain");
30+
void mediaTypeLowerCasesValue() {
31+
assertThat(ContentTypeHeader.mediaType("Application/JSON")).isEqualTo("application/json");
32+
assertThat(ContentTypeHeader.mediaType("Text/Plain; charset=UTF-8")).isEqualTo("text/plain");
3333
}
3434

3535
@Test

0 commit comments

Comments
 (0)