#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Code to redirect to error doc in output filter module?


    I am writing an Apache output filter module that performs basic "text substitutions" on documents. My output filter is working fine, but I want to add a feature that allows my filter to conditionally redirect the request to one of the standard error documents.

    For example, in my output filter function, I want to write a line of code that redirects the request to whatever the standard error document is for the "403" (Forbidden) status.

    I have successfully used the apr_internal_redirect function to redirect the request to an alternate URI-- this works fine. But what "URI" would I use to redirect to a standard error document?

    I tried simply returning the status code HTTP_FORBIDDEN (403) from the output filter function, but that simply causes Apache to serve an "Internal Server Error" document (500).

    Thank you in advance for any help you can provide.
  2. #2
  3. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    So you want to know how to get the 403 ErrorDocument configured for the current context within your output filter so you can redirect to it?

    I don't have any experience with filters like this, but it doesn't seem like this is what a filter is designed to do. Maybe you could explain a little about your situation and why you're taking this approach?
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    Yes, that sounds like what I want to do. I realize that filters weren't "designed" specifically to do this. But when a fatal error occurs in an output filter, redirecting the request to an error document seems like a reasonable thing to do.

    What do you advocate that an output filter should do, when it encounters a fatal error and cannot process the bucket brigade stream? Should it simply pass the bucket brigade through unmodified? That doesn't seem like a good idea, since the user would have no idea there was a problem. Errors are certain to happen, even in output filters, and there must be some way to report to the user that the request can't be processed.

    If worst comes to worst, I'll just substitute the entirety of the bucket brigade stream with an error document of my own formation. I was hoping there was a simple way to redirect the request to a standard error document.
  6. #4
  7. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    I can't find it now, but I ran across some documentation indicating that you can use an external program written in pretty much any language as a filter. Are you doing this or something else?

    I would assume (remember, no experience here) Apache calls the filters and has some way of handling a thrown or return error code.

    Have you looked at the source of an existing Apache module that acts within the filter chain to see how it handle errors?

    Sorry I can't be of more help with this one.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0
    My filter is not an external application, but rather a dynamically-linked shared object. It is written in "C", and compiled and linked just like most other Apache "modules". It is listed in the httpd.conf file with a typical "LoadModule" directive.

    There is an integer "return value" that I return from the "C" function where the output filter is invoked from Apache. However, returning anything other than "APR_SUCCESS" from this function results in Apache serving the "Internal Server Error" (500) document. It is unfortunate that I can't just return (403) from my filter function and have Apache serve the "Forbidden" error document (I tried and it just doesn't work).

    I can look at the source of other filter modules and see what they do. I was hoping that this topic would be "common knowledge" since it seems like such a common requirement.

    Thanks for your help.
  10. #6
  11. mod_dev_shed
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2002
    Location
    Atlanta, GA
    Posts
    14,817
    Rep Power
    1099
    I haven't been around in a while, but this forum hasn't historically been good with answering questions related to custom modules The majority of what has gone on here in the past is configuration questions. I'm just not sure we have someone around here who has experience in this kind of thing.
    # Jeremy

    Explain your problem instead of asking how to do what you decided was the solution.

IMN logo majestic logo threadwatch logo seochat tools logo