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,303 +0,0 @@
|
|
|
1
|
-
#import "RoutingHTTPServer.h"
|
|
2
|
-
#import "RoutingConnection.h"
|
|
3
|
-
#import "Route.h"
|
|
4
|
-
|
|
5
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
6
|
-
#pragma clang diagnostic ignored "-Widiomatic-parentheses"
|
|
7
|
-
|
|
8
|
-
@implementation RoutingHTTPServer {
|
|
9
|
-
NSMutableDictionary *routes;
|
|
10
|
-
NSMutableDictionary *defaultHeaders;
|
|
11
|
-
NSMutableDictionary *mimeTypes;
|
|
12
|
-
dispatch_queue_t routeQueue;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
@synthesize defaultHeaders;
|
|
16
|
-
|
|
17
|
-
- (id)init {
|
|
18
|
-
if (self = [super init]) {
|
|
19
|
-
connectionClass = [RoutingConnection self];
|
|
20
|
-
routes = [[NSMutableDictionary alloc] init];
|
|
21
|
-
defaultHeaders = [[NSMutableDictionary alloc] init];
|
|
22
|
-
[self setupMIMETypes];
|
|
23
|
-
}
|
|
24
|
-
return self;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
#if !OS_OBJECT_USE_OBJC_RETAIN_RELEASE
|
|
28
|
-
- (void)dealloc {
|
|
29
|
-
if (routeQueue)
|
|
30
|
-
dispatch_release(routeQueue);
|
|
31
|
-
}
|
|
32
|
-
#endif
|
|
33
|
-
|
|
34
|
-
- (void)setDefaultHeaders:(NSDictionary *)headers {
|
|
35
|
-
if (headers) {
|
|
36
|
-
defaultHeaders = [headers mutableCopy];
|
|
37
|
-
} else {
|
|
38
|
-
defaultHeaders = [[NSMutableDictionary alloc] init];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
- (void)setDefaultHeader:(NSString *)field value:(NSString *)value {
|
|
43
|
-
[defaultHeaders setObject:value forKey:field];
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
- (dispatch_queue_t)routeQueue {
|
|
47
|
-
return routeQueue;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
- (void)setRouteQueue:(dispatch_queue_t)queue {
|
|
51
|
-
#if !OS_OBJECT_USE_OBJC_RETAIN_RELEASE
|
|
52
|
-
if (queue)
|
|
53
|
-
dispatch_retain(queue);
|
|
54
|
-
|
|
55
|
-
if (routeQueue)
|
|
56
|
-
dispatch_release(routeQueue);
|
|
57
|
-
#endif
|
|
58
|
-
|
|
59
|
-
routeQueue = queue;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
- (NSDictionary *)mimeTypes {
|
|
63
|
-
return mimeTypes;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
- (void)setMIMETypes:(NSDictionary *)types {
|
|
67
|
-
NSMutableDictionary *newTypes;
|
|
68
|
-
if (types) {
|
|
69
|
-
newTypes = [types mutableCopy];
|
|
70
|
-
} else {
|
|
71
|
-
newTypes = [[NSMutableDictionary alloc] init];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
mimeTypes = newTypes;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
- (void)setMIMEType:(NSString *)theType forExtension:(NSString *)ext {
|
|
78
|
-
[mimeTypes setObject:theType forKey:ext];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
- (NSString *)mimeTypeForPath:(NSString *)path {
|
|
82
|
-
NSString *ext = [[path pathExtension] lowercaseString];
|
|
83
|
-
if (!ext || [ext length] < 1)
|
|
84
|
-
return nil;
|
|
85
|
-
|
|
86
|
-
return [mimeTypes objectForKey:ext];
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
- (void)get:(NSString *)path withBlock:(RequestHandler)block {
|
|
90
|
-
[self handleMethod:@"GET" withPath:path block:block];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
- (void)post:(NSString *)path withBlock:(RequestHandler)block {
|
|
94
|
-
[self handleMethod:@"POST" withPath:path block:block];
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
- (void)put:(NSString *)path withBlock:(RequestHandler)block {
|
|
98
|
-
[self handleMethod:@"PUT" withPath:path block:block];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
- (void)delete:(NSString *)path withBlock:(RequestHandler)block {
|
|
102
|
-
[self handleMethod:@"DELETE" withPath:path block:block];
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
- (void)handleMethod:(NSString *)method
|
|
106
|
-
withPath:(NSString *)path
|
|
107
|
-
block:(RequestHandler)block {
|
|
108
|
-
Route *route = [self routeWithPath:path];
|
|
109
|
-
route.handler = block;
|
|
110
|
-
|
|
111
|
-
[self addRoute:route forMethod:method];
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
- (void)handleMethod:(NSString *)method
|
|
115
|
-
withPath:(NSString *)path
|
|
116
|
-
target:(id)target
|
|
117
|
-
selector:(SEL)selector {
|
|
118
|
-
Route *route = [self routeWithPath:path];
|
|
119
|
-
route.target = target;
|
|
120
|
-
route.selector = selector;
|
|
121
|
-
|
|
122
|
-
[self addRoute:route forMethod:method];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
- (void)addRoute:(Route *)route forMethod:(NSString *)method {
|
|
126
|
-
method = [method uppercaseString];
|
|
127
|
-
NSMutableArray *methodRoutes = [routes objectForKey:method];
|
|
128
|
-
if (methodRoutes == nil) {
|
|
129
|
-
methodRoutes = [NSMutableArray array];
|
|
130
|
-
[routes setObject:methodRoutes forKey:method];
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
[methodRoutes addObject:route];
|
|
134
|
-
|
|
135
|
-
// Define a HEAD route for all GET routes
|
|
136
|
-
if ([method isEqualToString:@"GET"]) {
|
|
137
|
-
[self addRoute:route forMethod:@"HEAD"];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
- (Route *)routeWithPath:(NSString *)path {
|
|
142
|
-
Route *route = [[Route alloc] init];
|
|
143
|
-
NSMutableArray *keys = [NSMutableArray array];
|
|
144
|
-
|
|
145
|
-
if ([path length] > 2 && [path characterAtIndex:0] == '{') {
|
|
146
|
-
// This is a custom regular expression, just remove the {}
|
|
147
|
-
path = [path substringWithRange:NSMakeRange(1, [path length] - 2)];
|
|
148
|
-
} else {
|
|
149
|
-
NSRegularExpression *regex = nil;
|
|
150
|
-
|
|
151
|
-
// Escape regex characters
|
|
152
|
-
regex = [NSRegularExpression regularExpressionWithPattern:@"[.+()]" options:(NSRegularExpressionOptions)0 error:nil];
|
|
153
|
-
path = [regex stringByReplacingMatchesInString:path options:(NSMatchingOptions)0 range:NSMakeRange(0, path.length) withTemplate:@"\\\\$0"];
|
|
154
|
-
|
|
155
|
-
// Parse any :parameters and * in the path
|
|
156
|
-
regex = [NSRegularExpression regularExpressionWithPattern:@"(:(\\w+)|\\*)"
|
|
157
|
-
options:(NSRegularExpressionOptions)0
|
|
158
|
-
error:nil];
|
|
159
|
-
NSMutableString *regexPath = [NSMutableString stringWithString:path];
|
|
160
|
-
__block NSInteger diff = 0;
|
|
161
|
-
[regex enumerateMatchesInString:path options:(NSMatchingOptions)0 range:NSMakeRange(0, path.length)
|
|
162
|
-
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
|
|
163
|
-
NSRange replacementRange = NSMakeRange(diff + result.range.location, result.range.length);
|
|
164
|
-
NSString *replacementString;
|
|
165
|
-
|
|
166
|
-
NSString *capturedString = [path substringWithRange:result.range];
|
|
167
|
-
if ([capturedString isEqualToString:@"*"]) {
|
|
168
|
-
[keys addObject:@"wildcards"];
|
|
169
|
-
replacementString = @"(.*?)";
|
|
170
|
-
} else {
|
|
171
|
-
NSString *keyString = [path substringWithRange:[result rangeAtIndex:2]];
|
|
172
|
-
[keys addObject:keyString];
|
|
173
|
-
replacementString = @"([^/]+)";
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
[regexPath replaceCharactersInRange:replacementRange withString:replacementString];
|
|
177
|
-
diff += replacementString.length - result.range.length;
|
|
178
|
-
}];
|
|
179
|
-
|
|
180
|
-
path = [NSString stringWithFormat:@"^%@$", regexPath];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
route.regex = [NSRegularExpression regularExpressionWithPattern:path options:NSRegularExpressionCaseInsensitive error:nil];
|
|
184
|
-
if ([keys count] > 0) {
|
|
185
|
-
route.keys = keys;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
return route;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
- (BOOL)supportsMethod:(NSString *)method {
|
|
192
|
-
return ([routes objectForKey:method] != nil);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
- (void)handleRoute:(Route *)route
|
|
196
|
-
withRequest:(RouteRequest *)request
|
|
197
|
-
response:(RouteResponse *)response {
|
|
198
|
-
if (route.handler) {
|
|
199
|
-
route.handler(request, response);
|
|
200
|
-
} else {
|
|
201
|
-
id target = route.target;
|
|
202
|
-
SEL selector = route.selector;
|
|
203
|
-
NSMethodSignature *signature = [target methodSignatureForSelector:selector];
|
|
204
|
-
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
|
|
205
|
-
[invocation setSelector:selector];
|
|
206
|
-
[invocation setArgument:&request atIndex:2];
|
|
207
|
-
[invocation setArgument:&response atIndex:3];
|
|
208
|
-
[invocation invokeWithTarget:target];
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
- (RouteResponse *)routeMethod:(NSString *)method
|
|
213
|
-
withPath:(NSString *)path
|
|
214
|
-
parameters:(NSDictionary *)params
|
|
215
|
-
request:(HTTPMessage *)httpMessage
|
|
216
|
-
connection:(HTTPConnection *)connection {
|
|
217
|
-
NSMutableArray *methodRoutes = [routes objectForKey:method];
|
|
218
|
-
if (methodRoutes == nil)
|
|
219
|
-
return nil;
|
|
220
|
-
|
|
221
|
-
for (Route *route in methodRoutes) {
|
|
222
|
-
NSTextCheckingResult *result = [route.regex firstMatchInString:path options:(NSMatchingOptions)0 range:NSMakeRange(0, path.length)];
|
|
223
|
-
if (!result)
|
|
224
|
-
continue;
|
|
225
|
-
|
|
226
|
-
// The first range is all of the text matched by the regex.
|
|
227
|
-
NSUInteger captureCount = [result numberOfRanges];
|
|
228
|
-
|
|
229
|
-
if (route.keys) {
|
|
230
|
-
// Add the route's parameters to the parameter dictionary, accounting for
|
|
231
|
-
// the first range containing the matched text.
|
|
232
|
-
if (captureCount == [route.keys count] + 1) {
|
|
233
|
-
NSMutableDictionary *newParams = [params mutableCopy];
|
|
234
|
-
NSUInteger index = 1;
|
|
235
|
-
BOOL firstWildcard = YES;
|
|
236
|
-
for (NSString *key in route.keys) {
|
|
237
|
-
NSString *capture = [path substringWithRange:[result rangeAtIndex:index]];
|
|
238
|
-
if ([key isEqualToString:@"wildcards"]) {
|
|
239
|
-
NSMutableArray *wildcards = [newParams objectForKey:key];
|
|
240
|
-
if (firstWildcard) {
|
|
241
|
-
// Create a new array and replace any existing object with the same key
|
|
242
|
-
wildcards = [NSMutableArray array];
|
|
243
|
-
[newParams setObject:wildcards forKey:key];
|
|
244
|
-
firstWildcard = NO;
|
|
245
|
-
}
|
|
246
|
-
[wildcards addObject:capture];
|
|
247
|
-
} else {
|
|
248
|
-
[newParams setObject:capture forKey:key];
|
|
249
|
-
}
|
|
250
|
-
index++;
|
|
251
|
-
}
|
|
252
|
-
params = newParams;
|
|
253
|
-
}
|
|
254
|
-
} else if (captureCount > 1) {
|
|
255
|
-
// For custom regular expressions place the anonymous captures in the captures parameter
|
|
256
|
-
NSMutableDictionary *newParams = [params mutableCopy];
|
|
257
|
-
NSMutableArray *captures = [NSMutableArray array];
|
|
258
|
-
for (NSUInteger i = 1; i < captureCount; i++) {
|
|
259
|
-
[captures addObject:[path substringWithRange:[result rangeAtIndex:i]]];
|
|
260
|
-
}
|
|
261
|
-
[newParams setObject:captures forKey:@"captures"];
|
|
262
|
-
params = newParams;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
RouteRequest *request = [[RouteRequest alloc] initWithHTTPMessage:httpMessage parameters:params];
|
|
266
|
-
RouteResponse *response = [[RouteResponse alloc] initWithConnection:connection];
|
|
267
|
-
if (!routeQueue) {
|
|
268
|
-
[self handleRoute:route withRequest:request response:response];
|
|
269
|
-
} else {
|
|
270
|
-
// Process the route on the specified queue
|
|
271
|
-
dispatch_sync(routeQueue, ^{
|
|
272
|
-
@autoreleasepool {
|
|
273
|
-
[self handleRoute:route withRequest:request response:response];
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
}
|
|
277
|
-
return response;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return nil;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
- (void)setupMIMETypes {
|
|
284
|
-
mimeTypes = [[NSMutableDictionary alloc] initWithObjectsAndKeys:
|
|
285
|
-
@"application/x-javascript", @"js",
|
|
286
|
-
@"image/gif", @"gif",
|
|
287
|
-
@"image/jpeg", @"jpg",
|
|
288
|
-
@"image/jpeg", @"jpeg",
|
|
289
|
-
@"image/png", @"png",
|
|
290
|
-
@"image/svg+xml", @"svg",
|
|
291
|
-
@"image/tiff", @"tif",
|
|
292
|
-
@"image/tiff", @"tiff",
|
|
293
|
-
@"image/x-icon", @"ico",
|
|
294
|
-
@"image/x-ms-bmp", @"bmp",
|
|
295
|
-
@"text/css", @"css",
|
|
296
|
-
@"text/html", @"html",
|
|
297
|
-
@"text/html", @"htm",
|
|
298
|
-
@"text/plain", @"txt",
|
|
299
|
-
@"text/xml", @"xml",
|
|
300
|
-
nil];
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
@end
|
|
File without changes
|
|
File without changes
|