mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 12:15:37 +08:00
Added Gzip support
Summary: Added Gzip function to RCTUtils. This uses dlopen to load the zlib library at runtime so there's no need to link it into your project. The main reason for this feature is to support gzipping of HTTP request bodies. Now, if you add 'Content-Encoding:gzip' to your request headers when using XMLHttpRequest, your request body will be automatically gzipped on the native side before sending. (Note: Gzip decoding of *response* bodies is handled automatically by iOS, and was already available).
This commit is contained in:
@@ -249,8 +249,15 @@ RCT_EXPORT_MODULE()
|
||||
request.HTTPBody = result[@"body"];
|
||||
NSString *contentType = result[@"contentType"];
|
||||
if (contentType) {
|
||||
[request setValue:contentType forHTTPHeaderField:@"content-type"];
|
||||
[request setValue:contentType forHTTPHeaderField:@"Content-Type"];
|
||||
}
|
||||
|
||||
// Gzip the request body
|
||||
if ([request.allHTTPHeaderFields[@"Content-Encoding"] isEqualToString:@"gzip"]) {
|
||||
request.HTTPBody = RCTGzipData(request.HTTPBody, -1 /* default */);
|
||||
[request setValue:[@(request.HTTPBody.length) description] forHTTPHeaderField:@"Content-Length"];
|
||||
}
|
||||
|
||||
[self sendRequest:request
|
||||
incrementalUpdates:incrementalUpdates
|
||||
responseSender:responseSender];
|
||||
|
||||
Reference in New Issue
Block a user