[ReturnRaw]MIME Headers and Body content[/ReturnRaw]
- Sends 'raw' MIME headers and data back to browser.
To get more control over the exact MIME header information sent to the browser, place a [ReturnRaw] context into a template. You can create 'true' URL-redirect pages this way, or use it to force the remote browser to display password dialogs. Probably the most common use for this feature is to create "click-through" statistics on pages where you place advertisements with hyperlinks leading away from your site. ReturnRaw allows you to insert some WebDNA (to increment a hit counter, for instance) before leading the customer away from your site.
Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):
- [ReturnRaw]HTTP/1.0 200 OK
...your HTML here...
- Note: the above example must have <Carriage Return><LineFeed> at the end of each line in order to work. On a PC, simply using NotePad to create the file will put CR/LF in the proper places. On a Macintosh you may use BBEdit or another text editor to set the file type to DOS-style line endings.
For illustration purposes, the example above shows the MIME headers automatically created for you whenever you display any normal page from WebDNA. Of course, since these headers are always created automatically, this example does nothing special -- the real usefulness of this feature comes when you change the MIME headers to do something special, like a URL-redirect.
The following example causes the remote browser to immediately redirect to a different URL. This is better that the META tag some newer browsers support, because almost all browsers understand the low-level MIME header URL redirect.
- [ReturnRaw]HTTP/1.0 302 Found
(some WebDNA here that does something interesting)
Note: when you put a [ReturnRaw] context into a template, any text outside the [ReturnRaw] container is ignored. So if you want to display some HTML after the raw MIME headers, you must put that HTML inside the context.
"New for WebDNA 5.1" - 'BinaryBody' option:
- [ReturnRaw binarybody=...]
Allows the WebDNA programmer to designate a file (binary or text) to be
attached as the 'body' of an HTTP response. This makes it possible to send a binary file (image, executable, etc...) back to the client.
For example, you can create download links for any type of file, and that would force the 'save as'
dialog to open on the client machine.
Example code: Creates a download link for every file in the current folder, binary or text.
[!]Initailize the getfile variable[/!]
[!]Check if filename was passed in[/!]
[!]Generate the response[/!]
[ReturnRaw binarybody=[getfile]]HTTP/1.0 200 OK[unurl][line_ending][/unurl][!]
[/!]Content-Disposition: attachment; filename="[getfile]"[unurl][line_ending][line_ending][/unurl][!]
[!] Generate a list of download links for all files in local directory [/!]
Click on a filename to download.