Skip to content

Commit

Permalink
Migrate to ARC
Browse files Browse the repository at this point in the history
  • Loading branch information
mattstevens committed Jun 30, 2012
1 parent 0d6cab6 commit 8c412cd
Show file tree
Hide file tree
Showing 17 changed files with 46 additions and 90 deletions.
6 changes: 5 additions & 1 deletion Example/RoutingHTTPServer.xcodeproj/project.pbxproj
Expand Up @@ -328,7 +328,7 @@
C99CEC7C147959C200F648A5 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 0420;
LastUpgradeCheck = 0430;
};
buildConfigurationList = C99CEC7F147959C200F648A5 /* Build configuration list for PBXProject "RoutingHTTPServer" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -518,6 +518,7 @@
C99CECB8147959C300F648A5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RoutingHTTPServer/RoutingHTTPServer-Prefix.pch";
INFOPLIST_FILE = "RoutingHTTPServer/RoutingHTTPServer-Info.plist";
Expand All @@ -529,6 +530,7 @@
C99CECB9147959C300F648A5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ENABLE_OBJC_ARC = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RoutingHTTPServer/RoutingHTTPServer-Prefix.pch";
INFOPLIST_FILE = "RoutingHTTPServer/RoutingHTTPServer-Info.plist";
Expand All @@ -541,6 +543,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/RoutingHTTPServer.app/Contents/MacOS/RoutingHTTPServer";
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RoutingHTTPServer/RoutingHTTPServer-Prefix.pch";
Expand All @@ -555,6 +558,7 @@
isa = XCBuildConfiguration;
buildSettings = {
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/RoutingHTTPServer.app/Contents/MacOS/RoutingHTTPServer";
CLANG_ENABLE_OBJC_ARC = YES;
FRAMEWORK_SEARCH_PATHS = "$(DEVELOPER_LIBRARY_DIR)/Frameworks";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "RoutingHTTPServer/RoutingHTTPServer-Prefix.pch";
Expand Down
4 changes: 2 additions & 2 deletions Example/RoutingHTTPServer/AppDelegate.h
Expand Up @@ -3,8 +3,8 @@

@interface AppDelegate : NSObject <NSApplicationDelegate>

@property (assign) IBOutlet NSWindow *window;
@property (retain) RoutingHTTPServer *http;
@property (strong) IBOutlet NSWindow *window;
@property (strong) RoutingHTTPServer *http;

- (void)setupRoutes;

Expand Down
2 changes: 1 addition & 1 deletion Example/RoutingHTTPServer/AppDelegate.m
Expand Up @@ -13,7 +13,7 @@ @implementation AppDelegate
@synthesize http;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
self.http = [[[RoutingHTTPServer alloc] init] autorelease];
self.http = [[RoutingHTTPServer alloc] init];

// Set a default Server header in the form of YourApp/1.0
NSDictionary *bundleInfo = [[NSBundle mainBundle] infoDictionary];
Expand Down
13 changes: 6 additions & 7 deletions Example/RoutingHTTPServerTests/RoutingHTTPServerTests.m
Expand Up @@ -22,14 +22,13 @@ - (void)setUp {
}

- (void)tearDown {
[http release];
[super tearDown];
}

- (void)testRoutes {
RouteResponse *response;
NSDictionary *params = [NSDictionary dictionary];
HTTPMessage *request = [[[HTTPMessage alloc] initEmptyRequest] autorelease];
HTTPMessage *request = [[HTTPMessage alloc] initEmptyRequest];

response = [http routeMethod:@"GET" withPath:@"/null" parameters:params request:request connection:nil];
STAssertNil(response, @"Received response for path that does not exist");
Expand Down Expand Up @@ -105,7 +104,7 @@ - (void)setupRoutes {

[http post:@"/xml" withBlock:^(RouteRequest *request, RouteResponse *response) {
NSData *bodyData = [request body];
NSString *xml = [[[NSString alloc] initWithBytes:[bodyData bytes] length:[bodyData length] encoding:NSUTF8StringEncoding] autorelease];
NSString *xml = [[NSString alloc] initWithBytes:[bodyData bytes] length:[bodyData length] encoding:NSUTF8StringEncoding];

// Green?
NSRange tagRange = [xml rangeOfString:@"<greenLevel>"];
Expand All @@ -127,21 +126,21 @@ - (void)handleSelectorRequest:(RouteRequest *)request withResponse:(RouteRespons
- (void)verifyRouteWithMethod:(NSString *)method path:(NSString *)path {
RouteResponse *response;
NSDictionary *params = [NSDictionary dictionary];
HTTPMessage *request = [[[HTTPMessage alloc] initEmptyRequest] autorelease];
HTTPMessage *request = [[HTTPMessage alloc] initEmptyRequest];

response = [http routeMethod:method withPath:path parameters:params request:request connection:nil];
STAssertNotNil(response.proxiedResponse, @"Proxied response is nil for %@ %@", method, path);

NSUInteger length = [response.proxiedResponse contentLength];
NSData *data = [response.proxiedResponse readDataOfLength:length];
NSString *responseString = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
NSString *responseString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
STAssertEqualObjects(responseString, path, @"Unexpected response for %@ %@", method, path);
}

- (void)verifyRouteNotFoundWithMethod:(NSString *)method path:(NSString *)path {
RouteResponse *response;
NSDictionary *params = [NSDictionary dictionary];
HTTPMessage *request = [[[HTTPMessage alloc] initEmptyRequest] autorelease];
HTTPMessage *request = [[HTTPMessage alloc] initEmptyRequest];

response = [http routeMethod:method withPath:path parameters:params request:request connection:nil];
STAssertNil(response, @"Response should have been nil for %@ %@", method, path);
Expand Down Expand Up @@ -172,7 +171,7 @@ - (void)verifyMethod:(NSString *)method path:(NSString *)path contentType:(NSStr
httpResponse = (NSHTTPURLResponse *)response;
STAssertEquals([httpResponse statusCode], 200L, @"Unexpected status code for %@ %@", method, path);

NSString *responseString = [[[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding] autorelease];
NSString *responseString = [[NSString alloc] initWithBytes:[responseData bytes] length:[responseData length] encoding:NSUTF8StringEncoding];
STAssertEqualObjects(responseString, expectedResponseString, @"Unexpected response for %@ %@", method, path);
}

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.txt
@@ -1,4 +1,4 @@
Copyright (c) 2011 Matt Stevens
Copyright (c) 2011-2012 Matt Stevens

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Source/HTTPResponseProxy.h
Expand Up @@ -8,7 +8,7 @@
NSInteger status;
}

@property (nonatomic, retain) NSObject<HTTPResponse> *response;
@property (nonatomic) NSObject<HTTPResponse> *response;
@property (nonatomic) NSInteger status;

- (NSInteger)customStatus;
Expand Down
6 changes: 0 additions & 6 deletions Source/HTTPResponseProxy.m
@@ -1,15 +1,9 @@
#import "HTTPResponseProxy.h"


@implementation HTTPResponseProxy

@synthesize response;

- (void)dealloc {
self.response = nil;
[super dealloc];
}

- (NSInteger)status {
if (status != 0) {
return status;
Expand Down
9 changes: 4 additions & 5 deletions Source/Route.h
@@ -1,19 +1,18 @@
#import <Foundation/Foundation.h>
#import "RoutingHTTPServer.h"


@interface Route : NSObject {
NSRegularExpression *regex;
RequestHandler handler;
id target;
__weak id target;
SEL selector;
NSArray *keys;
}

@property (nonatomic, retain) NSRegularExpression *regex;
@property (nonatomic) NSRegularExpression *regex;
@property (nonatomic, copy) RequestHandler handler;
@property (nonatomic, assign) id target;
@property (nonatomic, weak) id target;
@property (nonatomic, assign) SEL selector;
@property (nonatomic, retain) NSArray *keys;
@property (nonatomic) NSArray *keys;

@end
8 changes: 0 additions & 8 deletions Source/Route.m
@@ -1,6 +1,5 @@
#import "Route.h"


@implementation Route

@synthesize regex;
Expand All @@ -9,11 +8,4 @@ @implementation Route
@synthesize selector;
@synthesize keys;

- (void)dealloc {
self.regex = nil;
self.keys = nil;
self.handler = nil;
[super dealloc];
}

@end
1 change: 0 additions & 1 deletion Source/RouteRequest.h
@@ -1,7 +1,6 @@
#import <Foundation/Foundation.h>
@class HTTPMessage;


@interface RouteRequest : NSObject {
NSDictionary *params;
HTTPMessage *message;
Expand Down
13 changes: 3 additions & 10 deletions Source/RouteRequest.m
@@ -1,25 +1,18 @@
#import "RouteRequest.h"
#import "HTTPMessage.h"


@implementation RouteRequest

@synthesize params;

- (id)initWithHTTPMessage:(HTTPMessage *)msg parameters:(NSDictionary *)parameters {
if (self = [super init]) {
params = [parameters retain];
message = [msg retain];
params = parameters;
message = msg;
}
return self;
}

- (void)dealloc {
[params release];
[message release];
[super dealloc];
}

- (NSDictionary *)headers {
return [message allHeaderFields];
}
Expand All @@ -46,7 +39,7 @@ - (NSData *)body {

- (NSString *)description {
NSData *data = [message messageData];
return [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
}

@end
7 changes: 3 additions & 4 deletions Source/RouteResponse.h
Expand Up @@ -3,16 +3,15 @@
@class HTTPConnection;
@class HTTPResponseProxy;


@interface RouteResponse : NSObject {
HTTPConnection *connection;
__weak HTTPConnection *connection;
NSMutableDictionary *headers;
HTTPResponseProxy *proxy;
}

@property (nonatomic, readonly) HTTPConnection *connection;
@property (nonatomic, weak, readonly) HTTPConnection *connection;
@property (nonatomic, readonly) NSDictionary *headers;
@property (nonatomic, retain) NSObject<HTTPResponse> *response;
@property (nonatomic, strong) NSObject<HTTPResponse> *response;
@property (nonatomic, readonly) NSObject<HTTPResponse> *proxiedResponse;
@property (nonatomic) NSInteger statusCode;

Expand Down
13 changes: 3 additions & 10 deletions Source/RouteResponse.m
Expand Up @@ -5,7 +5,6 @@
#import "HTTPAsyncFileResponse.h"
#import "HTTPResponseProxy.h"


@implementation RouteResponse

@synthesize connection;
Expand All @@ -20,12 +19,6 @@ - (id)initWithConnection:(HTTPConnection *)theConnection {
return self;
}

- (void)dealloc {
[proxy release];
[headers release];
[super dealloc];
}

- (NSObject <HTTPResponse>*)response {
return proxy.response;
}
Expand Down Expand Up @@ -63,7 +56,7 @@ - (void)respondWithString:(NSString *)string encoding:(NSStringEncoding)encoding
}

- (void)respondWithData:(NSData *)data {
self.response = [[[HTTPDataResponse alloc] initWithData:data] autorelease];
self.response = [[HTTPDataResponse alloc] initWithData:data];
}

- (void)respondWithFile:(NSString *)path {
Expand All @@ -72,9 +65,9 @@ - (void)respondWithFile:(NSString *)path {

- (void)respondWithFile:(NSString *)path async:(BOOL)async {
if (async) {
self.response = [[[HTTPAsyncFileResponse alloc] initWithFilePath:path forConnection:connection] autorelease];
self.response = [[HTTPAsyncFileResponse alloc] initWithFilePath:path forConnection:connection];
} else {
self.response = [[[HTTPFileResponse alloc] initWithFilePath:path forConnection:connection] autorelease];
self.response = [[HTTPFileResponse alloc] initWithFilePath:path forConnection:connection];
}
}

Expand Down
2 changes: 1 addition & 1 deletion Source/RoutingConnection.h
Expand Up @@ -3,7 +3,7 @@
@class RoutingHTTPServer;

@interface RoutingConnection : HTTPConnection {
RoutingHTTPServer *http;
__weak RoutingHTTPServer *http;
NSDictionary *headers;
}

Expand Down
11 changes: 2 additions & 9 deletions Source/RoutingConnection.m
Expand Up @@ -3,7 +3,6 @@
#import "HTTPMessage.h"
#import "HTTPResponseProxy.h"


@implementation RoutingConnection

- (id)initWithAsyncSocket:(GCDAsyncSocket *)newSocket configuration:(HTTPConfig *)aConfig {
Expand All @@ -16,11 +15,6 @@ - (id)initWithAsyncSocket:(GCDAsyncSocket *)newSocket configuration:(HTTPConfig
return self;
}

- (void)dealloc {
[headers release];
[super dealloc];
}

- (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path {

if ([http supportsMethod:method])
Expand Down Expand Up @@ -49,7 +43,6 @@ - (void)processBodyData:(NSData *)postDataChunk {
NSURL *url = [request url];
NSString *query = nil;
NSDictionary *params = [NSDictionary dictionary];
[headers release];
headers = nil;

if (url) {
Expand All @@ -62,7 +55,7 @@ - (void)processBodyData:(NSData *)postDataChunk {

RouteResponse *response = [http routeMethod:method withPath:path parameters:params request:request connection:self];
if (response != nil) {
headers = [response.headers retain];
headers = response.headers;
return response.proxiedResponse;
}

Expand All @@ -71,7 +64,7 @@ - (void)processBodyData:(NSData *)postDataChunk {
if (staticResponse && [staticResponse respondsToSelector:@selector(filePath)]) {
NSString *mimeType = [http mimeTypeForPath:[staticResponse performSelector:@selector(filePath)]];
if (mimeType) {
headers = [[NSDictionary dictionaryWithObject:mimeType forKey:@"Content-Type"] retain];
headers = [NSDictionary dictionaryWithObject:mimeType forKey:@"Content-Type"];
}
}
return staticResponse;
Expand Down
1 change: 0 additions & 1 deletion Source/RoutingHTTPServer.h
Expand Up @@ -3,7 +3,6 @@
#import "RouteRequest.h"
#import "RouteResponse.h"


@interface RoutingHTTPServer : HTTPServer {
NSMutableDictionary *routes;
NSMutableDictionary *defaultHeaders;
Expand Down

0 comments on commit 8c412cd

Please sign in to comment.