neylitalo Posted March 16, 2007 Share Posted March 16, 2007 I've recently found myself in a situation where a frequently-modified XML document was being cached by the web browser, and the changes wouldn't take effect until the client's cache was cleared. The only solution to this, I think, is to send the "Cache-Control: no-cache" header with the XML document. However, I don't see anything in any W3C specifications, RFCs, or w3schools documents that indicate a way to send HTTP headers in an XML document. If someone has a link, can describe how it can be done, or can point me at a document saying that it can't be done, I would very much appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/ Share on other sites More sharing options...
Daniel0 Posted March 16, 2007 Share Posted March 16, 2007 You could make it go through PHP and use the header function. I haven't heard about a way to do it directly from the document either. Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/#findComment-208636 Share on other sites More sharing options...
neylitalo Posted March 16, 2007 Author Share Posted March 16, 2007 I considered that approach, but there was a problem: There are dozens of these XML files, and I certainly didn't want to go adding PHP code to all these XML files. There are also other applications, both on the server and client side, that reference and modify these XML files, and they wouldn't know how to handle the PHP code. The next step was to find a way to isolate these few files with Apache directives and only send the Cache-Control header with those files. httpd.conf was out of the question, since this code base is used by a handful of developers and one production machine, and it would be a hassle to make everybody update their httpd.conf files. Per-directory configs (also known as .htaccess files ) saved the day. These directives in .htaccess files in the appropriate directories solved the problem: <Files "filename.xml"> Header set Cache-Control no-cache </Files> Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/#findComment-208681 Share on other sites More sharing options...
ober Posted March 16, 2007 Share Posted March 16, 2007 Excellent solution Neal.. thanks for sharing Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/#findComment-208724 Share on other sites More sharing options...
neylitalo Posted March 16, 2007 Author Share Posted March 16, 2007 In my travels I've run across a little-known Apache feature, one that I thought might help me - the mod_asis module. With this module enabled, you can have Apache send files with a minimum set of headers, and specify the headers you want INSIDE the file - something I thought was pretty cool. To shamelessly steal the example provided by Apache: Here's an example of a file whose contents are sent as is so as to tell the client that a file has redirected. Status: 301 Now where did I leave that URL Location: http://xyz.abc.com/foo/bar.html Content-type: text/html <html> <head> <title>Lame excuses'R'us</title> </head> <body> <h1>Fred's exceptionally wonderful page has moved to <a href="http://xyz.abc.com/foo/bar.html">Joe's</a> site. </h1> </body> </html> See http://httpd.apache.org/docs/2.0/mod/mod_asis.html for more information. Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/#findComment-208958 Share on other sites More sharing options...
ShogunWarrior Posted March 16, 2007 Share Posted March 16, 2007 In reference to your initial question the reason XML doesn't have caching headers/tags defined is because it is an abstract description language, it was not designed specifically for the web. Also, XML is content-level, so things such as Authentication/Caching/etc. are left up to the server/client to figure out AFAIK. I think the Apache solution if the appropriate and best one. Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/#findComment-209000 Share on other sites More sharing options...
neylitalo Posted March 16, 2007 Author Share Posted March 16, 2007 I didn't think there was a way to send HTTP headers in the official XML specification, but I was hoping for a particular parameter to set that was universally accepted as a way to set HTTP headers. But as you said, the Apache solution looks to be pretty easily implemented and very elegant. Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/#findComment-209057 Share on other sites More sharing options...
steviewdr Posted March 17, 2007 Share Posted March 17, 2007 All I can say is - apache and htaccess ROCKS. All I can say to IIS and Windoze - hahaha. :-) -steve Quote Link to comment https://forums.phpfreaks.com/topic/42948-http-headers-in-xml-documents/#findComment-209575 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.