cancel
Showing results for 
Search instead for 
Did you mean: 
Login & Join the DevCentral Connects Group to watch the Recorded LiveStream (May 12) on Basic iControl Security - show notes included.

Problem this snippet solves:

This iRule illustrates how to transform a single part HTTP response into a multi-part response, as suggested in AskF5 SOL9396: Downloading a linearized PDF file may fail when using the Firefox browser. Click here to view the solution.

Code :

when HTTP_REQUEST {
   if { [HTTP::header exists "Range"] and ([HTTP::header "Range"] contains ",") } { 
      set multirange_request 1   
   } else {
      set multirange_request 0
   }
}

when HTTP_RESPONSE {
   if { $multirange_request and [HTTP::status] == 206 /
    and !([HTTP::header "Content-Type"] starts_with "multipart/") } {
      if {([HTTP::header exists "Content-Length"]) && /
       ([HTTP::header "Content-Length"] <= 1000000)}{
         set content_length [HTTP::header "Content-Length"]
      } else {
         # may need to be larger if client requests really big chunks
         set content_length 1000000
      }
      if { [info exists content_length] && $content_length > 0} {
         HTTP::collect $content_length
      }
   }
}

when HTTP_RESPONSE_DATA {
   HTTP::payload replace 0 0 "{BR}--MPBOUNDARY{BR}Content-Type: [HTTP::header "Content-Type"]/
     {BR}Content-Range: [HTTP::header  "Content-Range"]\r\n\r\n"
   HTTP::payload replace [HTTP::payload length] 0 "{BR}--MPBOUNDARY--{BR}"
   HTTP::header replace "Content-Type" "multipart/byteranges; boundary=MPBOUNDARY"
   HTTP::header remove "Content-Range"
}
Version history
Last update:
‎18-Mar-2015 14:57
Updated by:
Contributors