static int HTTP_PERFLOG = -1;
+@interface WOCoreApplication(SimpleParserSelection)
+
+- (BOOL)shouldUseSimpleHTTPParserForTransaction:(id)_tx;
+
+@end
+
@implementation WOHttpTransaction
static NSMutableDictionary *pendingTransactions = nil; // THREAD
}
+ (void)initialize {
static BOOL didInit = NO;
- if (!didInit) {
- NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
- didInit = YES;
-
- useSimpleParser = [ud boolForKey:@"WOHttpTransactionUseSimpleParser"];
- debugOn = [[ud objectForKey:@"WODebugHttpTransaction"] boolValue] ? 1 : 0;
- doCore = [[ud objectForKey:@"WOCoreOnHTTPAdaptorException"] boolValue]?1:0;
-
- adLogPath = [[ud stringForKey:@"WOAdaptorLogPath"] copy];
- if (adLogPath == nil)
- adLogPath = @"";
- }
+ NSUserDefaults *ud = [NSUserDefaults standardUserDefaults];
+ if (didInit) return;
+ didInit = YES;
+
+ useSimpleParser = [ud boolForKey:@"WOHttpTransactionUseSimpleParser"];
+ debugOn = [[ud objectForKey:@"WODebugHttpTransaction"] boolValue] ? 1 : 0;
+ doCore = [[ud objectForKey:@"WOCoreOnHTTPAdaptorException"] boolValue]?1:0;
+
+ adLogPath = [[ud stringForKey:@"WOAdaptorLogPath"] copy];
+ if (adLogPath == nil) adLogPath = @"";
}
- (BOOL)optionLogStream {
}
- (void)dealloc {
- //[self debugWithFormat:@"dealloc ..."];
+#if 0
+ [self debugWithFormat:@"dealloc ..."];
+#endif
[self reset];
[self->socket release];
[self->lastException release];
[super dealloc];
}
+/* state management */
+
- (void)reset {
if (self->asyncResponseToken) {
[self logWithFormat:
self->t = [self->startDate timeIntervalSince1970];
}
- (void)finish {
- if (self->woResponse) {
- [self logResponse:self->woResponse
- toRequest:self->woRequest
- connection:self->socket];
+ if (self->woResponse == nil)
+ return;
+
+ [self logResponse:self->woResponse
+ toRequest:self->woRequest
+ connection:self->socket];
- if (HTTP_PERFLOG) {
+ if (HTTP_PERFLOG) {
struct timeval tv;
gettimeofday(&tv, NULL);
self->t = (((double)tv.tv_sec) * ((double)tv.tv_usec) / 1000.0) -
self->t;
- NSLog(@"processing of request took %4.3fs.", self->t < 0.0 ? -1.0 : t);
- }
+ NSLog(@"processing of request took %4.3fs.",
+ self->t < 0.0 ? -self->t : self->t);
}
}
}
return self->io != nil ? YES : NO;
}
+
static int logCounter = 0;
- (NSString *)currentRecordingPath:(NSString *)_suffix {
static NSString *s = nil;
NSString *p;
+
if (s == nil) {
s = [[self->application recordingPath] copy];
if (s == nil) s = @"";
if (self->woRequest)
[self logWithFormat:@"WARNING: woRequest already set ???"];
- if (useSimpleParser) {
+ if ([self->application shouldUseSimpleHTTPParserForTransaction:self]) {
WOSimpleHTTPParser *parser;
parser = [[WOSimpleHTTPParser alloc] initWithStream:self->io];
fflush(stdout);
}
-@end /* WOHttpTransaction */
-
-@implementation WOHttpTransaction(NGHttpMessageParserDelegate)
+/* NGHttpMessageParserDelegate */
- (BOOL)httpParserWillParseRequest:(NGHttpMessageParser *)_parser {
return YES;
- (void)parser:(NGMimePartParser *)_parser didParseHeader:(NGHashMap *)_header {
}
-@end /* WOHttpAdaptor(NGHttpMessageParserDelegate) */
+@end /* WOHttpAdaptor */
+
+@implementation WOCoreApplication(SimpleParserSelection)
+
+- (BOOL)shouldUseSimpleHTTPParserForTransaction:(id)_tx {
+ return useSimpleParser;
+}
+
+@end /* WOCoreApplication(SimpleParserSelection) */