- (id)dispatchInContext:(WOContext *)_ctx {
NSAutoreleasePool *pool;
WORequest *rq;
+ NSString *httpMethod;
id clientObject;
id methodObject;
id resultObject;
}
// TODO: should check XML-RPC !!!
- // (hm, why ? XML-RPC is handled by other dispatcher ?)
+ // (hm, why? XML-RPC is handled by other dispatcher?)
+
+ /*
+ This X- field is used by Google which uses POST to trigger REST methods,
+ don't ask me why ... ;-/
+ */
+ if (![(httpMethod = [rq headerForKey:@"x-http-method-override"]) isNotEmpty])
+ httpMethod = [rq method];
/* find callable (method) object */
[self debugWithFormat:@"traversed object is callable: %@", self->object];
methodObject = self->object;
}
- else if ([[self->object soClass] hasKey:[rq method] inContext:_ctx]) {
+ else if ([[self->object soClass] hasKey:httpMethod inContext:_ctx]) {
// TODO: I'm not sure whether this step is correct
/* the class has a GET/PUT/xxx method */
methodObject = [self->object lookupName:[rq method]
NSString *defaultName;
defaultName = [self->object defaultMethodNameInContext:_ctx];
- if ([defaultName isNotNull]) {
- if ([defaultName length] > 0) {
- WOResponse *r;
- NSString *url;
+ if ([defaultName isNotEmpty]) {
+ WOResponse *r;
+ NSString *url;
- url = [self->object baseURLInContext:_ctx];
- if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
- url = [url stringByAppendingString:defaultName];
+ url = [self->object baseURLInContext:_ctx];
+ if (![url hasSuffix:@"/"]) url = [url stringByAppendingString:@"/"];
+ url = [url stringByAppendingString:defaultName];
- [self debugWithFormat:@"redirect to default method %@ of %@: %@",
- defaultName, self->object, url];
+ [self debugWithFormat:@"redirect to default method %@ of %@: %@",
+ defaultName, self->object, url];
- r = [[_ctx response] retain];
- [r setStatus:302 /* moved */];
- [r setHeader:url forKey:@"location"];
- [pool release];
- return [r autorelease];
- }
+ r = [[_ctx response] retain];
+ [r setStatus:302 /* moved */];
+ [r setHeader:url forKey:@"location"];
+ [pool release];
+ return [r autorelease];
}
}
else {