Permalink
Browse files

Re-adding fixes for local url to HttpRequest

  • Loading branch information...
1 parent a7a9268 commit a76220949d16f7768ec05ce55894d9c83f29ea93 @jamesnvc jamesnvc committed Nov 3, 2012
Showing with 16 additions and 4 deletions.
  1. +16 −4 Classes/Ejecta/EJUtils/EJBindingHttpRequest.m
@@ -91,7 +91,14 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
state = kEJHttpRequestStateHeadersReceived;
[response release];
- response = (NSHTTPURLResponse *)[responsep retain];
+ if ([responsep respondsToSelector:@selector(statusCode)]) {
+ response = (NSHTTPURLResponse*)[responsep retain];
+ } else {
+ response = [[NSHTTPURLResponse alloc] initWithURL:responsep.URL
+ statusCode:200
+ HTTPVersion:@"1.1"
+ headerFields:[NSDictionary dictionary]];
+ }
[self triggerEvent:@"progress" argc:0 argv:NULL];
[self triggerEvent:@"readystatechange" argc:0 argv:NULL];
}
@@ -177,8 +184,11 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if( !method || !url ) { return NULL; }
[self clearConnection];
-
- NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
+ NSURL *remoteUrl = [NSURL URLWithString:url];
+ if (![remoteUrl host]) { // No host => local file
+ remoteUrl = [NSURL fileURLWithPath:[[EJApp instance] pathForResource:url]];
+ }
+ NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:remoteUrl];
[request setHTTPMethod:method];
for( NSString * header in requestHeaders ) {
@@ -201,7 +211,9 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
if( async ) {
state = kEJHttpRequestStateLoading;
- connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
+ connection = [[NSURLConnection alloc] initWithRequest:request
+ delegate:self
+ startImmediately:YES];
}
else {
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];

0 comments on commit a762209

Please sign in to comment.