Is header(‘Content-Type:text/plain’); necessary at all?

Define “necessary”. It is necessary if you want the browser to know what the type of the file is. PHP automatically sets the Content-Type header to text/html if you don’t override it so your browser is treating it as an HTML file that doesn’t contain any HTML. If your output contained any HTML you’d see … Read more

Ideal HTTP cache control headers for different types of resources

I would probably use these settings: Cache-Control: max-age=31556926 – Representations may be cached by any cache. The cached representation is to be considered fresh for 1 year: To mark a response as “never expires,” an origin server sends an Expires date approximately one year from the time the response is sent. HTTP/1.1 servers SHOULD NOT … Read more

‘Refresh’ HTTP header

As far as I know, Refresh (along with Set-Cookie and possibly some other proprietary pseudo-headers) were created by Netscape in the very early days of the internet and have been basically (but not quite) standard since then. Because just about every browser supports it, Refresh is pretty safe to use — and commonly is. I … Read more

How do you add a custom HTTP response header in Rails?

Use: response.headers[‘HEADER NAME’] = ‘HEADER VALUE’ either in a specific method or to a before_filter method of your application controller depending on whether you need this to be added in a specific or to all of your responses. UPDATE for Rails 5 – February 24th, 2018 As noted by @BrentMatzelle in the comments, for Rails … Read more

Can I change the headers of the HTTP request sent by the browser?

I would partially disagree with Milan’s suggestion of embedding the requested representation in the URI. If anyhow possible, URIs should only be used for addressing resources and not for tunneling HTTP methods/verbs. Eventually, specific business action (edit, lock, etc.) could be embedded in the URI if create (POST) or update (PUT) alone do not serve … Read more