Open TharmiganK opened 5 months ago
Currently checking an error in HTTP/2 client when retrieving the response payload which is compressed using brotli format. Getting a poll time out when trying to get the http content. Reproducible with the following:
import ballerina/http;
import ballerina/log;
int http2AcceptEncodingHeaderTestPort = 9090;
listener http:Listener http2AcceptEncodingListenerEP = new (http2AcceptEncodingHeaderTestPort, server = "Mysql" );
service /hello on http2AcceptEncodingListenerEP {
resource function 'default .(http:Caller caller, http:Request req) returns error? {
http:Response res = new;
map<json> payload = {};
boolean hasHeader = req.hasHeader("Accept-Encoding");
if hasHeader {
log:printInfo("Accept-Encoding header is present.");
payload["acceptEncoding"] = check req.getHeader("Accept-Encoding");
} else {
log:printInfo("Accept-Encoding header is not present.");
payload["acceptEncoding"] = "Not present";
}
log:printInfo("Sending response.");
res.setJsonPayload(payload);
check caller->respond(res);
}
}
- client:
```bal
import ballerina/http;
import ballerina/log;
int http2AcceptEncodingHeaderTestPort = 9090;
final http:Client http2AcceptEncodingEnableEP = check new (
"http://localhost:" + http2AcceptEncodingHeaderTestPort.toString() + "/hello",
http2Settings = {
http2PriorKnowledge: true
},
compression = http:COMPRESSION_ALWAYS
);
public function main() returns error? {
http:Request req = new;
req.setTextPayload("accept encoding test");
log:printInfo("Sending request.");
json|error response = http2AcceptEncodingEnableEP->post("/", req);
log:printInfo("Response received.");
if response is json {
log:printInfo("response recieved", payload = response);
} else {
log:printError("error occured", response);
}
}
Description:
There is a requirement to add support for
brotli
format in the HTTP response compression/decompression. Currently the HTTP package only supportsdeflate
andgzip
. Please note that netty already supports this format, but we need to pack some native libraries to enable the compression/decompression.Describe your problem(s)
The current HTTP client does not support decompressing response payload which is compressed with
brotli
compression format. In addition to that, the HTTP server does not support thebrotli
compression for sending response payloads.This was checked using the following backend written in expressjs:
The endpoint:
localhost:3000/mock
returns an xml payload compressed inbrotli
format.Use the following ballerina service to check the behavior:
Accept-Encoding: gzip, deflate, br
header)Content-Encoding
headerContent-Encoding: br
headerContent-Encoding: br
headerContent-Encoding
headerbrotli
format with theContent-Encoding: br
headerDescribe your solution(s)
Add the compression and decompression support for the
brotli
format in the service and the client. This requires the addition of the followingbrotli4j
compression/decompression library which is used by netty: