// $Id: WOResponse+Apache.m,v 1.1 2004/06/08 11:06:00 helge Exp $ #include "WOResponse+Apache.h" #include #include #include #include "common.h" @implementation WOResponse(Apache) - (BOOL)applyHeadersOnApacheRequest:(ApacheRequest *)_rq { static NSMutableSet *ignoredHeaders = nil; ApacheTable *apHeaders; NSString *ctype; NSEnumerator *keys; NSString *key; if (_rq == nil) return NO; if (ignoredHeaders == nil) { ignoredHeaders = [[NSMutableSet alloc] initWithObjects: @"content-type", nil]; } if ((ctype = [self headerForKey:@"content-type"])) [_rq setContentType:ctype]; /* apply all headers ... */ apHeaders = [_rq headersOut]; keys = [[self headerKeys] objectEnumerator]; while ((key = [keys nextObject])) { NSString *svalue; if ([ignoredHeaders containsObject:key]) continue; svalue = [[self headersForKey:key] componentsJoinedByString:@", "]; [apHeaders setObject:svalue forKey:key]; } return YES; } - (int)sendContentUsingApacheRequest:(ApacheRequest *)_rq { return [_rq rwriteData:[self content]]; } - (int)sendResponseUsingApacheRequest:(ApacheRequest *)_rq { NSAutoreleasePool *pool; int result; result = [self status]; pool = [[NSAutoreleasePool alloc] init]; [_rq setStatus:[self status]]; if (![self applyHeadersOnApacheRequest:_rq]) result = 500; else { #if DONT_SEND_CONTENT_IN_SUBREQUESTS if ([_rq mainRequest]) { [self logWithFormat:@"is subrequest (no content is send) ..."]; } else { #endif [_rq sendHttpHeader]; if (![_rq isHeadRequest]) result = [self sendContentUsingApacheRequest:_rq]; #if DONT_SEND_CONTENT_IN_SUBREQUESTS } #endif } RELEASE(pool); return ApacheHandledRequest; } @end /* WOResponse(Apache) */ @implementation WOResponse(ApacheAppend) - (void)appendApacheResponseInfo:(ApacheRequest *)_request { [self appendContentString:@""]; #if 0 [self appendContentString: @""]; #endif [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString: @""]; [self appendContentString:@"
Description:
"];
  [self appendContentHTMLString:[_request description]];
  [self appendContentString:@"
Status:"]; [self appendContentHTMLString:[NSString stringWithFormat:@"%i",[_request status]]]; [self appendContentString:@"
unparsed URI:"]; [self appendContentHTMLString:[_request unparsedURI]]; [self appendContentString:@"
URI:"]; [self appendContentHTMLString:[_request uri]]; [self appendContentString:@"
filename:"]; [self appendContentHTMLString:[_request filename]]; [self appendContentString:@"
filetype:"]; [self appendContentHTMLString:[_request fileType]]; [self appendContentString:@"
content-type:"]; [self appendContentHTMLString:[_request contentType]]; [self appendContentString:@"
queryargs:"]; [self appendContentHTMLString:[_request queryArgs]]; [self appendContentString:@"
pathinfo:"]; [self appendContentHTMLString:[_request pathInfo]]; [self appendContentString:@"
Headers:
"];
  [self appendContentHTMLString:
          [[[_request headersOut] asDictionary] description]];
  [self appendContentString:@"
"]; } @end /* WOResponse(ApacheAppend) */