This PR contains all the work related to setting up this project as required to implement the [Assignment](https://repo.rock-n-code.com/rock-n-code/deep-linking-assignment/wiki/Assignment) on top, as intended. To summarise this work: - [x] created a new **Xcode** project; - [x] cloned the `Wikipedia` app and inserted it into the **Xcode** project; - [x] created the `Locations` app and also, its `Libraries` package; - [x] created the `Shared` package to share dependencies between the apps; - [x] added a `Makefile` file and implemented some **environment** and **help** commands. Co-authored-by: Javier Cicchelli <javier@rock-n-code.com> Reviewed-on: rock-n-code/deep-linking-assignment#1
48 lines
1.3 KiB
Objective-C
48 lines
1.3 KiB
Objective-C
#import "NSURLRequest+LSHTTPRequest.h"
|
|
|
|
@implementation NSURLRequest (LSHTTPRequest)
|
|
|
|
- (NSURL*)url {
|
|
return self.URL;
|
|
}
|
|
|
|
- (NSString *)method {
|
|
return self.HTTPMethod;
|
|
}
|
|
|
|
- (NSDictionary *)headers {
|
|
return self.allHTTPHeaderFields;
|
|
}
|
|
|
|
- (NSData *)body {
|
|
if (self.HTTPBodyStream) {
|
|
NSInputStream *stream = self.HTTPBodyStream;
|
|
NSMutableData *data = [NSMutableData data];
|
|
[stream open];
|
|
size_t bufferSize = 4096;
|
|
uint8_t *buffer = malloc(bufferSize);
|
|
if (buffer == NULL) {
|
|
[NSException raise:@"NocillaMallocFailure" format:@"Could not allocate %zu bytes to read HTTPBodyStream", bufferSize];
|
|
}
|
|
while ([stream hasBytesAvailable]) {
|
|
NSInteger bytesRead = [stream read:buffer maxLength:bufferSize];
|
|
if (bytesRead > 0) {
|
|
NSData *readData = [NSData dataWithBytes:buffer length:bytesRead];
|
|
[data appendData:readData];
|
|
} else if (bytesRead < 0) {
|
|
[NSException raise:@"NocillaStreamReadError" format:@"An error occurred while reading HTTPBodyStream (%ld)", (long)bytesRead];
|
|
} else if (bytesRead == 0) {
|
|
break;
|
|
}
|
|
}
|
|
free(buffer);
|
|
[stream close];
|
|
|
|
return data;
|
|
}
|
|
|
|
return self.HTTPBody;
|
|
}
|
|
|
|
@end
|