Skip to content
Related Articles

Related Articles

HTTP headers | Content-Disposition

Improve Article
Save Article
  • Difficulty Level : Medium
  • Last Updated : 22 Jun, 2020
Improve Article
Save Article

The HTTP Content Disposition is a response-type header field that gives information on how to process the response payload and additional information such as filename when user saves it locally. This response header field holds a number of values and parameters in the larger context of MIME (Multipurpose Internet Mail Extensions). However, it reduces to a fixed set of parameters and values under HTTP forms and POST requests. 

The Content Disposition header field takes different values while working as a response header for data enclosed in the main body, forms, or multiple parts of the content. It has an option to make the data available locally or display it in the browser while treating content present in the main body present on the browser. It can give information about the specified field of data which are stored as sub-parts in Multipart/Form data. 

Syntax : 

  • Syntax for treating data in the main body : 
Content Disposition : inline 
Content Disposition : attachment
Content Disposition : attachment ; filename = "file_name.html"
  • Syntax for treating Multipart/Form Data : 
Content-Disposition : form-data
Content-Disposition : form-data; name="field_value"
Content-Disposition : form-data; name="field_value"; filename="file_name.html"

Directives : 

1. Content Disposition Type : 

  •   inline: This indicates that data should be displayed automatically on prompt in browser.
  • attachment: This indicates that user should receive a prompt (usually a Save As dialog box) to save the file locally on the disk to access it.
  • filename: It is an optional parameter that contains the original name of file sent to the recipient. The receiver has completely authority to change the name or the suggested directory to save file. This parameter can also be used in inline type of disposition. RFC 5987 provided a variant filename* with new encoding but performs similar function. This parameter is now preferred over conventional filename when both are used by a header.

2. Content Disposition Parameters : 

  • name: It contains the name or value of HTML field which is referred by subpart of the form.
  • form-data: This indicates that data is divided into various parts and each part is separated by a boundary.

3.Working of Content Disposition and Multipart : 

  • When Content-Disposition Header is used on multipart, it is applied to the complete set as whole and disposition type of sub-parts do not need to be consulted. However, while displaying the content under multipart, the disposition of each subpart should be respected.
  • On using inline disposition, the multipart should be displayed normally and if any attachment sub-part is present, it requires user action.
  • User action is required when attachment disposition is used as whole on multipart.

Examples :  The following examples have been taken from RFC 6266 and RFC 7578. 

content-disposition: form-data; name="field1"

 content-disposition: form-data; name="_charset_"

Content-Disposition: attachment;
filename="EURO rates";

 Content-Disposition: inline ; filename=example.html

Supported Browsers :  The browsers  supported by HTTP headers | Content-Disposition are listed  below

  • Google Chrome
  • Safari
  • Mozilla Firefox
  • Microsoft Edge
  • Internet Explorer
  • Opera
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!