static int debugLookup = -1;
static int debugBaseURL = -1;
+static int useRelativeURLs = -1;
static void _initialize(void) {
if (debugLookup == -1) {
debugLookup = [[NSUserDefaults standardUserDefaults]
boolForKey:@"SoDebugBaseURL"] ? 1 : 0;
NSLog(@"Note(SoObject): SoDebugBaseURL is enabled!");
}
+ if (useRelativeURLs == -1) {
+ useRelativeURLs = [[NSUserDefaults standardUserDefaults]
+ boolForKey:@"WOUseRelativeURLs"] ?1:0;
+ NSLog(@"Note(SoObject): relative base URLs are enabled.");
+ }
}
/* classes */
baseURL = [baseURL stringByAppendingString:name];
if (debugBaseURL) {
- [self logWithFormat:@"baseURL: name=%@ (container=%@)\n container: %@\n own: %@",
- [self nameInContainer], NSStringFromClass([[self container] class]),
+ [self logWithFormat:
+ @"baseURL: name=%@ (container=%@)\n container: %@\n own: %@",
+ [self nameInContainer],
+ NSStringFromClass([[self container] class]),
[[self container] baseURL], baseURL];
}
}
// TODO: this is somewhat weird, why don't we use WOContext for URL gen.?
- rq = [_ctx request];
- port = [[rq headerForKey:@"x-webobjects-server-port"] intValue];
+ rq = [_ctx request];
+ ms = [[NSMutableString alloc] initWithCapacity:128];
+
+ if (!useRelativeURLs) {
+ port = [[rq headerForKey:@"x-webobjects-server-port"] intValue];
- /* this is actually a bug in Apache */
- if (port == 0) {
- static BOOL didWarn = NO;
- if (!didWarn) {
- [self warnWithFormat:@"(%s:%i): got an empty port from Apache!",
+ /* this is actually a bug in Apache */
+ if (port == 0) {
+ static BOOL didWarn = NO;
+ if (!didWarn) {
+ [self warnWithFormat:@"(%s:%i): got an empty port from Apache!",
__PRETTY_FUNCTION__, __LINE__];
- didWarn = YES;
+ didWarn = YES;
+ }
+ port = 80;
}
- port = 80;
- }
-
- ms = [[NSMutableString alloc] initWithCapacity:128];
- if ((tmp = [rq headerForKey:@"host"]) != nil) {
- /* check whether we have a host header with port */
- if ([tmp rangeOfString:@":"].length == 0)
- tmp = nil;
- }
- if (tmp != nil) { /* we have a host header with port */
- isHTTPS =
- [[rq headerForKey:@"x-webobjects-server-url"] hasPrefix:@"https"];
- [ms appendString:isHTTPS ? @"https://" : @"http://"];
- [ms appendString:tmp];
- }
- else if ((tmp = [rq headerForKey:@"x-webobjects-server-url"]) != nil) {
- /* sometimes the URL is just wrong! (suggests port 80) */
- if ([tmp hasSuffix:@":0"] && [tmp length] > 2) { // TODO: bad bad bad
- [self warnWithFormat:@"%s: got incorrect URL from Apache: '%@'",
- __PRETTY_FUNCTION__, tmp];
- tmp = [tmp substringToIndex:([tmp length] - 2)];
+ if ((tmp = [rq headerForKey:@"host"]) != nil) {
+ /* check whether we have a host header with port */
+ if ([tmp rangeOfString:@":"].length == 0)
+ tmp = nil;
+ }
+ if (tmp != nil) { /* we have a host header with port */
+ isHTTPS =
+ [[rq headerForKey:@"x-webobjects-server-url"] hasPrefix:@"https"];
+ [ms appendString:isHTTPS ? @"https://" : @"http://"];
+ [ms appendString:tmp];
}
- else if ([tmp hasSuffix:@":443"] && [tmp hasPrefix:@"http://"]) {
- /* see OGo bug #1435, Debian Apache hack */
- [self warnWithFormat:@"%s: got 'http' protocol but 443 port, "
+ else if ((tmp = [rq headerForKey:@"x-webobjects-server-url"]) != nil) {
+ /* sometimes the URL is just wrong! (suggests port 80) */
+ if ([tmp hasSuffix:@":0"] && [tmp length] > 2) { // TODO: bad bad bad
+ [self warnWithFormat:@"%s: got incorrect URL from Apache: '%@'",
+ __PRETTY_FUNCTION__, tmp];
+ tmp = [tmp substringToIndex:([tmp length] - 2)];
+ }
+ else if ([tmp hasSuffix:@":443"] && [tmp hasPrefix:@"http://"]) {
+ /* see OGo bug #1435, Debian Apache hack */
+ [self warnWithFormat:@"%s: got 'http' protocol but 443 port, "
@"assuming Debian/Apache bug (OGo #1435): '%@'",
__PRETTY_FUNCTION__, tmp];
- tmp = [tmp substringWithRange:NSMakeRange(4, [tmp length] - 4 - 4)];
- tmp = [@"https" stringByAppendingString:tmp];
+ tmp = [tmp substringWithRange:NSMakeRange(4, [tmp length] - 4 - 4)];
+ tmp = [@"https" stringByAppendingString:tmp];
+ }
+ [ms appendString:tmp];
}
- [ms appendString:tmp];
- }
- else {
- // TODO: isHTTPS always no in this case?
- [ms appendString:isHTTPS ? @"https://" : @"http://"];
+ else {
+ // TODO: isHTTPS always no in this case?
+ [ms appendString:isHTTPS ? @"https://" : @"http://"];
- [ms appendString:[rq headerForKey:@"x-webobjects-server-name"]];
- if ((isHTTPS ? (port != 443) : (port != 80)) && port != 0)
- [ms appendFormat:@":%i", port];
+ [ms appendString:[rq headerForKey:@"x-webobjects-server-name"]];
+ if ((isHTTPS ? (port != 443) : (port != 80)) && port != 0)
+ [ms appendFormat:@":%i", port];
+ }
}
if (withAppPart) {
return rootURL;
}
- rootURL = SoObjectRootURLInContext(_ctx, self, YES);
+ rootURL = SoObjectRootURLInContext
+ (_ctx, self /* logger */, YES /* withAppPart */);
/* remember in cache */
if (debugBaseURL) {