appium-mac2-driver 4.1.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/WebDriverAgentMac/IntegrationTests/AMFindElementTests.m +165 -2
- package/WebDriverAgentMac/IntegrationTests/AMIntegrationTestCase.h +11 -0
- package/WebDriverAgentMac/IntegrationTests/AMIntegrationTestCase.m +33 -0
- package/WebDriverAgentMac/IntegrationTests/AMW3CActionsTests.m +7 -9
- package/WebDriverAgentMac/WebDriverAgent/Base.lproj/Main.storyboard +16 -1
- package/WebDriverAgentMac/WebDriverAgent/WebViewController.h +21 -0
- package/WebDriverAgentMac/WebDriverAgent/WebViewController.m +49 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Categories/NSPredicate+FBFormat.m +80 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Categories/XCUIElement+AMAttributes.h +29 -1
- package/WebDriverAgentMac/WebDriverAgentLib/Categories/XCUIElement+AMAttributes.m +66 -15
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/AMHTTPServer.h +84 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/AMHTTPServer.m +493 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/AMTCPSocket.h +109 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/AMTCPSocket.m +235 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/FBWebServer.h +1 -1
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/FBWebServer.m +9 -21
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/RouteRequest.h +36 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/RouteRequest.m +33 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/RouteResponse.h +37 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Routing/RouteResponse.m +62 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMSnapshotUtils.h +22 -0
- package/WebDriverAgentMac/WebDriverAgentLib/Utilities/AMSnapshotUtils.m +5 -11
- package/WebDriverAgentMac/WebDriverAgentLib/Utilities/FBElementUtils.m +7 -1
- package/WebDriverAgentMac/WebDriverAgentMac.xcodeproj/project.pbxproj +46 -180
- package/npm-shrinkwrap.json +75 -146
- package/package.json +2 -1
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncSocket.h +0 -1226
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncSocket.m +0 -8513
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncUdpSocket.h +0 -1036
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncUdpSocket.m +0 -5632
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDNumber.h +0 -12
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDNumber.m +0 -88
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDRange.h +0 -56
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDRange.m +0 -106
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPConnection.h +0 -107
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPConnection.m +0 -2238
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPLogging.h +0 -122
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPMessage.h +0 -48
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPMessage.m +0 -114
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPResponse.h +0 -149
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPServer.h +0 -200
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPServer.m +0 -720
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPDataResponse.h +0 -13
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPDataResponse.m +0 -83
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPErrorResponse.h +0 -9
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPErrorResponse.m +0 -40
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/HTTPResponseProxy.h +0 -13
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/HTTPResponseProxy.m +0 -84
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/Route.h +0 -18
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/Route.m +0 -11
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteRequest.h +0 -16
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteRequest.m +0 -50
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteResponse.h +0 -20
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteResponse.m +0 -66
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingConnection.h +0 -5
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingConnection.m +0 -142
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingHTTPServer.h +0 -55
- package/WebDriverAgentMac/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingHTTPServer.m +0 -288
package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPDataResponse.m
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
#import "HTTPDataResponse.h"
|
|
2
|
-
#import "HTTPLogging.h"
|
|
3
|
-
|
|
4
|
-
#if ! __has_feature(objc_arc)
|
|
5
|
-
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
|
6
|
-
#endif
|
|
7
|
-
|
|
8
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
9
|
-
#pragma clang diagnostic ignored "-Wcast-qual"
|
|
10
|
-
#pragma clang diagnostic ignored "-Wunused-variable"
|
|
11
|
-
|
|
12
|
-
// Log levels : off, error, warn, info, verbose
|
|
13
|
-
// Other flags: trace
|
|
14
|
-
static const int httpLogLevel = HTTP_LOG_LEVEL_OFF; // | HTTP_LOG_FLAG_TRACE;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@implementation HTTPDataResponse
|
|
18
|
-
|
|
19
|
-
- (id)initWithData:(NSData *)dataParam
|
|
20
|
-
{
|
|
21
|
-
if((self = [super init]))
|
|
22
|
-
{
|
|
23
|
-
HTTPLogTrace();
|
|
24
|
-
|
|
25
|
-
offset = 0;
|
|
26
|
-
data = dataParam;
|
|
27
|
-
}
|
|
28
|
-
return self;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
- (void)dealloc
|
|
32
|
-
{
|
|
33
|
-
HTTPLogTrace();
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
- (UInt64)contentLength
|
|
38
|
-
{
|
|
39
|
-
UInt64 result = (UInt64)[data length];
|
|
40
|
-
|
|
41
|
-
HTTPLogTrace2(@"%@[%p]: contentLength - %llu", THIS_FILE, self, result);
|
|
42
|
-
|
|
43
|
-
return result;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
- (UInt64)offset
|
|
47
|
-
{
|
|
48
|
-
HTTPLogTrace();
|
|
49
|
-
|
|
50
|
-
return offset;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
- (void)setOffset:(UInt64)offsetParam
|
|
54
|
-
{
|
|
55
|
-
HTTPLogTrace2(@"%@[%p]: setOffset:%lu", THIS_FILE, self, (unsigned long)offset);
|
|
56
|
-
|
|
57
|
-
offset = (NSUInteger)offsetParam;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
- (NSData *)readDataOfLength:(NSUInteger)lengthParameter
|
|
61
|
-
{
|
|
62
|
-
HTTPLogTrace2(@"%@[%p]: readDataOfLength:%lu", THIS_FILE, self, (unsigned long)lengthParameter);
|
|
63
|
-
|
|
64
|
-
NSUInteger remaining = [data length] - offset;
|
|
65
|
-
NSUInteger length = lengthParameter < remaining ? lengthParameter : remaining;
|
|
66
|
-
|
|
67
|
-
void *bytes = (void *)(((char*)[data bytes]) + offset);
|
|
68
|
-
|
|
69
|
-
offset += length;
|
|
70
|
-
|
|
71
|
-
return [NSData dataWithBytesNoCopy:bytes length:length freeWhenDone:NO];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
- (BOOL)isDone
|
|
75
|
-
{
|
|
76
|
-
BOOL result = (offset == [data length]);
|
|
77
|
-
|
|
78
|
-
HTTPLogTrace2(@"%@[%p]: isDone - %@", THIS_FILE, self, (result ? @"YES" : @"NO"));
|
|
79
|
-
|
|
80
|
-
return result;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@end
|
package/WebDriverAgentMac/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPErrorResponse.m
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
#import "HTTPErrorResponse.h"
|
|
2
|
-
|
|
3
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
4
|
-
|
|
5
|
-
@implementation HTTPErrorResponse
|
|
6
|
-
|
|
7
|
-
-(id)initWithErrorCode:(int)httpErrorCode
|
|
8
|
-
{
|
|
9
|
-
if ((self = [super init]))
|
|
10
|
-
{
|
|
11
|
-
_status = httpErrorCode;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
return self;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
- (UInt64) contentLength {
|
|
18
|
-
return 0;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
- (UInt64) offset {
|
|
22
|
-
return 0;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
- (void)setOffset:(UInt64)offset {
|
|
26
|
-
;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
- (NSData*) readDataOfLength:(NSUInteger)length {
|
|
30
|
-
return nil;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
- (BOOL) isDone {
|
|
34
|
-
return YES;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
- (NSInteger) status {
|
|
38
|
-
return _status;
|
|
39
|
-
}
|
|
40
|
-
@end
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import "HTTPResponse.h"
|
|
3
|
-
|
|
4
|
-
// Wraps an HTTPResponse object to allow setting a custom status code
|
|
5
|
-
// without needing to create subclasses of every response.
|
|
6
|
-
@interface HTTPResponseProxy : NSObject <HTTPResponse>
|
|
7
|
-
|
|
8
|
-
@property (nonatomic) NSObject<HTTPResponse> *response;
|
|
9
|
-
@property (nonatomic) NSInteger status;
|
|
10
|
-
|
|
11
|
-
- (NSInteger)customStatus;
|
|
12
|
-
|
|
13
|
-
@end
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#import "HTTPResponseProxy.h"
|
|
2
|
-
|
|
3
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
4
|
-
|
|
5
|
-
@implementation HTTPResponseProxy
|
|
6
|
-
|
|
7
|
-
@synthesize response;
|
|
8
|
-
@synthesize status;
|
|
9
|
-
|
|
10
|
-
- (NSInteger)status {
|
|
11
|
-
if (status != 0) {
|
|
12
|
-
return status;
|
|
13
|
-
} else if ([response respondsToSelector:@selector(status)]) {
|
|
14
|
-
return [response status];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return 200;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
- (void)setStatus:(NSInteger)statusCode {
|
|
21
|
-
status = statusCode;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
- (NSInteger)customStatus {
|
|
25
|
-
return status;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// Implement the required HTTPResponse methods
|
|
29
|
-
- (UInt64)contentLength {
|
|
30
|
-
if (response) {
|
|
31
|
-
return [response contentLength];
|
|
32
|
-
} else {
|
|
33
|
-
return 0;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
- (UInt64)offset {
|
|
38
|
-
if (response) {
|
|
39
|
-
return [response offset];
|
|
40
|
-
} else {
|
|
41
|
-
return 0;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
- (void)setOffset:(UInt64)offset {
|
|
46
|
-
if (response) {
|
|
47
|
-
[response setOffset:offset];
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
- (NSData *)readDataOfLength:(NSUInteger)length {
|
|
52
|
-
if (response) {
|
|
53
|
-
return [response readDataOfLength:length];
|
|
54
|
-
} else {
|
|
55
|
-
return nil;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
- (BOOL)isDone {
|
|
60
|
-
if (response) {
|
|
61
|
-
return [response isDone];
|
|
62
|
-
} else {
|
|
63
|
-
return YES;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// Forward all other invocations to the actual response object
|
|
68
|
-
- (void)forwardInvocation:(NSInvocation *)invocation {
|
|
69
|
-
if ([response respondsToSelector:[invocation selector]]) {
|
|
70
|
-
[invocation invokeWithTarget:response];
|
|
71
|
-
} else {
|
|
72
|
-
[super forwardInvocation:invocation];
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
- (BOOL)respondsToSelector:(SEL)selector {
|
|
77
|
-
if ([super respondsToSelector:selector])
|
|
78
|
-
return YES;
|
|
79
|
-
|
|
80
|
-
return [response respondsToSelector:selector];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
@end
|
|
84
|
-
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import "RoutingHTTPServer.h"
|
|
3
|
-
|
|
4
|
-
@interface Route : NSObject
|
|
5
|
-
|
|
6
|
-
@property (nonatomic) NSRegularExpression *regex;
|
|
7
|
-
@property (nonatomic, copy) RequestHandler handler;
|
|
8
|
-
|
|
9
|
-
#if __has_feature(objc_arc_weak)
|
|
10
|
-
@property (nonatomic, weak) id target;
|
|
11
|
-
#else
|
|
12
|
-
@property (nonatomic, assign) id target;
|
|
13
|
-
#endif
|
|
14
|
-
|
|
15
|
-
@property (nonatomic, assign) SEL selector;
|
|
16
|
-
@property (nonatomic) NSArray *keys;
|
|
17
|
-
|
|
18
|
-
@end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
@class HTTPMessage;
|
|
3
|
-
|
|
4
|
-
@interface RouteRequest : NSObject
|
|
5
|
-
|
|
6
|
-
@property (nonatomic, readonly) NSDictionary *headers;
|
|
7
|
-
@property (nonatomic, readonly) NSDictionary *params;
|
|
8
|
-
|
|
9
|
-
- (id)initWithHTTPMessage:(HTTPMessage *)msg parameters:(NSDictionary *)params;
|
|
10
|
-
- (NSString *)header:(NSString *)field;
|
|
11
|
-
- (id)param:(NSString *)name;
|
|
12
|
-
- (NSString *)method;
|
|
13
|
-
- (NSURL *)url;
|
|
14
|
-
- (NSData *)body;
|
|
15
|
-
|
|
16
|
-
@end
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
#import "RouteRequest.h"
|
|
2
|
-
#import "HTTPMessage.h"
|
|
3
|
-
|
|
4
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
5
|
-
#pragma clang diagnostic ignored "-Widiomatic-parentheses"
|
|
6
|
-
|
|
7
|
-
@implementation RouteRequest {
|
|
8
|
-
HTTPMessage *message;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
@synthesize params;
|
|
12
|
-
|
|
13
|
-
- (id)initWithHTTPMessage:(HTTPMessage *)msg parameters:(NSDictionary *)parameters {
|
|
14
|
-
if (self = [super init]) {
|
|
15
|
-
params = parameters;
|
|
16
|
-
message = msg;
|
|
17
|
-
}
|
|
18
|
-
return self;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
- (NSDictionary *)headers {
|
|
22
|
-
return [message allHeaderFields];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
- (NSString *)header:(NSString *)field {
|
|
26
|
-
return [message headerField:field];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
- (id)param:(NSString *)name {
|
|
30
|
-
return [params objectForKey:name];
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
- (NSString *)method {
|
|
34
|
-
return [message method];
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
- (NSURL *)url {
|
|
38
|
-
return [message url];
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
- (NSData *)body {
|
|
42
|
-
return [message body];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
- (NSString *)description {
|
|
46
|
-
NSData *data = [message messageData];
|
|
47
|
-
return [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
@end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#import "HTTPResponse.h"
|
|
3
|
-
@class HTTPConnection;
|
|
4
|
-
@class HTTPResponseProxy;
|
|
5
|
-
|
|
6
|
-
@interface RouteResponse : NSObject
|
|
7
|
-
|
|
8
|
-
@property (nonatomic, unsafe_unretained, readonly) HTTPConnection *connection;
|
|
9
|
-
@property (nonatomic, readonly) NSDictionary *headers;
|
|
10
|
-
@property (nonatomic, strong) NSObject<HTTPResponse> *response;
|
|
11
|
-
@property (nonatomic, readonly) NSObject<HTTPResponse> *proxiedResponse;
|
|
12
|
-
@property (nonatomic) NSInteger statusCode;
|
|
13
|
-
|
|
14
|
-
- (id)initWithConnection:(HTTPConnection *)theConnection;
|
|
15
|
-
- (void)setHeader:(NSString *)field value:(NSString *)value;
|
|
16
|
-
- (void)respondWithString:(NSString *)string;
|
|
17
|
-
- (void)respondWithString:(NSString *)string encoding:(NSStringEncoding)encoding;
|
|
18
|
-
- (void)respondWithData:(NSData *)data;
|
|
19
|
-
|
|
20
|
-
@end
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
#import "RouteResponse.h"
|
|
2
|
-
#import "HTTPConnection.h"
|
|
3
|
-
#import "HTTPDataResponse.h"
|
|
4
|
-
#import "HTTPResponseProxy.h"
|
|
5
|
-
|
|
6
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
7
|
-
#pragma clang diagnostic ignored "-Widiomatic-parentheses"
|
|
8
|
-
|
|
9
|
-
@implementation RouteResponse {
|
|
10
|
-
NSMutableDictionary *headers;
|
|
11
|
-
HTTPResponseProxy *proxy;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
@synthesize connection;
|
|
15
|
-
@synthesize headers;
|
|
16
|
-
|
|
17
|
-
- (id)initWithConnection:(HTTPConnection *)theConnection {
|
|
18
|
-
if (self = [super init]) {
|
|
19
|
-
connection = theConnection;
|
|
20
|
-
headers = [[NSMutableDictionary alloc] init];
|
|
21
|
-
proxy = [[HTTPResponseProxy alloc] init];
|
|
22
|
-
}
|
|
23
|
-
return self;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
- (NSObject <HTTPResponse>*)response {
|
|
27
|
-
return proxy.response;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
- (void)setResponse:(NSObject <HTTPResponse>*)response {
|
|
31
|
-
proxy.response = response;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
- (NSObject <HTTPResponse>*)proxiedResponse {
|
|
35
|
-
if (proxy.response != nil || proxy.customStatus != 0 || [headers count] > 0) {
|
|
36
|
-
return proxy;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return nil;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
- (NSInteger)statusCode {
|
|
43
|
-
return proxy.status;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
- (void)setStatusCode:(NSInteger)status {
|
|
47
|
-
proxy.status = status;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
- (void)setHeader:(NSString *)field value:(NSString *)value {
|
|
51
|
-
[headers setObject:value forKey:field];
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
- (void)respondWithString:(NSString *)string {
|
|
55
|
-
[self respondWithString:string encoding:NSUTF8StringEncoding];
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
- (void)respondWithString:(NSString *)string encoding:(NSStringEncoding)encoding {
|
|
59
|
-
[self respondWithData:[string dataUsingEncoding:encoding]];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
- (void)respondWithData:(NSData *)data {
|
|
63
|
-
self.response = [[HTTPDataResponse alloc] initWithData:data];
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
@end
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
#import "RoutingConnection.h"
|
|
2
|
-
#import "RoutingHTTPServer.h"
|
|
3
|
-
#import "HTTPMessage.h"
|
|
4
|
-
#import "HTTPResponseProxy.h"
|
|
5
|
-
|
|
6
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
7
|
-
#pragma clang diagnostic ignored "-Widiomatic-parentheses"
|
|
8
|
-
#pragma clang diagnostic ignored "-Wundeclared-selector"
|
|
9
|
-
|
|
10
|
-
@implementation RoutingConnection {
|
|
11
|
-
__unsafe_unretained RoutingHTTPServer *http;
|
|
12
|
-
NSDictionary *headers;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
- (id)initWithAsyncSocket:(GCDAsyncSocket *)newSocket configuration:(HTTPConfig *)aConfig {
|
|
16
|
-
if (self = [super initWithAsyncSocket:newSocket configuration:aConfig]) {
|
|
17
|
-
NSAssert([config.server isKindOfClass:[RoutingHTTPServer class]],
|
|
18
|
-
@"A RoutingConnection is being used with a server that is not a %@",
|
|
19
|
-
NSStringFromClass([RoutingHTTPServer class]));
|
|
20
|
-
|
|
21
|
-
http = (RoutingHTTPServer *)config.server;
|
|
22
|
-
}
|
|
23
|
-
return self;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
- (BOOL)supportsMethod:(NSString *)method atPath:(NSString *)path {
|
|
27
|
-
|
|
28
|
-
if ([http supportsMethod:method])
|
|
29
|
-
return YES;
|
|
30
|
-
|
|
31
|
-
return [super supportsMethod:method atPath:path];
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
- (BOOL)shouldHandleRequestForMethod:(NSString *)method atPath:(NSString *)path {
|
|
35
|
-
// The default implementation is strict about the use of Content-Length. Either
|
|
36
|
-
// a given method + path combination must *always* include data or *never*
|
|
37
|
-
// include data. The routing connection is lenient, a POST that sometimes does
|
|
38
|
-
// not include data or a GET that sometimes does is fine. It is up to the route
|
|
39
|
-
// implementations to decide how to handle these situations.
|
|
40
|
-
return YES;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
- (void)processBodyData:(NSData *)postDataChunk {
|
|
44
|
-
BOOL result = [request appendData:postDataChunk];
|
|
45
|
-
if (!result) {
|
|
46
|
-
// TODO: Log
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
- (NSObject<HTTPResponse> *)httpResponseForMethod:(NSString *)method URI:(NSString *)path {
|
|
51
|
-
NSURL *url = [request url];
|
|
52
|
-
NSString *query = nil;
|
|
53
|
-
NSDictionary *params = [NSDictionary dictionary];
|
|
54
|
-
headers = nil;
|
|
55
|
-
|
|
56
|
-
if (url) {
|
|
57
|
-
path = [url path]; // Strip the query string from the path
|
|
58
|
-
query = [url query];
|
|
59
|
-
if (query) {
|
|
60
|
-
params = [self parseParams:query];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
RouteResponse *response = [http routeMethod:method withPath:path parameters:params request:request connection:self];
|
|
65
|
-
if (response != nil) {
|
|
66
|
-
headers = response.headers;
|
|
67
|
-
return response.proxiedResponse;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Set a MIME type for static files if possible
|
|
71
|
-
NSObject<HTTPResponse> *staticResponse = [super httpResponseForMethod:method URI:path];
|
|
72
|
-
if (staticResponse && [staticResponse respondsToSelector:@selector(filePath)]) {
|
|
73
|
-
NSString *mimeType = [http mimeTypeForPath:[staticResponse performSelector:@selector(filePath)]];
|
|
74
|
-
if (mimeType) {
|
|
75
|
-
headers = [NSDictionary dictionaryWithObject:mimeType forKey:@"Content-Type"];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return staticResponse;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
- (void)responseHasAvailableData:(NSObject<HTTPResponse> *)sender {
|
|
82
|
-
HTTPResponseProxy *proxy = (HTTPResponseProxy *)httpResponse;
|
|
83
|
-
if (proxy.response == sender) {
|
|
84
|
-
[super responseHasAvailableData:httpResponse];
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
- (void)responseDidAbort:(NSObject<HTTPResponse> *)sender {
|
|
89
|
-
HTTPResponseProxy *proxy = (HTTPResponseProxy *)httpResponse;
|
|
90
|
-
if (proxy.response == sender) {
|
|
91
|
-
[super responseDidAbort:httpResponse];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
- (void)setHeadersForResponse:(HTTPMessage *)response isError:(BOOL)isError {
|
|
96
|
-
[http.defaultHeaders enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL *stop) {
|
|
97
|
-
[response setHeaderField:field value:value];
|
|
98
|
-
}];
|
|
99
|
-
|
|
100
|
-
if (headers && !isError) {
|
|
101
|
-
[headers enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL *stop) {
|
|
102
|
-
[response setHeaderField:field value:value];
|
|
103
|
-
}];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// Set the connection header if not already specified
|
|
107
|
-
NSString *connection = [response headerField:@"Connection"];
|
|
108
|
-
if (!connection) {
|
|
109
|
-
connection = [self shouldDie] ? @"close" : @"keep-alive";
|
|
110
|
-
[response setHeaderField:@"Connection" value:connection];
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
- (NSData *)preprocessResponse:(HTTPMessage *)response {
|
|
115
|
-
[self setHeadersForResponse:response isError:NO];
|
|
116
|
-
return [super preprocessResponse:response];
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
- (NSData *)preprocessErrorResponse:(HTTPMessage *)response {
|
|
120
|
-
[self setHeadersForResponse:response isError:YES];
|
|
121
|
-
return [super preprocessErrorResponse:response];
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
- (BOOL)shouldDie {
|
|
125
|
-
__block BOOL shouldDie = [super shouldDie];
|
|
126
|
-
|
|
127
|
-
// Allow custom headers to determine if the connection should be closed
|
|
128
|
-
if (!shouldDie && headers) {
|
|
129
|
-
[headers enumerateKeysAndObjectsUsingBlock:^(id field, id value, BOOL *stop) {
|
|
130
|
-
if ([field caseInsensitiveCompare:@"connection"] == NSOrderedSame) {
|
|
131
|
-
if ([value caseInsensitiveCompare:@"close"] == NSOrderedSame) {
|
|
132
|
-
shouldDie = YES;
|
|
133
|
-
}
|
|
134
|
-
*stop = YES;
|
|
135
|
-
}
|
|
136
|
-
}];
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return shouldDie;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
@end
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
|
|
3
|
-
//! Project version number for Peertalk.
|
|
4
|
-
FOUNDATION_EXPORT double RoutingHTTPServerVersionNumber;
|
|
5
|
-
|
|
6
|
-
//! Project version string for Peertalk.
|
|
7
|
-
FOUNDATION_EXPORT const unsigned char RoutingHTTPServerVersionString[];
|
|
8
|
-
|
|
9
|
-
#import "HTTPServer.h"
|
|
10
|
-
#import "HTTPConnection.h"
|
|
11
|
-
#import "HTTPResponse.h"
|
|
12
|
-
#import "RouteResponse.h"
|
|
13
|
-
#import "RouteRequest.h"
|
|
14
|
-
#import "RoutingConnection.h"
|
|
15
|
-
|
|
16
|
-
#import "GCDAsyncSocket.h"
|
|
17
|
-
|
|
18
|
-
typedef void (^RequestHandler)(RouteRequest *request, RouteResponse *response);
|
|
19
|
-
|
|
20
|
-
@interface RoutingHTTPServer : HTTPServer
|
|
21
|
-
|
|
22
|
-
@property (nonatomic, readonly) NSDictionary *defaultHeaders;
|
|
23
|
-
|
|
24
|
-
// Specifies headers that will be set on every response.
|
|
25
|
-
// These headers can be overridden by RouteResponses.
|
|
26
|
-
- (void)setDefaultHeaders:(NSDictionary *)headers;
|
|
27
|
-
- (void)setDefaultHeader:(NSString *)field value:(NSString *)value;
|
|
28
|
-
|
|
29
|
-
// Returns the dispatch queue on which routes are processed.
|
|
30
|
-
// By default this is NULL and routes are processed on CocoaHTTPServer's
|
|
31
|
-
// connection queue. You can specify a queue to process routes on, such as
|
|
32
|
-
// dispatch_get_main_queue() to process all routes on the main thread.
|
|
33
|
-
- (dispatch_queue_t)routeQueue;
|
|
34
|
-
- (void)setRouteQueue:(dispatch_queue_t)queue;
|
|
35
|
-
|
|
36
|
-
- (NSDictionary *)mimeTypes;
|
|
37
|
-
- (void)setMIMETypes:(NSDictionary *)types;
|
|
38
|
-
- (void)setMIMEType:(NSString *)type forExtension:(NSString *)ext;
|
|
39
|
-
- (NSString *)mimeTypeForPath:(NSString *)path;
|
|
40
|
-
|
|
41
|
-
// Convenience methods. Yes I know, this is Cocoa and we don't use convenience
|
|
42
|
-
// methods because typing lengthy primitives over and over and over again is
|
|
43
|
-
// elegant with the beauty and the poetry. These are just, you know, here.
|
|
44
|
-
- (void)get:(NSString *)path withBlock:(RequestHandler)block;
|
|
45
|
-
- (void)post:(NSString *)path withBlock:(RequestHandler)block;
|
|
46
|
-
- (void)put:(NSString *)path withBlock:(RequestHandler)block;
|
|
47
|
-
- (void)delete:(NSString *)path withBlock:(RequestHandler)block;
|
|
48
|
-
|
|
49
|
-
- (void)handleMethod:(NSString *)method withPath:(NSString *)path block:(RequestHandler)block;
|
|
50
|
-
- (void)handleMethod:(NSString *)method withPath:(NSString *)path target:(id)target selector:(SEL)selector;
|
|
51
|
-
|
|
52
|
-
- (BOOL)supportsMethod:(NSString *)method;
|
|
53
|
-
- (RouteResponse *)routeMethod:(NSString *)method withPath:(NSString *)path parameters:(NSDictionary *)params request:(HTTPMessage *)request connection:(HTTPConnection *)connection;
|
|
54
|
-
|
|
55
|
-
@end
|