Retry-after HTTP response header – does it affect anything?

The current state of the Retry-After header The implementation of the Retry-After header in clients and servers has changed a bit in the recent years since the original posting of this question. So I thought I’d provide an updated answer. First off, RFC 2616, section 14.37 Retry-After states: The Retry-After response-header field can be used … Read more

Force file download with php using header()

I’m pretty sure you don’t add the mime type as a JPEG on file downloads: header(‘Content-Type: image/png’); These headers have never failed me: $quoted = sprintf(‘”%s”‘, addcslashes(basename($file), ‘”\\’)); $size = filesize($file); header(‘Content-Description: File Transfer’); header(‘Content-Type: application/octet-stream’); header(‘Content-Disposition: attachment; filename=” . $quoted); header(“Content-Transfer-Encoding: binary’); header(‘Connection: Keep-Alive’); header(‘Expires: 0’); header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0’); header(‘Pragma: public’); header(‘Content-Length: ‘ … Read more

How to get the file size from http headers

Yes, assuming the HTTP server you’re talking to supports/allows this: public long GetFileSize(string url) { long result = -1; System.Net.WebRequest req = System.Net.WebRequest.Create(url); req.Method = “HEAD”; using (System.Net.WebResponse resp = req.GetResponse()) { if (long.TryParse(resp.Headers.Get(“Content-Length”), out long ContentLength)) { result = ContentLength; } } return result; } If using the HEAD method is not allowed, or … Read more

HTTP Cache Control max-age, must-revalidate

a) If the server includes this header: Cache-Control “max-age=3600, must-revalidate” it is telling both client caches and proxy caches that once the content is stale (older than 3600 seconds) they must revalidate at the origin server before they can serve the content. This should be the default behavior of caching systems, but the must-revalidate directive … Read more

Return a PHP page as an image

The PHP Manual has this example: <?php // open the file in a binary mode $name=”./img/ok.png”; $fp = fopen($name, ‘rb’); // send the right headers header(“Content-Type: image/png”); header(“Content-Length: ” . filesize($name)); // dump the picture and stop the script fpassthru($fp); exit; ?> The important points is that you must send a Content-Type header. Also, you … Read more