Gzip content when using HTTP::respond
I have a Virtual Server with a compression profile and an iRule that returns static text using HTTP::respond.
When using HTTP::respond the content is not compressed using gzip.
I have worked around this by placing an additional Virtual Server with a compression infront of the original Virtual Server with the iRule which then compresses the response.
Is there a way I can compress the content of a response using HTTP::respond?
Current iRule example:
when HTTP_REQUEST {
set CONTENT "Lots of text that compresses well."
HTTP::respond \
200 \
content $CONTENT \
Content-Type "text/text"
}
Is there a way to do something like the following (note: bogus "EXAMPLE" command placeholder):
when HTTP_REQUEST {
set CONTENT "Lots of text that compresses well."
switch -glob [string tolower [HTTP::header Accept-Encoding]] {
"*deflate*" -
"*gzip*" {
set COMPRESSEDCONTENT [EXAMPLE::gzip compress $CONTENT] ; ### Not a real command.
HTTP::respond \
200 \
content $COMPRESSEDCONTENT \
Content-Type "text/text" \
Content-Encoding gzip
}
default {
HTTP::respond \
200 \
content $CONTENT \
Content-Type "text/text" \
}
}
}
Thanks in advance!
Jo
I don't think what you're looking for is possible like the way you describe it.
Thinking out loud though, if your content is static you could serve it as a precompressed gzip file? Jason has an article about serving files via ifile here:
Oh, and if the content is brotli compatible and the client supports it you migth want to look into that as an alternative to gzip.
https://en.wikipedia.org/wiki/Brotli
Kind regards,
Patrik