- (BOOL)shouldRewriteURLString:(NSString *)_s inContext:(WOContext *)_ctx {
// TODO: we need a binding to disable rewriting!
- NSRange r;
+ NSRange r;
r = [_s rangeOfString:@":"];
- if (!r.length) return YES;
- return [[_s substringToIndex:r.location] isEqualToString:@"http"];
+ if (r.length == 0)
+ return YES;
+
+ /* only rewrite HTTP URLs */
+ return [_s hasPrefix:@"http"];
}
- (BOOL)_appendHrefToResponse:(WOResponse *)_r inContext:(WOContext *)_ctx {
base = [_ctx baseURL];
hrefValue = [self->href valueInContext:_ctx];
- url = hrefValue;
+ url = nil;
if (hrefValue == nil)
return NO;
- if ([hrefValue isKindOfClass:NSURLClass]) {
+ if ((*(Class *)hrefValue == NSURLClass) ||
+ [hrefValue isKindOfClass:NSURLClass]) {
s = [hrefValue stringValueRelativeToURL:base];
}
else {
+ /* given HREF is a string */
s = [hrefValue stringValue];
+ /* we do not want to rewrite stuff like mailto: or javascript: URLs */
if ([self shouldRewriteURLString:s inContext:_ctx]) {
if ([s isAbsoluteURL]) {
// TODO: why are we doing this? we could just pass through the string?
if (url == nil) {
[self logWithFormat:
- @"couldn't construct URL from 'href' string '%@' (base=%@)",
+ @"could not construct URL from 'href' string '%@' (base=%@)",
s, base];
return NO;
}
[self logWithFormat:@" base %@", base];
[self logWithFormat:@" base-abs %@", [base absoluteString]];
[self logWithFormat:@" url %@", url];
- [self logWithFormat:@" url-abs %@", [url absoluteString]];
+ if (url != nil)
+ [self logWithFormat:@" url-abs %@", [url absoluteString]];
+ else
+ [self logWithFormat:@" href %@", hrefValue];
[self logWithFormat:@" string %@", s];
}
+
WOResponse_AddString(_r, s);
return YES;
}
inContext:_ctx
error:&error
acquire:doAcquire];
- if (error)
+ if (error != nil)
currentObject = error;
/* retain result */
doDispatch = YES;
object = [self lookupObjectForRequest:_rq inContext:_ctx];
- if (object) {
+ if (object != nil) {
[self->dispatcherRules
takeValue:[_ctx clientObject] forKey:@"clientObject"];
[self->dispatcherRules takeValue:object forKey:@"object"];
}
else {
r = [_ctx response];
- [r setStatus:404];
+ [r setStatus:404 /* not found */];
[r setHeader:@"text/html" forKey:@"content-type"];
[r appendContentString:@"object not found: "];
[r appendContentHTMLString: