diff --git a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpUtils.java b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpUtils.java index 488242d921c..d20ccec53cb 100644 --- a/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpUtils.java +++ b/dubbo-remoting/dubbo-remoting-http12/src/main/java/org/apache/dubbo/remoting/http12/HttpUtils.java @@ -32,7 +32,6 @@ import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.ByteBufInputStream; import io.netty.buffer.ByteBufOutputStream; -import io.netty.buffer.Unpooled; import io.netty.buffer.UnpooledByteBufAllocator; import io.netty.handler.codec.http.DefaultFullHttpRequest; import io.netty.handler.codec.http.DefaultHttpHeaders; @@ -169,7 +168,7 @@ public static HttpPostRequestDecoder createPostRequestDecoder( inputStream.mark(Integer.MAX_VALUE); } if (inputStream.available() == 0) { - data = Unpooled.EMPTY_BUFFER; + return null; } else { data = HEAP_ALLOC.buffer(); ByteBufOutputStream os = new ByteBufOutputStream(data); diff --git a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/RestProtocolTest.groovy b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/RestProtocolTest.groovy index 430a646d019..57e836d44ac 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/RestProtocolTest.groovy +++ b/dubbo-rpc/dubbo-rpc-triple/src/test/groovy/org/apache/dubbo/rpc/protocol/tri/rest/support/basic/RestProtocolTest.groovy @@ -24,6 +24,9 @@ import org.apache.dubbo.rpc.protocol.tri.rest.test.BaseServiceTest import org.apache.dubbo.rpc.protocol.tri.test.TestRequest import org.apache.dubbo.rpc.protocol.tri.test.TestRunnerBuilder +import io.netty.buffer.AbstractByteBuf +import io.netty.util.ResourceLeakDetector + class RestProtocolTest extends BaseServiceTest { @Override @@ -174,8 +177,14 @@ class RestProtocolTest extends BaseServiceTest { '/argTest' | 'Sam is 8 years old' } + @SuppressWarnings('GroovyAccessibility') def "urlEncodeForm body test"() { given: + def level = ResourceLeakDetector.level + def leaks = AbstractByteBuf.leakDetector.allLeaks + ResourceLeakDetector.level = ResourceLeakDetector.Level.PARANOID + leaks.clear() + and: def request = new TestRequest( path: path, contentType: MediaType.APPLICATION_FROM_URLENCODED, @@ -183,9 +192,13 @@ class RestProtocolTest extends BaseServiceTest { ) expect: runner.post(request) == output + leaks.empty + cleanup: + ResourceLeakDetector.level = level where: path | body | output '/argTest' | 'name=Sam&age=8' | 'Sam is 8 years old' + '/argTest' | '' | 'null is 0 years old' } def "override mapping test"() {