appium-mac2-driver 4.2.0 → 4.3.1
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/AMW3CActionsTests.m +7 -9
- 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/WebDriverAgentMac.xcodeproj/project.pbxproj +32 -176
- package/npm-shrinkwrap.json +107 -167
- package/package.json +3 -2
- 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
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In order to provide fast and flexible logging, this project uses Cocoa Lumberjack.
|
|
3
|
-
*
|
|
4
|
-
* The Google Code page has a wealth of documentation if you have any questions.
|
|
5
|
-
* https://github.com/robbiehanson/CocoaLumberjack
|
|
6
|
-
*
|
|
7
|
-
* Here's what you need to know concerning how logging is setup for CocoaHTTPServer:
|
|
8
|
-
*
|
|
9
|
-
* There are 4 log levels:
|
|
10
|
-
* - Error
|
|
11
|
-
* - Warning
|
|
12
|
-
* - Info
|
|
13
|
-
* - Verbose
|
|
14
|
-
*
|
|
15
|
-
* In addition to this, there is a Trace flag that can be enabled.
|
|
16
|
-
* When tracing is enabled, it spits out the methods that are being called.
|
|
17
|
-
*
|
|
18
|
-
* Please note that tracing is separate from the log levels.
|
|
19
|
-
* For example, one could set the log level to warning, and enable tracing.
|
|
20
|
-
*
|
|
21
|
-
* All logging is asynchronous, except errors.
|
|
22
|
-
* To use logging within your own custom files, follow the steps below.
|
|
23
|
-
*
|
|
24
|
-
* Step 1:
|
|
25
|
-
* Import this header in your implementation file:
|
|
26
|
-
*
|
|
27
|
-
* #import "HTTPLogging.h"
|
|
28
|
-
*
|
|
29
|
-
* Step 2:
|
|
30
|
-
* Define your logging level in your implementation file:
|
|
31
|
-
*
|
|
32
|
-
* // Log levels: off, error, warn, info, verbose
|
|
33
|
-
* static const int httpLogLevel = HTTP_LOG_LEVEL_VERBOSE;
|
|
34
|
-
*
|
|
35
|
-
* If you wish to enable tracing, you could do something like this:
|
|
36
|
-
*
|
|
37
|
-
* // Debug levels: off, error, warn, info, verbose
|
|
38
|
-
* static const int httpLogLevel = HTTP_LOG_LEVEL_INFO | HTTP_LOG_FLAG_TRACE;
|
|
39
|
-
*
|
|
40
|
-
* Step 3:
|
|
41
|
-
* Replace your NSLog statements with HTTPLog statements according to the severity of the message.
|
|
42
|
-
*
|
|
43
|
-
* NSLog(@"Fatal error, no dohickey found!"); -> HTTPLogError(@"Fatal error, no dohickey found!");
|
|
44
|
-
*
|
|
45
|
-
* HTTPLog works exactly the same as NSLog.
|
|
46
|
-
* This means you can pass it multiple variables just like NSLog.
|
|
47
|
-
**/
|
|
48
|
-
|
|
49
|
-
// Define logging context for every log message coming from the HTTP server.
|
|
50
|
-
// The logging context can be extracted from the DDLogMessage from within the logging framework,
|
|
51
|
-
// which gives loggers, formatters, and filters the ability to optionally process them differently.
|
|
52
|
-
|
|
53
|
-
#define HTTP_LOG_CONTEXT 80
|
|
54
|
-
|
|
55
|
-
// Configure log levels.
|
|
56
|
-
|
|
57
|
-
#define HTTP_LOG_FLAG_ERROR (1 << 0) // 0...00001
|
|
58
|
-
#define HTTP_LOG_FLAG_WARN (1 << 1) // 0...00010
|
|
59
|
-
#define HTTP_LOG_FLAG_INFO (1 << 2) // 0...00100
|
|
60
|
-
#define HTTP_LOG_FLAG_VERBOSE (1 << 3) // 0...01000
|
|
61
|
-
|
|
62
|
-
#define HTTP_LOG_LEVEL_OFF 0 // 0...00000
|
|
63
|
-
#define HTTP_LOG_LEVEL_ERROR (HTTP_LOG_LEVEL_OFF | HTTP_LOG_FLAG_ERROR) // 0...00001
|
|
64
|
-
#define HTTP_LOG_LEVEL_WARN (HTTP_LOG_LEVEL_ERROR | HTTP_LOG_FLAG_WARN) // 0...00011
|
|
65
|
-
#define HTTP_LOG_LEVEL_INFO (HTTP_LOG_LEVEL_WARN | HTTP_LOG_FLAG_INFO) // 0...00111
|
|
66
|
-
#define HTTP_LOG_LEVEL_VERBOSE (HTTP_LOG_LEVEL_INFO | HTTP_LOG_FLAG_VERBOSE) // 0...01111
|
|
67
|
-
|
|
68
|
-
// Setup fine grained logging.
|
|
69
|
-
// The first 4 bits are being used by the standard log levels (0 - 3)
|
|
70
|
-
//
|
|
71
|
-
// We're going to add tracing, but NOT as a log level.
|
|
72
|
-
// Tracing can be turned on and off independently of log level.
|
|
73
|
-
|
|
74
|
-
#define HTTP_LOG_FLAG_TRACE (1 << 4) // 0...10000
|
|
75
|
-
|
|
76
|
-
// Setup the usual boolean macros.
|
|
77
|
-
|
|
78
|
-
#define HTTP_LOG_ERROR (httpLogLevel & HTTP_LOG_FLAG_ERROR)
|
|
79
|
-
#define HTTP_LOG_WARN (httpLogLevel & HTTP_LOG_FLAG_WARN)
|
|
80
|
-
#define HTTP_LOG_INFO (httpLogLevel & HTTP_LOG_FLAG_INFO)
|
|
81
|
-
#define HTTP_LOG_VERBOSE (httpLogLevel & HTTP_LOG_FLAG_VERBOSE)
|
|
82
|
-
#define HTTP_LOG_TRACE (httpLogLevel & HTTP_LOG_FLAG_TRACE)
|
|
83
|
-
|
|
84
|
-
// Configure asynchronous logging.
|
|
85
|
-
// We follow the default configuration,
|
|
86
|
-
// but we reserve a special macro to easily disable asynchronous logging for debugging purposes.
|
|
87
|
-
|
|
88
|
-
#define HTTP_LOG_ASYNC_ENABLED YES
|
|
89
|
-
|
|
90
|
-
#define HTTP_LOG_ASYNC_ERROR ( NO && HTTP_LOG_ASYNC_ENABLED)
|
|
91
|
-
#define HTTP_LOG_ASYNC_WARN (YES && HTTP_LOG_ASYNC_ENABLED)
|
|
92
|
-
#define HTTP_LOG_ASYNC_INFO (YES && HTTP_LOG_ASYNC_ENABLED)
|
|
93
|
-
#define HTTP_LOG_ASYNC_VERBOSE (YES && HTTP_LOG_ASYNC_ENABLED)
|
|
94
|
-
#define HTTP_LOG_ASYNC_TRACE (YES && HTTP_LOG_ASYNC_ENABLED)
|
|
95
|
-
|
|
96
|
-
// Define logging primitives.
|
|
97
|
-
|
|
98
|
-
#define HTTPLogError(...) { }
|
|
99
|
-
|
|
100
|
-
#define HTTPLogWarn(...) { }
|
|
101
|
-
|
|
102
|
-
#define HTTPLogInfo(...) { }
|
|
103
|
-
|
|
104
|
-
#define HTTPLogVerbose(...) { }
|
|
105
|
-
|
|
106
|
-
#define HTTPLogTrace() { }
|
|
107
|
-
|
|
108
|
-
#define HTTPLogTrace2(...) { }
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
#define HTTPLogCError(...) { }
|
|
112
|
-
|
|
113
|
-
#define HTTPLogCWarn(...) { }
|
|
114
|
-
|
|
115
|
-
#define HTTPLogCInfo(...) { }
|
|
116
|
-
|
|
117
|
-
#define HTTPLogCVerbose(...) { }
|
|
118
|
-
|
|
119
|
-
#define HTTPLogCTrace() { }
|
|
120
|
-
|
|
121
|
-
#define HTTPLogCTrace2(...) { }
|
|
122
|
-
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The HTTPMessage class is a simple Objective-C wrapper around Apple's CFHTTPMessage class.
|
|
3
|
-
**/
|
|
4
|
-
|
|
5
|
-
#import <Foundation/Foundation.h>
|
|
6
|
-
|
|
7
|
-
#if TARGET_OS_IPHONE
|
|
8
|
-
// Note: You may need to add the CFNetwork Framework to your project
|
|
9
|
-
#import <CFNetwork/CFNetwork.h>
|
|
10
|
-
#endif
|
|
11
|
-
|
|
12
|
-
#define HTTPVersion1_0 ((NSString *)kCFHTTPVersion1_0)
|
|
13
|
-
#define HTTPVersion1_1 ((NSString *)kCFHTTPVersion1_1)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
@interface HTTPMessage : NSObject
|
|
17
|
-
{
|
|
18
|
-
CFHTTPMessageRef message;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
- (id)initEmptyRequest;
|
|
22
|
-
|
|
23
|
-
- (id)initRequestWithMethod:(NSString *)method URL:(NSURL *)url version:(NSString *)version;
|
|
24
|
-
|
|
25
|
-
- (id)initResponseWithStatusCode:(NSInteger)code description:(NSString *)description version:(NSString *)version;
|
|
26
|
-
|
|
27
|
-
- (BOOL)appendData:(NSData *)data;
|
|
28
|
-
|
|
29
|
-
- (BOOL)isHeaderComplete;
|
|
30
|
-
|
|
31
|
-
- (NSString *)version;
|
|
32
|
-
|
|
33
|
-
- (NSString *)method;
|
|
34
|
-
- (NSURL *)url;
|
|
35
|
-
|
|
36
|
-
- (NSInteger)statusCode;
|
|
37
|
-
|
|
38
|
-
- (NSDictionary *)allHeaderFields;
|
|
39
|
-
- (NSString *)headerField:(NSString *)headerField;
|
|
40
|
-
|
|
41
|
-
- (void)setHeaderField:(NSString *)headerField value:(NSString *)headerFieldValue;
|
|
42
|
-
|
|
43
|
-
- (NSData *)messageData;
|
|
44
|
-
|
|
45
|
-
- (NSData *)body;
|
|
46
|
-
- (void)setBody:(NSData *)body;
|
|
47
|
-
|
|
48
|
-
@end
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
#import "HTTPMessage.h"
|
|
2
|
-
|
|
3
|
-
#if ! __has_feature(objc_arc)
|
|
4
|
-
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
|
5
|
-
#endif
|
|
6
|
-
|
|
7
|
-
#pragma clang diagnostic ignored "-Wdirect-ivar-access"
|
|
8
|
-
|
|
9
|
-
@implementation HTTPMessage
|
|
10
|
-
|
|
11
|
-
- (id)initEmptyRequest
|
|
12
|
-
{
|
|
13
|
-
if ((self = [super init]))
|
|
14
|
-
{
|
|
15
|
-
message = CFHTTPMessageCreateEmpty(NULL, YES);
|
|
16
|
-
}
|
|
17
|
-
return self;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
- (id)initRequestWithMethod:(NSString *)method URL:(NSURL *)url version:(NSString *)version
|
|
21
|
-
{
|
|
22
|
-
if ((self = [super init]))
|
|
23
|
-
{
|
|
24
|
-
message = CFHTTPMessageCreateRequest(NULL,
|
|
25
|
-
(__bridge CFStringRef)method,
|
|
26
|
-
(__bridge CFURLRef)url,
|
|
27
|
-
(__bridge CFStringRef)version);
|
|
28
|
-
}
|
|
29
|
-
return self;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
- (id)initResponseWithStatusCode:(NSInteger)code description:(NSString *)description version:(NSString *)version
|
|
33
|
-
{
|
|
34
|
-
if ((self = [super init]))
|
|
35
|
-
{
|
|
36
|
-
message = CFHTTPMessageCreateResponse(NULL,
|
|
37
|
-
(CFIndex)code,
|
|
38
|
-
(__bridge CFStringRef)description,
|
|
39
|
-
(__bridge CFStringRef)version);
|
|
40
|
-
}
|
|
41
|
-
return self;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
- (void)dealloc
|
|
45
|
-
{
|
|
46
|
-
if (message)
|
|
47
|
-
{
|
|
48
|
-
CFRelease(message);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
- (BOOL)appendData:(NSData *)data
|
|
53
|
-
{
|
|
54
|
-
return CFHTTPMessageAppendBytes(message, [data bytes], [data length]);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
- (BOOL)isHeaderComplete
|
|
58
|
-
{
|
|
59
|
-
return CFHTTPMessageIsHeaderComplete(message);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
- (NSString *)version
|
|
63
|
-
{
|
|
64
|
-
return (__bridge_transfer NSString *)CFHTTPMessageCopyVersion(message);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
- (NSString *)method
|
|
68
|
-
{
|
|
69
|
-
return (__bridge_transfer NSString *)CFHTTPMessageCopyRequestMethod(message);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
- (NSURL *)url
|
|
73
|
-
{
|
|
74
|
-
return (__bridge_transfer NSURL *)CFHTTPMessageCopyRequestURL(message);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
- (NSInteger)statusCode
|
|
78
|
-
{
|
|
79
|
-
return (NSInteger)CFHTTPMessageGetResponseStatusCode(message);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
- (NSDictionary *)allHeaderFields
|
|
83
|
-
{
|
|
84
|
-
return (__bridge_transfer NSDictionary *)CFHTTPMessageCopyAllHeaderFields(message);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
- (NSString *)headerField:(NSString *)headerField
|
|
88
|
-
{
|
|
89
|
-
return (__bridge_transfer NSString *)CFHTTPMessageCopyHeaderFieldValue(message, (__bridge CFStringRef)headerField);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
- (void)setHeaderField:(NSString *)headerField value:(NSString *)headerFieldValue
|
|
93
|
-
{
|
|
94
|
-
CFHTTPMessageSetHeaderFieldValue(message,
|
|
95
|
-
(__bridge CFStringRef)headerField,
|
|
96
|
-
(__bridge CFStringRef)headerFieldValue);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
- (NSData *)messageData
|
|
100
|
-
{
|
|
101
|
-
return (__bridge_transfer NSData *)CFHTTPMessageCopySerializedMessage(message);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
- (NSData *)body
|
|
105
|
-
{
|
|
106
|
-
return (__bridge_transfer NSData *)CFHTTPMessageCopyBody(message);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
- (void)setBody:(NSData *)body
|
|
110
|
-
{
|
|
111
|
-
CFHTTPMessageSetBody(message, (__bridge CFDataRef)body);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
@end
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
@protocol HTTPResponse
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns the length of the data in bytes.
|
|
8
|
-
* If you don't know the length in advance, implement the isChunked method and have it return YES.
|
|
9
|
-
**/
|
|
10
|
-
- (UInt64)contentLength;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* The HTTP server supports range requests in order to allow things like
|
|
14
|
-
* file download resumption and optimized streaming on mobile devices.
|
|
15
|
-
**/
|
|
16
|
-
- (UInt64)offset;
|
|
17
|
-
- (void)setOffset:(UInt64)offset;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns the data for the response.
|
|
21
|
-
* You do not have to return data of the exact length that is given.
|
|
22
|
-
* You may optionally return data of a lesser length.
|
|
23
|
-
* However, you must never return data of a greater length than requested.
|
|
24
|
-
* Doing so could disrupt proper support for range requests.
|
|
25
|
-
*
|
|
26
|
-
* To support asynchronous responses, read the discussion at the bottom of this header.
|
|
27
|
-
**/
|
|
28
|
-
- (NSData *)readDataOfLength:(NSUInteger)length;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Should only return YES after the HTTPConnection has read all available data.
|
|
32
|
-
* That is, all data for the response has been returned to the HTTPConnection via the readDataOfLength method.
|
|
33
|
-
**/
|
|
34
|
-
- (BOOL)isDone;
|
|
35
|
-
|
|
36
|
-
@optional
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* If you need time to calculate any part of the HTTP response headers (status code or header fields),
|
|
40
|
-
* this method allows you to delay sending the headers so that you may asynchronously execute the calculations.
|
|
41
|
-
* Simply implement this method and return YES until you have everything you need concerning the headers.
|
|
42
|
-
*
|
|
43
|
-
* This method ties into the asynchronous response architecture of the HTTPConnection.
|
|
44
|
-
* You should read the full discussion at the bottom of this header.
|
|
45
|
-
*
|
|
46
|
-
* If you return YES from this method,
|
|
47
|
-
* the HTTPConnection will wait for you to invoke the responseHasAvailableData method.
|
|
48
|
-
* After you do, the HTTPConnection will again invoke this method to see if the response is ready to send the headers.
|
|
49
|
-
*
|
|
50
|
-
* You should only delay sending the headers until you have everything you need concerning just the headers.
|
|
51
|
-
* Asynchronously generating the body of the response is not an excuse to delay sending the headers.
|
|
52
|
-
* Instead you should tie into the asynchronous response architecture, and use techniques such as the isChunked method.
|
|
53
|
-
*
|
|
54
|
-
* Important: You should read the discussion at the bottom of this header.
|
|
55
|
-
**/
|
|
56
|
-
- (BOOL)delayResponseHeaders;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Status code for response.
|
|
60
|
-
* Allows for responses such as redirect (301), etc.
|
|
61
|
-
**/
|
|
62
|
-
- (NSInteger)status;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* If you want to add any extra HTTP headers to the response,
|
|
66
|
-
* simply return them in a dictionary in this method.
|
|
67
|
-
**/
|
|
68
|
-
- (NSDictionary *)httpHeaders;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* If you don't know the content-length in advance,
|
|
72
|
-
* implement this method in your custom response class and return YES.
|
|
73
|
-
*
|
|
74
|
-
* Important: You should read the discussion at the bottom of this header.
|
|
75
|
-
**/
|
|
76
|
-
- (BOOL)isChunked;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* This method is called from the HTTPConnection class when the connection is closed,
|
|
80
|
-
* or when the connection is finished with the response.
|
|
81
|
-
* If your response is asynchronous, you should implement this method so you know not to
|
|
82
|
-
* invoke any methods on the HTTPConnection after this method is called (as the connection may be deallocated).
|
|
83
|
-
**/
|
|
84
|
-
- (void)connectionDidClose;
|
|
85
|
-
|
|
86
|
-
@end
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Important notice to those implementing custom asynchronous and/or chunked responses:
|
|
91
|
-
*
|
|
92
|
-
* HTTPConnection supports asynchronous responses. All you have to do in your custom response class is
|
|
93
|
-
* asynchronously generate the response, and invoke HTTPConnection's responseHasAvailableData method.
|
|
94
|
-
* You don't have to wait until you have all of the response ready to invoke this method. For example, if you
|
|
95
|
-
* generate the response in incremental chunks, you could call responseHasAvailableData after generating
|
|
96
|
-
* each chunk. Please see the HTTPAsyncFileResponse class for an example of how to do this.
|
|
97
|
-
*
|
|
98
|
-
* The normal flow of events for an HTTPConnection while responding to a request is like this:
|
|
99
|
-
* - Send http resopnse headers
|
|
100
|
-
* - Get data from response via readDataOfLength method.
|
|
101
|
-
* - Add data to asyncSocket's write queue.
|
|
102
|
-
* - Wait for asyncSocket to notify it that the data has been sent.
|
|
103
|
-
* - Get more data from response via readDataOfLength method.
|
|
104
|
-
* - ... continue this cycle until the entire response has been sent.
|
|
105
|
-
*
|
|
106
|
-
* With an asynchronous response, the flow is a little different.
|
|
107
|
-
*
|
|
108
|
-
* First the HTTPResponse is given the opportunity to postpone sending the HTTP response headers.
|
|
109
|
-
* This allows the response to asynchronously execute any code needed to calculate a part of the header.
|
|
110
|
-
* An example might be the response needs to generate some custom header fields,
|
|
111
|
-
* or perhaps the response needs to look for a resource on network-attached storage.
|
|
112
|
-
* Since the network-attached storage may be slow, the response doesn't know whether to send a 200 or 404 yet.
|
|
113
|
-
* In situations such as this, the HTTPResponse simply implements the delayResponseHeaders method and returns YES.
|
|
114
|
-
* After returning YES from this method, the HTTPConnection will wait until the response invokes its
|
|
115
|
-
* responseHasAvailableData method. After this occurs, the HTTPConnection will again query the delayResponseHeaders
|
|
116
|
-
* method to see if the response is ready to send the headers.
|
|
117
|
-
* This cycle will continue until the delayResponseHeaders method returns NO.
|
|
118
|
-
*
|
|
119
|
-
* You should only delay sending the response headers until you have everything you need concerning just the headers.
|
|
120
|
-
* Asynchronously generating the body of the response is not an excuse to delay sending the headers.
|
|
121
|
-
*
|
|
122
|
-
* After the response headers have been sent, the HTTPConnection calls your readDataOfLength method.
|
|
123
|
-
* You may or may not have any available data at this point. If you don't, then simply return nil.
|
|
124
|
-
* You should later invoke HTTPConnection's responseHasAvailableData when you have data to send.
|
|
125
|
-
*
|
|
126
|
-
* You don't have to keep track of when you return nil in the readDataOfLength method, or how many times you've invoked
|
|
127
|
-
* responseHasAvailableData. Just simply call responseHasAvailableData whenever you've generated new data, and
|
|
128
|
-
* return nil in your readDataOfLength whenever you don't have any available data in the requested range.
|
|
129
|
-
* HTTPConnection will automatically detect when it should be requesting new data and will act appropriately.
|
|
130
|
-
*
|
|
131
|
-
* It's important that you also keep in mind that the HTTP server supports range requests.
|
|
132
|
-
* The setOffset method is mandatory, and should not be ignored.
|
|
133
|
-
* Make sure you take into account the offset within the readDataOfLength method.
|
|
134
|
-
* You should also be aware that the HTTPConnection automatically sorts any range requests.
|
|
135
|
-
* So if your setOffset method is called with a value of 100, then you can safely release bytes 0-99.
|
|
136
|
-
*
|
|
137
|
-
* HTTPConnection can also help you keep your memory footprint small.
|
|
138
|
-
* Imagine you're dynamically generating a 10 MB response. You probably don't want to load all this data into
|
|
139
|
-
* RAM, and sit around waiting for HTTPConnection to slowly send it out over the network. All you need to do
|
|
140
|
-
* is pay attention to when HTTPConnection requests more data via readDataOfLength. This is because HTTPConnection
|
|
141
|
-
* will never allow asyncSocket's write queue to get much bigger than READ_CHUNKSIZE bytes. You should
|
|
142
|
-
* consider how you might be able to take advantage of this fact to generate your asynchronous response on demand,
|
|
143
|
-
* while at the same time keeping your memory footprint small, and your application lightning fast.
|
|
144
|
-
*
|
|
145
|
-
* If you don't know the content-length in advanced, you should also implement the isChunked method.
|
|
146
|
-
* This means the response will not include a Content-Length header, and will instead use "Transfer-Encoding: chunked".
|
|
147
|
-
* There's a good chance that if your response is asynchronous and dynamic, it's also chunked.
|
|
148
|
-
* If your response is chunked, you don't need to worry about range requests.
|
|
149
|
-
**/
|
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
|
|
3
|
-
@class GCDAsyncSocket;
|
|
4
|
-
@class WebSocket;
|
|
5
|
-
|
|
6
|
-
#if TARGET_OS_IPHONE
|
|
7
|
-
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 // iPhone 4.0
|
|
8
|
-
#define IMPLEMENTED_PROTOCOLS <NSNetServiceDelegate>
|
|
9
|
-
#else
|
|
10
|
-
#define IMPLEMENTED_PROTOCOLS
|
|
11
|
-
#endif
|
|
12
|
-
#else
|
|
13
|
-
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 // Mac OS X 10.6
|
|
14
|
-
#define IMPLEMENTED_PROTOCOLS <NSNetServiceDelegate>
|
|
15
|
-
#else
|
|
16
|
-
#define IMPLEMENTED_PROTOCOLS
|
|
17
|
-
#endif
|
|
18
|
-
#endif
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
@interface HTTPServer : NSObject IMPLEMENTED_PROTOCOLS
|
|
22
|
-
{
|
|
23
|
-
// Underlying asynchronous TCP/IP socket
|
|
24
|
-
GCDAsyncSocket *asyncSocket;
|
|
25
|
-
|
|
26
|
-
// Dispatch queues
|
|
27
|
-
dispatch_queue_t serverQueue;
|
|
28
|
-
dispatch_queue_t connectionQueue;
|
|
29
|
-
void *IsOnServerQueueKey;
|
|
30
|
-
void *IsOnConnectionQueueKey;
|
|
31
|
-
|
|
32
|
-
// HTTP server configuration
|
|
33
|
-
NSString *documentRoot;
|
|
34
|
-
Class connectionClass;
|
|
35
|
-
NSString *interface;
|
|
36
|
-
UInt16 port;
|
|
37
|
-
|
|
38
|
-
// NSNetService and related variables
|
|
39
|
-
NSNetService *netService;
|
|
40
|
-
NSString *domain;
|
|
41
|
-
NSString *type;
|
|
42
|
-
NSString *name;
|
|
43
|
-
NSString *publishedName;
|
|
44
|
-
NSDictionary *txtRecordDictionary;
|
|
45
|
-
|
|
46
|
-
// Connection management
|
|
47
|
-
NSMutableArray *connections;
|
|
48
|
-
NSLock *connectionsLock;
|
|
49
|
-
|
|
50
|
-
BOOL isRunning;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Specifies the document root to serve files from.
|
|
55
|
-
* For example, if you set this to "/Users/<your_username>/Sites",
|
|
56
|
-
* then it will serve files out of the local Sites directory (including subdirectories).
|
|
57
|
-
*
|
|
58
|
-
* The default value is nil.
|
|
59
|
-
* The default server configuration will not serve any files until this is set.
|
|
60
|
-
*
|
|
61
|
-
* If you change the documentRoot while the server is running,
|
|
62
|
-
* the change will affect future incoming http connections.
|
|
63
|
-
**/
|
|
64
|
-
- (NSString *)documentRoot;
|
|
65
|
-
- (void)setDocumentRoot:(NSString *)value;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* The connection class is the class used to handle incoming HTTP connections.
|
|
69
|
-
*
|
|
70
|
-
* The default value is [HTTPConnection class].
|
|
71
|
-
* You can override HTTPConnection, and then set this to [MyHTTPConnection class].
|
|
72
|
-
*
|
|
73
|
-
* If you change the connectionClass while the server is running,
|
|
74
|
-
* the change will affect future incoming http connections.
|
|
75
|
-
**/
|
|
76
|
-
- (Class)connectionClass;
|
|
77
|
-
- (void)setConnectionClass:(Class)value;
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Set what interface you'd like the server to listen on.
|
|
81
|
-
* By default this is nil, which causes the server to listen on all available interfaces like en1, wifi etc.
|
|
82
|
-
*
|
|
83
|
-
* The interface may be specified by name (e.g. "en1" or "lo0") or by IP address (e.g. "192.168.4.34").
|
|
84
|
-
* You may also use the special strings "localhost" or "loopback" to specify that
|
|
85
|
-
* the socket only accept connections from the local machine.
|
|
86
|
-
**/
|
|
87
|
-
- (NSString *)interface;
|
|
88
|
-
- (void)setInterface:(NSString *)value;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* The port number to run the HTTP server on.
|
|
92
|
-
*
|
|
93
|
-
* The default port number is zero, meaning the server will automatically use any available port.
|
|
94
|
-
* This is the recommended port value, as it avoids possible port conflicts with other applications.
|
|
95
|
-
* Technologies such as Bonjour can be used to allow other applications to automatically discover the port number.
|
|
96
|
-
*
|
|
97
|
-
* Note: As is common on most OS's, you need root privledges to bind to port numbers below 1024.
|
|
98
|
-
*
|
|
99
|
-
* You can change the port property while the server is running, but it won't affect the running server.
|
|
100
|
-
* To actually change the port the server is listening for connections on you'll need to restart the server.
|
|
101
|
-
*
|
|
102
|
-
* The listeningPort method will always return the port number the running server is listening for connections on.
|
|
103
|
-
* If the server is not running this method returns 0.
|
|
104
|
-
**/
|
|
105
|
-
- (UInt16)port;
|
|
106
|
-
- (UInt16)listeningPort;
|
|
107
|
-
- (void)setPort:(UInt16)value;
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Bonjour domain for publishing the service.
|
|
111
|
-
* The default value is "local.".
|
|
112
|
-
*
|
|
113
|
-
* Note: Bonjour publishing requires you set a type.
|
|
114
|
-
*
|
|
115
|
-
* If you change the domain property after the bonjour service has already been published (server already started),
|
|
116
|
-
* you'll need to invoke the republishBonjour method to update the broadcasted bonjour service.
|
|
117
|
-
**/
|
|
118
|
-
- (NSString *)domain;
|
|
119
|
-
- (void)setDomain:(NSString *)value;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Bonjour name for publishing the service.
|
|
123
|
-
* The default value is "".
|
|
124
|
-
*
|
|
125
|
-
* If using an empty string ("") for the service name when registering,
|
|
126
|
-
* the system will automatically use the "Computer Name".
|
|
127
|
-
* Using an empty string will also handle name conflicts
|
|
128
|
-
* by automatically appending a digit to the end of the name.
|
|
129
|
-
*
|
|
130
|
-
* Note: Bonjour publishing requires you set a type.
|
|
131
|
-
*
|
|
132
|
-
* If you change the name after the bonjour service has already been published (server already started),
|
|
133
|
-
* you'll need to invoke the republishBonjour method to update the broadcasted bonjour service.
|
|
134
|
-
*
|
|
135
|
-
* The publishedName method will always return the actual name that was published via the bonjour service.
|
|
136
|
-
* If the service is not running this method returns nil.
|
|
137
|
-
**/
|
|
138
|
-
- (NSString *)name;
|
|
139
|
-
- (NSString *)publishedName;
|
|
140
|
-
- (void)setName:(NSString *)value;
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Bonjour type for publishing the service.
|
|
144
|
-
* The default value is nil.
|
|
145
|
-
* The service will not be published via bonjour unless the type is set.
|
|
146
|
-
*
|
|
147
|
-
* If you wish to publish the service as a traditional HTTP server, you should set the type to be "_http._tcp.".
|
|
148
|
-
*
|
|
149
|
-
* If you change the type after the bonjour service has already been published (server already started),
|
|
150
|
-
* you'll need to invoke the republishBonjour method to update the broadcasted bonjour service.
|
|
151
|
-
**/
|
|
152
|
-
- (NSString *)type;
|
|
153
|
-
- (void)setType:(NSString *)value;
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Republishes the service via bonjour if the server is running.
|
|
157
|
-
* If the service was not previously published, this method will publish it (if the server is running).
|
|
158
|
-
**/
|
|
159
|
-
- (void)republishBonjour;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
*
|
|
163
|
-
**/
|
|
164
|
-
- (NSDictionary *)TXTRecordDictionary;
|
|
165
|
-
- (void)setTXTRecordDictionary:(NSDictionary *)dict;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Attempts to starts the server on the configured port, interface, etc.
|
|
169
|
-
*
|
|
170
|
-
* If an error occurs, this method returns NO and sets the errPtr (if given).
|
|
171
|
-
* Otherwise returns YES on success.
|
|
172
|
-
*
|
|
173
|
-
* Some examples of errors that might occur:
|
|
174
|
-
* - You specified the server listen on a port which is already in use by another application.
|
|
175
|
-
* - You specified the server listen on a port number below 1024, which requires root priviledges.
|
|
176
|
-
*
|
|
177
|
-
* Code Example:
|
|
178
|
-
*
|
|
179
|
-
* NSError *err = nil;
|
|
180
|
-
* if (![httpServer start:&err])
|
|
181
|
-
* {
|
|
182
|
-
* NSLog(@"Error starting http server: %@", err);
|
|
183
|
-
* }
|
|
184
|
-
**/
|
|
185
|
-
- (BOOL)start:(NSError **)errPtr;
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Stops the server, preventing it from accepting any new connections.
|
|
189
|
-
* You may specify whether or not you want to close the existing client connections.
|
|
190
|
-
*
|
|
191
|
-
* The default stop method (with no arguments) will close any existing connections. (It invokes [self stop:NO])
|
|
192
|
-
**/
|
|
193
|
-
- (void)stop;
|
|
194
|
-
- (void)stop:(BOOL)keepExistingConnections;
|
|
195
|
-
|
|
196
|
-
- (BOOL)isRunning;
|
|
197
|
-
|
|
198
|
-
- (NSUInteger)numberOfHTTPConnections;
|
|
199
|
-
|
|
200
|
-
@end
|