Forum Discussion

jo's avatar
jo
Icon for Nimbostratus rankNimbostratus
Oct 06, 2023

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