-
Notifications
You must be signed in to change notification settings - Fork 308
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
Content-Encoding: gzip #255
Comments
Hello, It is technically possible to set and retrieve gzip-encoded JSON, but this does not mean that Webdis will compress a regular JSON output. So to be clear, it does not mean that you can have Webdis respond with a compressed version of its regular responses. There is an example in the Here's a demo showing a gzip'd file stored in Redis via Webdis, similar to the PNG example. Let's say we have a JSON file containing some record (really, it could be any kind of file):
It's 408 bytes raw, so let's gzip it and store it under the key
This command uses process substitution, so The original file was 408 bytes, but let's see how many bytes are now stored at that key:
So we are storing compressed data. Let's now need to fetch this binary data alone, meaning not wrapped in a First, let's see how many bytes that returns, and what this data looks like:
Let's now decode this gzip data to get back our original data file:
We can make sure the data is the same by hashing the original
We did get back our full original file, although we had to (1) send it compressed to Redis via Webdis, and (2) fetch it compressed from Redis via Webdis before decompressing it. So that's pretty much the only way to do it with Webdis alone at this time, given that it does not support compressing its responses. An alternative is to have a reverse proxy in front of it like (Click here for the full contents of `data.json` used in this test){
"id": 834719,
"username": "johndoe",
"email": "[email protected]",
"full_name": "John Doe",
"date_of_birth": "1992-07-15",
"created_at": "2023-09-10T14:23:45Z",
"last_login": "2024-03-12T09:15:33Z",
"settings": {
"theme": "dark",
"language": "en-US",
"two_factor_enabled": true
},
"roles": [
"user",
"moderator"
]
} I realize this might not be exactly what you were looking for, but I'm afraid this is the only option for Webdis at this time: sending Webdis the data already compressed, which it will store as provided into Redis, and retrieving it compressed. Best, |
Hey @nicolasff given that modern browsers all send the I came up with a proof of concept commit: aminroosta@5038b12 to also send the And it seems to work just fine.curl -v -s http://127.0.0.1:7379/GET/user:johndoe.json_gzip | gunzip -
* Trying 127.0.0.1:7379...
* Connected to 127.0.0.1 (127.0.0.1) port 7379
> GET /GET/user:johndoe.json_gzip HTTP/1.1
> Host: 127.0.0.1:7379
> User-Agent: curl/8.4.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Webdis
< Allow: GET,POST,PUT,OPTIONS
< Access-Control-Allow-Methods: GET,POST,PUT,OPTIONS
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: X-Requested-With, Content-Type, Authorization
< Content-Type: application/json
< ETag: "e905059b26cfdf0862495103f63287e5"
< Content-Encoding: gzip
< Connection: Keep-Alive
< Content-Length: 256
<
{ [256 bytes data]
* Connection #0 to host 127.0.0.1 left intact
{
"id": 834719,
"username": "johndoe",
"email": "[email protected]",
"full_name": "John Doe",
"date_of_birth": "1992-07-15",
"created_at": "2023-09-10T14:23:45Z",
"last_login": "2024-03-12T09:15:33Z",
"settings": {
"theme": "dark",
"language": "en-US",
"two_factor_enabled": true
},
"roles": [
"user",
"moderator"
]
} ![]() |
Is it possible to SET and GET gzip or brotli encoded JSON?
The text was updated successfully, but these errors were encountered: