appium-webdriveragent 16.6.0 → 16.7.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 +6 -0
- package/WebDriverAgent.xcodeproj/project.pbxproj +45 -303
- package/WebDriverAgentLib/Info.plist +2 -2
- package/WebDriverAgentLib/Routing/{WatchOS/FBWatchHTTPServer.h → FBHTTPServer.h} +11 -7
- package/WebDriverAgentLib/Routing/{WatchOS/FBWatchHTTPServer.m → FBHTTPServer.m} +26 -13
- package/WebDriverAgentLib/Routing/FBTCPSocket.h +10 -45
- package/WebDriverAgentLib/Routing/FBTCPSocket.m +12 -94
- package/WebDriverAgentLib/Routing/FBWebServer.h +1 -1
- package/WebDriverAgentLib/Routing/FBWebServer.m +4 -49
- package/WebDriverAgentLib/Routing/{WatchOS/RouteRequest.h → RouteRequest.h} +2 -4
- package/WebDriverAgentLib/Routing/{WatchOS/RouteResponse.h → RouteResponse.h} +2 -2
- package/WebDriverAgentLib/Utilities/FBMjpegServer.h +3 -5
- package/WebDriverAgentLib/Utilities/FBMjpegServer.m +1 -66
- package/package.json +1 -1
- package/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncSocket.h +0 -1220
- package/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncSocket.m +0 -8786
- package/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncUdpSocket.h +0 -1036
- package/WebDriverAgentLib/Vendor/CocoaAsyncSocket/GCDAsyncUdpSocket.m +0 -5868
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDNumber.h +0 -12
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDNumber.m +0 -88
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDRange.h +0 -56
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Categories/DDRange.m +0 -100
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPConnection.h +0 -109
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPConnection.m +0 -2281
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPLogging.h +0 -122
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPMessage.h +0 -53
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPMessage.m +0 -357
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPResponse.h +0 -149
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPServer.h +0 -126
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/HTTPServer.m +0 -372
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/LICENSE +0 -18
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPDataResponse.h +0 -13
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPDataResponse.m +0 -83
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPErrorResponse.h +0 -9
- package/WebDriverAgentLib/Vendor/CocoaHTTPServer/Responses/HTTPErrorResponse.m +0 -38
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/HTTPResponseProxy.h +0 -13
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/HTTPResponseProxy.m +0 -84
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/LICENSE +0 -19
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/Route.h +0 -18
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/Route.m +0 -11
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteRequest.h +0 -16
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteRequest.m +0 -50
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteResponse.h +0 -20
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RouteResponse.m +0 -66
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingConnection.h +0 -5
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingConnection.m +0 -142
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingHTTPServer.h +0 -55
- package/WebDriverAgentLib/Vendor/RoutingHTTPServer/RoutingHTTPServer.m +0 -303
- /package/WebDriverAgentLib/Routing/{WatchOS/RouteRequest.m → RouteRequest.m} +0 -0
- /package/WebDriverAgentLib/Routing/{WatchOS/RouteResponse.m → RouteResponse.m} +0 -0
|
@@ -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,19 +0,0 @@
|
|
|
1
|
-
Copyright (c) 2011 Matt Stevens
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
|
11
|
-
all copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
THE SOFTWARE.
|
|
@@ -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
|