-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable gzip encoding for capcitor http #6387
Changes from 44 commits
659012f
f2f59cc
2272fc3
b0be2ba
d12f6fc
dcd4fb8
52b3604
aa58b9f
8cd4fe6
4656256
827dc35
a668f5f
d281a3e
739df49
b723810
ea4687d
f81a628
f5dbb18
450e1de
32dd11b
599cc06
fb9e164
d9d1b89
a142f29
b851634
a0f39d9
55070ac
4ee77da
019fe0f
8109c63
aafa9bf
6620192
1a625fc
8968fdb
ec9507a
b5af74d
2596273
767f9a8
1e03ab6
3fe706a
1ace063
635b6ef
df16fa0
f8100b3
7d3bc27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import * as Pako from 'pako'; | ||
|
||
import type { Plugin } from './definitions'; | ||
import { registerPlugin } from './global'; | ||
import { WebPlugin } from './web-plugin'; | ||
|
@@ -208,6 +210,11 @@ export interface HttpOptions { | |
* special handling in the native layer | ||
*/ | ||
dataType?: 'file' | 'formData'; | ||
/** | ||
* Use this option if you need a gzip compression of the data payload | ||
* A compatible consumer interface must be ensured. The default is _false_. | ||
*/ | ||
gzipCompression?: boolean; | ||
} | ||
|
||
export interface HttpParams { | ||
|
@@ -318,7 +325,15 @@ export const buildRequestInit = ( | |
|
||
// If body is already a string, then pass it through as-is. | ||
if (typeof options.data === 'string') { | ||
output.body = options.data; | ||
if (options?.gzipCompression && options.headers) { | ||
options.headers['Content-Encoding'] = 'gzip'; | ||
output.headers = options.headers; | ||
|
||
const gzippedData: Uint8Array = Pako.gzip(options.data); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a fan of adding this dependency to core. Is there a reason you can't just gzip and gunzip on the client side from javascript on your side? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the thing is that we could do that, but why we switched to capacitor http is, that we need background functionality of the http services and therefore we started using capacitor-community/http which brought us here. The Pako compression could be done client side in the app code, but we moved it to the web part of the plugin to complete the gzip functionality for all platforms. I didn't find any good code example to do it without Pako, maybe this dependency can be kept? |
||
output.body = gzippedData.buffer; | ||
} else { | ||
output.body = options.data; | ||
} | ||
} | ||
// Build request initializers based off of content-type | ||
else if (type.includes('application/x-www-form-urlencoded')) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this should be an on/off setting that is applied for the entire lifecycle of the plugin.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we will probably move this to a param in the http function call, this makes sense not to have it globally