Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import java.util.Locale;

import io.netty.buffer.ByteBuf;
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;
import io.netty.handler.codec.http.HttpHeaders;
Expand All @@ -51,6 +54,7 @@

public final class HttpUtils {

public static final ByteBufAllocator HEAP_ALLOC = new UnpooledByteBufAllocator(false, false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using heap instend of dicrect

public static final HttpDataFactory DATA_FACTORY = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE);
public static final String CHARSET_PREFIX = "charset=";

Expand Down Expand Up @@ -164,7 +168,13 @@ public static HttpPostRequestDecoder createPostRequestDecoder(
if (canMark) {
inputStream.mark(Integer.MAX_VALUE);
}
data = Unpooled.wrappedBuffer(StreamUtils.readBytes(inputStream));
if (inputStream.available() == 0) {
data = Unpooled.EMPTY_BUFFER;
} else {
data = HEAP_ALLOC.buffer();
ByteBufOutputStream os = new ByteBufOutputStream(data);
StreamUtils.copy(inputStream, os);
}
} catch (IOException e) {
throw new DecodeException("Error while reading post data: " + e.getMessage(), e);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.dubbo.common.threadpool.manager.ExecutorRepository;
import org.apache.dubbo.common.threadpool.serial.SerializingExecutor;
import org.apache.dubbo.common.utils.MethodUtils;
import org.apache.dubbo.common.utils.UrlUtils;
import org.apache.dubbo.remoting.http12.HttpChannel;
import org.apache.dubbo.remoting.http12.HttpInputMessage;
import org.apache.dubbo.remoting.http12.HttpStatus;
Expand Down Expand Up @@ -278,14 +279,27 @@ protected final RpcInvocation buildRpcInvocation(RpcInvocationBuildContext conte
if (consumerAppName != null) {
inv.put(TripleHeaderEnum.CONSUMER_APP_NAME_KEY, consumerAppName);
}

// customizer RpcInvocation
headerFilters.forEach(f -> f.invoke(invoker, inv));
HeaderFilter[] headerFilters =
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lost when merging code.

UrlUtils.computeServiceAttribute(invoker.getUrl(), HEADER_FILTERS_CACHE, this::loadHeaderFilters);
for (HeaderFilter headerFilter : headerFilters) {
headerFilter.invoke(invoker, inv);
}

initializeAltSvc(url);

return onBuildRpcInvocationCompletion(inv);
}

private HeaderFilter[] loadHeaderFilters(URL url) {
List<HeaderFilter> headerFilters = frameworkModel
.getExtensionLoader(HeaderFilter.class)
.getActivateExtension(url, CommonConstants.HEADER_FILTER_KEY);
LOGGER.info("Header filters for [{}] loaded: {}", url, headerFilters);
return headerFilters.toArray(new HeaderFilter[0]);
}

protected RpcInvocation onBuildRpcInvocationCompletion(RpcInvocation invocation) {
String timeoutString = httpMetadata.header(TripleHeaderEnum.SERVICE_TIMEOUT.getKey());
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,20 @@ class RestProtocolTest extends BaseServiceTest {
'/argTest' | 'Sam is 8 years old'
}

def "urlEncodeForm body test"() {
given:
def request = new TestRequest(
path: path,
contentType: MediaType.APPLICATION_FROM_URLENCODED,
body: body
)
expect:
runner.post(request) == output
where:
path | body | output
'/argTest' | 'name=Sam&age=8' | 'Sam is 8 years old'
}

def "override mapping test"() {
expect:
runner.get(path) == output
Expand Down