Forum Discussion

Marc_13733's avatar
Marc_13733
Icon for Nimbostratus rankNimbostratus
Feb 16, 2010

Change Content Disposition from Inline to Attachment

Our DMS server returns only inline disposition headers:

Content-Disposition: inline; filename=somefile.pdf

We need to replace this header with the following:

Content-Disposition: attachment; filename=somefile.pdf

Basically we need something like this:

 
 set newheader [HTTP::header Content-Disposition] 
 set newheader strreplace($newheader, "inline", "attachment") 
 HTTP::header replace Content-Disposition $newheader 
 

Something like this??:

 
 set newheader string map {inline attachment} [HTTP::header Content-Disposition] 
 

5 Replies

  • Hi Marc,

    Can you try this?

     
     when HTTP_RESPONSE { 
      
         Check if there is a Content-Disposition header with inline in the value 
        if {[string tolower [HTTP::header Content-Disposition]] contains "inline"}{ 
      
            Replace the Content-Disposition header with inline replaced with attachment 
           HTTP::header replace Content-Disposition [string map -nocase "inline attachment" [HTTP::header Content-Disposition]] 
        } 
     } 
     

    Aaron
  • Thanks Aaron, works perfectly!

    One more thing - we want this modification to only occur when the querystring contains the word "attachment". When we do this:

     
     when HTTP_RESPONSE { 
     set querystring URI::query 
     if { $querystring contains "attachment=1" } { 
      HTTP::header replace Content-Disposition [string map -nocase "inline attachment" [HTTP::header Content-Disposition]]  
     } 
     } 
     

    We get an error "command is not valid in current event context". Apparently we can't query the querystring in a HTTP_RESPONSE block. How else can we do this header modification based on the URI?
  • Gottit!

     
     when HTTP_REQUEST {  
      set querystring URI::query  
     } 
      
     when HTTP_RESPONSE {  
      if { $querystring contains "attachment=1" } {  
       HTTP::header replace Content-Disposition [string map -nocase "inline attachment" [HTTP::header Content-Disposition]]   
      }  
      
     } 
     
  • Great that you figured it out. You could also try something like this:

      
      when HTTP_REQUEST {  
        
          Check if the query string contains a parameter named attachment with a value of 1  
         if {[URI::query [HTTP::uri] "attachment"] == 1}{  
            set check_response 1  
         } else {  
            set check_response 0  
         }       
      }  
        
      when HTTP_RESPONSE {  
         if { $check_response } {  
            HTTP::header replace Content-Disposition [string map -nocase "inline attachment" [HTTP::header Content-Disposition]]  
         }  
      }  
      

    Aaron

    edited to add HTTP::query to URI::query command...