Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 
Custom Alert Banner

Gzip content when using HTTP::respond

jo
Nimbostratus
Nimbostratus

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

1 ACCEPTED SOLUTION

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:

 https://community.f5.com/t5/technical-articles/v11-1-external-file-access-from-irules-via-ifiles/ta-...

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

View solution in original post

2 REPLIES 2

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:

 https://community.f5.com/t5/technical-articles/v11-1-external-file-access-from-irules-via-ifiles/ta-...

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

jo
Nimbostratus
Nimbostratus

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.