Skip to content

Commit 6ebdde6

Browse files
authored
trpc-proto-http: fix response header parsing in HttpConsumerInvoker (#135)
* trpc-proto-http: fix response header parsing in HttpConsumerInvoker The previous implementation iterated over HeaderElement objects and called element.getName() to extract header values. This only returns the token before the first '=' or ';' delimiter, causing truncation of composite header values such as: Content-Type: application/json; charset=utf-8 -> "application/json" X-Token: key=abc123 -> "key" Set-Cookie: sessionId=abc; Path=/; HttpOnly -> "sessionId" Fix this by calling header.getValue() directly to obtain the complete header value, consistent with the approach already used in Http2ConsumerInvoker. Also remove the now-unused HeaderElement import. Add HttpConsumerInvokerTest covering: - simple header values (no delimiters) - composite values containing semicolons (core fix scenario) - values containing equals signs - multiple headers all stored correctly - header values stored as byte[] (tRPC protocol consistency) - non-200 status code throws TRpcException - zero Content-Length returns empty response body - complex cookie header with multiple semicolons and equals signs - non-zero Content-Length with response body decoded correctly * trpc-proto-http: fix comment
1 parent 2c3fdd0 commit 6ebdde6

2 files changed

Lines changed: 404 additions & 5 deletions

File tree

trpc-proto/trpc-proto-http/src/main/java/com/tencent/trpc/proto/http/client/HttpConsumerInvoker.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import java.util.Objects;
3333
import org.apache.commons.io.IOUtils;
3434
import org.apache.http.Header;
35-
import org.apache.http.HeaderElement;
3635
import org.apache.http.HttpHeaders;
3736
import org.apache.http.HttpRequest;
3837
import org.apache.http.HttpStatus;
@@ -93,10 +92,8 @@ private Response handleResponse(Request request, CloseableHttpResponse httpRespo
9392
Map<String, Object> respAttachments = new HashMap<>();
9493
for (Header header : httpResponse.getAllHeaders()) {
9594
String name = header.getName();
96-
for (HeaderElement element : header.getElements()) {
97-
String value = element.getName();
98-
respAttachments.put(name, value.getBytes(StandardCharsets.UTF_8));
99-
}
95+
String value = header.getValue();
96+
respAttachments.put(name, value.getBytes(StandardCharsets.UTF_8));
10097
}
10198

10299
Header contentLengthHdr = httpResponse.getFirstHeader(HttpHeaders.CONTENT_LENGTH);

0 commit comments

Comments
 (0)