On Tue, Apr 5, 2011 at 00:10, Jason Cwik <ja...@connecticinc.com> wrote: > I'm trying to write a module that will improve REST compatibility with Flex > & JS by implementing support for X-Http-Method-Override to change the > request method when only GET/POST are the only methods supported from the > client. > > I've read the modules book and looked through lots of other modules, but I > can't figure out the right way to do this. I've implemented a input filter, > but it always seems like the request has been read by the time my filter > runs and I only get body content (I've tried registering it at > AP_FTYPE_CONNECTION and even AP_FTYPE_CONNECTION+1, but never see the raw > request) > > Looking at hooks, it seems like the earliest I can hook in is > post_read_request; also too late.
Well... you can add your input filter at the end of the chain, buffer everything until you see the X-Http-Method-Override header and then pass on the buffered input with a modified request line. But that's a hack and probably a can of worms, I really wouldn't recommend it. > Another direction I went was to create a subrequest and execute that instead > of the current request. That worked fine, but ended up executing my current > request twice. Is this the right way to go? If so, > 1) how do I stream data to the subrequest (e.g. POST and PUT) > 2) how do I terminate the current processing chain so it stops after my > subrequest (and doesn't execute again)? I tried ap_internal_fast_redirect, > but that ended up crashing mod_php in the subrequest. Depends on what you want to do. To trick mod_php into thinking that a POST is really a PUT, add a fixup hook where you update r->method and r->method_number. The drawback is that you break <Limit> directives this way. Out of curiosity, why don't you handle this from within PHP itself? if (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) { $_SERVER['REQUEST_METHOD'] = $_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']; } That should be all it takes, right?