From 20c6eaeb9835668876ba77138c52e70989fc2156 Mon Sep 17 00:00:00 2001 From: Puneet Khanduri Date: Sat, 3 Dec 2022 15:51:18 +0530 Subject: [PATCH] use contentEquals to compare AsciiString HeaderValues --- src/main/scala/ai/diffy/proxy/HttpEndpoint.java | 2 +- src/test/scala/ai/diffy/HttpHeaderValuesTest.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/test/scala/ai/diffy/HttpHeaderValuesTest.java diff --git a/src/main/scala/ai/diffy/proxy/HttpEndpoint.java b/src/main/scala/ai/diffy/proxy/HttpEndpoint.java index 391eab0..ace5f43 100644 --- a/src/main/scala/ai/diffy/proxy/HttpEndpoint.java +++ b/src/main/scala/ai/diffy/proxy/HttpEndpoint.java @@ -22,7 +22,7 @@ public class HttpEndpoint extends IndependentEndpoint } if(req.isFormUrlencoded() && HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED - .equals(req.requestHeaders().get(HttpHeaderNames.CONTENT_TYPE))){ + .contentEquals(req.requestHeaders().get(HttpHeaderNames.CONTENT_TYPE))){ throw new RuntimeException("Content-Type : application/x-www-form-urlencoded is not supported"); } return req.receive().aggregate().asString().toFuture().thenApply(body -> new HttpRequest( diff --git a/src/test/scala/ai/diffy/HttpHeaderValuesTest.java b/src/test/scala/ai/diffy/HttpHeaderValuesTest.java new file mode 100644 index 0000000..05f49ab --- /dev/null +++ b/src/test/scala/ai/diffy/HttpHeaderValuesTest.java @@ -0,0 +1,12 @@ +package ai.diffy; + +import io.netty.handler.codec.http.HttpHeaderValues; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class HttpHeaderValuesTest { + @Test + public void urlEncodedHeader() { + assertTrue(HttpHeaderValues.APPLICATION_X_WWW_FORM_URLENCODED.contentEquals("application/x-www-form-urlencoded")); + } +}