Request decompression

I’m trying to replace my current web server, openresty, which handles request decompression via a lua script. Is it possible for Caddy to handle a compressed request? (not compressed responses, I know that’s possible)

For example:

echo '{
  "jsonrpc":"2.0",
  "method":"eth_chainId",
  "params":[],
  "id":1
}' | gzip | curl -i \
  --url http://localhost:8080 \
  --header 'Content-Type: application/json' \
  --header 'Content-Encoding: gzip' \
  --compressed \
  --data-binary @-

What I need Caddy to do is to identify this is a compressed message (--compressed) that’s gzip encoded (--header 'Content-Encoding: gzip' ) and decompress that request before passing it on to the upstream server.

Is this possible?

I don’t know the answer to your question, but curl’s --compressed is to request a compressed response, and not related to the request.

Correct, I was mistaken.

I think the following it’s what you are looking for.

encode zstd gzip

That’s response encoding, not request decompression/deflating.

Encodes responses using the configured encoding(s). A typical use for encoding is compression.

I don’t think that’s supported right now (unless Go stdlib handles it already transparently), but it shouldn’t be too hard to implement with a plugin if you need it.

1 Like

I setup a test caddy instnace to see if it would work (fingers crossed) out of the box…unfortunately it didn’t. It just passes the request along as-is with out decompressing it. So better than erroring out or something but not what I would like.

I thought about a plugin, just don’t know where to start (and I don’t know go so I’ll need to figure that out too. I’m pretty good with a few other languages, just never used go). My thought, too, was that it would be pretty easy in a plugin…hopefully I’m not wrong :smiley:

We have a guide here:

You can look through caddy/modules/caddyhttp/encode at master · caddyserver/caddy · GitHub which is the encode directive, the library we use for that github.com/klauspost/compress should be a good fit for you as well.

You’d probably also need to manipulate the request headers to drop Content-Encoding before passing it on to the next handler.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.