Forum Discussion
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
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- joNimbostratus
Thanks for the reply, Patrik.
I assumed that I would be able to do it but I wanted to ask before going down a different path.
Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com