Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we add http response headers directly into html pages

I need to add response headers like X-Frame, Cache-control, Pragma etc directly into the html code, may be, using attributes in html elements?

It is for help pages which are directly coming from a directory via href link.

Is there any way to add headers to these htmls?

like image 284
Pramod Avatar asked Mar 22 '16 16:03

Pramod


2 Answers

In short: no, you cannot. HTML files are the body of an HTTP response; the headers must come from the server. Anything you could embed in the HTML file would just become part of the body.

like image 91
Ross Presser Avatar answered Oct 14 '22 22:10

Ross Presser


You can use meta to replicate some of these. Normally not the ideal solution, but look into the http-equiv attribute of meta tags. I believe a lot of these have been deprecated in newer browsers.

Examples:

<meta http-equiv="Cache-control" content="no-cache"/>

<meta http-equiv="X-Frame-Options" content="sameorigin"/>

<meta http-equiv="pragma" content="no-cache"/>
like image 8
hopkins-matt Avatar answered Oct 14 '22 22:10

hopkins-matt