![]() |
| Frontier Tutorials / Writing an ObjectNotFoundHandler / Mixing Modes |
So far, we have created a new script for each different type of operation we wanted to do. However, sometimes we want to try several different approaches before we give up. For example, when Mode 3 (stuffing the page table) fails, we want to fall back on a customized Page Not Found response using Mode 1 or Mode 2.
As it turns out, we can easily do that, as long as we keep ordering in mind. But we have to do two things:
Replace your #objectNotFoundHandler entry with the following script. Note that we're naming the actual script #objectNotFoundHandler, instead of just putting its address there. This script becomes the master controller for other ONFH scripts.
|
|---|
This script first calls the Mode 3 ReturnBinaryObject script, to give it a chance to handle the URL. Other Mode 2 and Mode 3 scripts could be called from the same location. If ReturnBinaryObject does handle the URL, the remainder of ObjectNotFoundHandler will be skipped (because ReturnBinaryObject finishes with a scriptError("!return") call).
ObjectNotFoundHandler makes another assumption about the ReturnBinaryObject script (and other Mode 2 & 3 scripts), though. It assumes that ReturnBinaryObject will return to the caller if it doesn't handle the URL. A few minor modifications to the ReturnBinaryObject script we created earlier will take care of this.
Finally, after giving the Mode 2 or 3 script (or multiple Mode 2 & 3 scripts) a chance to handle the URL, the master script functions as a Mode 1 ONFH, returning some default page content.
The ReturnBinaryObject script we wrote earlier is appropriate if it is the sole ONFH script. However, we need to modify it slightly to make it play nice with other ONFH scripts. The changes are:
After these changes, the script will simply return to the caller (the ObjectNotFoundHandler master script) if it is unable to handle a URL. If it does handle a URL, it will call scriptError("!return") to bypass further processing, as before.
The general structure of a Mode 3 ONFH script for use with the master ONFH script is:
|
|---|
Note that it simply returns without error if it doesn't handle the URL.
The general structure of a Mode 2 ONFH script for use with the master ONFH script is:
|
|---|
Note that it simply returns without error if it doesn't handle the URL.
Go to your browser again, and and load the page "http://localhost/onfhTutorial/download/binary1.zip" (the same one as before). You should see exactly the same behavior as before.
Now change the filename in the URL from "binary1.zip" to "binary2.zip". You should see the page-not-found page returned by your PageNotFound script.
|
|---|
Instead of the master script functioning as a Mode 1 ONFH handler, you could make it a Mode 2 handler by doing an unconditional redirect, as we did in the Mode 2 example.
|
|---|