mirror of
https://github.com/swisspol/GCDWebServer.git
synced 2026-02-11 00:00:07 +08:00
Compare commits
13 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a0c274807 | ||
|
|
591da12aa3 | ||
|
|
72475429e4 | ||
|
|
01da5969e4 | ||
|
|
46890a0642 | ||
|
|
143ca5b99f | ||
|
|
519866bc03 | ||
|
|
a93cac5ea6 | ||
|
|
43b578677f | ||
|
|
10cbe27e50 | ||
|
|
b1169ce7d1 | ||
|
|
3e5fe3f956 | ||
|
|
a5208bd60f |
@@ -71,8 +71,8 @@
|
||||
|
||||
/**
|
||||
* The GCDWebDAVServer subclass of GCDWebServer implements a class 1 compliant
|
||||
* WebDAV server. It is also partially class 2 compliant (but only when the
|
||||
* client is the OS X WebDAV implementation), so it can work with the OS X Finder.
|
||||
* WebDAV server. It is also partially class 2 compliant but only when the
|
||||
* client is the OS X WebDAV implementation (so it can work with the OS X Finder).
|
||||
*
|
||||
* See the README.md file for more information about the features of GCDWebDAVServer.
|
||||
*/
|
||||
@@ -89,16 +89,15 @@
|
||||
@property(nonatomic, assign) id<GCDWebDAVServerDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Restricts which files should be listed and allowed to be uploaded, downloaded,
|
||||
* moved, copied or deleted depending on their extensions.
|
||||
* Sets which files are allowed to be operated on depending on their extension.
|
||||
*
|
||||
* The default value is nil i.e. all file extensions are allowed.
|
||||
*/
|
||||
@property(nonatomic, copy) NSArray* allowedFileExtensions;
|
||||
|
||||
/**
|
||||
* Sets if files and directories whose name start with a period should be
|
||||
* listed and allowed to be uploaded, downloaded, moved, copied or deleted.
|
||||
* Sets if files and directories whose name start with a period are allowed to
|
||||
* be operated on.
|
||||
*
|
||||
* The default value is NO.
|
||||
*/
|
||||
@@ -119,7 +118,7 @@
|
||||
@interface GCDWebDAVServer (Subclassing)
|
||||
|
||||
/**
|
||||
* This method is called to check if a file is allowed to be uploaded.
|
||||
* This method is called to check if a file upload is allowed to complete.
|
||||
* The uploaded file is available for inspection at "tempPath".
|
||||
*
|
||||
* The default implementation returns YES.
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'GCDWebServer'
|
||||
s.version = '2.3'
|
||||
s.version = '2.3.2'
|
||||
s.author = { 'Pierre-Olivier Latour' => 'info@pol-online.net' }
|
||||
s.license = { :type => 'BSD', :file => 'LICENSE' }
|
||||
s.homepage = 'https://github.com/swisspol/GCDWebServer'
|
||||
@@ -22,6 +22,7 @@ Pod::Spec.new do |s|
|
||||
|
||||
s.subspec 'Core' do |cs|
|
||||
cs.source_files = 'GCDWebServer/**/*.{h,m}'
|
||||
cs.private_header_files = "GCDWebServer/Core/GCDWebServerPrivate.h"
|
||||
cs.requires_arc = true
|
||||
cs.ios.library = 'z'
|
||||
cs.ios.frameworks = 'MobileCoreServices', 'CFNetwork'
|
||||
|
||||
@@ -59,7 +59,7 @@ typedef GCDWebServerRequest* (^GCDWebServerMatchBlock)(NSString* requestMethod,
|
||||
|
||||
/**
|
||||
* The GCDWebServerProcessBlock is called after the HTTP request has been fully
|
||||
* received (i.e. the entire HTTP body has been read). THe block is passed the
|
||||
* received (i.e. the entire HTTP body has been read). The block is passed the
|
||||
* GCDWebServerRequest created at the previous step by the GCDWebServerMatchBlock.
|
||||
*
|
||||
* The block must return a GCDWebServerResponse or nil on error, which will
|
||||
@@ -72,14 +72,14 @@ typedef GCDWebServerResponse* (^GCDWebServerProcessBlock)(GCDWebServerRequest* r
|
||||
/**
|
||||
* The port used by the GCDWebServer (NSNumber / NSUInteger).
|
||||
*
|
||||
* Default value is 0 i.e. let the OS pick a random port.
|
||||
* The default value is 0 i.e. let the OS pick a random port.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_Port;
|
||||
|
||||
/**
|
||||
* The Bonjour name used by the GCDWebServer (NSString).
|
||||
*
|
||||
* Default value is an empty string i.e. use the computer / device name.
|
||||
* The default value is an empty string i.e. use the computer / device name.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_BonjourName;
|
||||
|
||||
@@ -87,14 +87,14 @@ extern NSString* const GCDWebServerOption_BonjourName;
|
||||
* The maximum number of incoming HTTP requests that can be queued waiting to
|
||||
* be handled before new ones are dropped (NSNumber / NSUInteger).
|
||||
*
|
||||
* Default value is 16.
|
||||
* The default value is 16.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_MaxPendingConnections;
|
||||
|
||||
/**
|
||||
* The value for "Server" HTTP header used by the GCDWebServer (NSString).
|
||||
*
|
||||
* Default value is the GCDWebServer class name.
|
||||
* The default value is the GCDWebServer class name.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_ServerName;
|
||||
|
||||
@@ -102,14 +102,14 @@ extern NSString* const GCDWebServerOption_ServerName;
|
||||
* The authentication method used by the GCDWebServer
|
||||
* (one of "GCDWebServerAuthenticationMethod_...").
|
||||
*
|
||||
* Default value is nil i.e. authentication disabled.
|
||||
* The default value is nil i.e. authentication is disabled.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_AuthenticationMethod;
|
||||
|
||||
/**
|
||||
* The authentication realm used by the GCDWebServer (NSString).
|
||||
*
|
||||
* Default value is the same as GCDWebServerOption_ServerName.
|
||||
* The default value is the same as the GCDWebServerOption_ServerName option.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_AuthenticationRealm;
|
||||
|
||||
@@ -117,7 +117,7 @@ extern NSString* const GCDWebServerOption_AuthenticationRealm;
|
||||
* The authentication accounts used by the GCDWebServer
|
||||
* (NSDictionary of username / password pairs).
|
||||
*
|
||||
* Default value is nil i.e. no accounts.
|
||||
* The default value is nil i.e. no accounts.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_AuthenticationAccounts;
|
||||
|
||||
@@ -125,7 +125,7 @@ extern NSString* const GCDWebServerOption_AuthenticationAccounts;
|
||||
* The class used by the GCDWebServer when instantiating GCDWebServerConnection
|
||||
* (subclass of GCDWebServerConnection).
|
||||
*
|
||||
* Default value is GCDWebServerConnection class.
|
||||
* The default value is the GCDWebServerConnection class.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_ConnectionClass;
|
||||
|
||||
@@ -133,7 +133,7 @@ extern NSString* const GCDWebServerOption_ConnectionClass;
|
||||
* Allow the GCDWebServer to pretend "HEAD" requests are actually "GET" ones
|
||||
* and automatically discard the HTTP body of the response (NSNumber / BOOL).
|
||||
*
|
||||
* Default value is YES.
|
||||
* The default value is YES.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_AutomaticallyMapHEADToGET;
|
||||
|
||||
@@ -142,7 +142,7 @@ extern NSString* const GCDWebServerOption_AutomaticallyMapHEADToGET;
|
||||
* coalesce calls to -webServerDidConnect: and -webServerDidDisconnect:
|
||||
* (NSNumber / double). Coalescing will be disabled if the interval is <= 0.0.
|
||||
*
|
||||
* Default value is 1.0 second.
|
||||
* The default value is 1.0 second.
|
||||
*/
|
||||
extern NSString* const GCDWebServerOption_ConnectedStateCoalescingInterval;
|
||||
|
||||
@@ -156,7 +156,7 @@ extern NSString* const GCDWebServerOption_ConnectedStateCoalescingInterval;
|
||||
*
|
||||
* See the README.md file for more information about this option.
|
||||
*
|
||||
* Default value is YES.
|
||||
* The default value is YES.
|
||||
*
|
||||
* @warning The running property will be NO while the GCDWebServer is suspended.
|
||||
*/
|
||||
@@ -167,7 +167,8 @@ extern NSString* const GCDWebServerOption_AutomaticallySuspendInBackground;
|
||||
/**
|
||||
* HTTP Basic Authentication scheme (see https://tools.ietf.org/html/rfc2617).
|
||||
*
|
||||
* @warning Use of this method is not recommended as the passwords are sent in clear.
|
||||
* @warning Use of this authentication scheme is not recommended as the
|
||||
* passwords are sent in clear.
|
||||
*/
|
||||
extern NSString* const GCDWebServerAuthenticationMethod_Basic;
|
||||
|
||||
@@ -187,7 +188,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
@optional
|
||||
|
||||
/**
|
||||
* This method is called after the server has succesfully started.
|
||||
* This method is called after the server has successfully started.
|
||||
*/
|
||||
- (void)webServerDidStart:(GCDWebServer*)server;
|
||||
|
||||
@@ -199,9 +200,11 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
|
||||
/**
|
||||
* This method is called when the first GCDWebServerConnection is opened by the
|
||||
* server to serve a series of HTTP requests. A series is ongoing as long as
|
||||
* new HTTP requests keep coming (and new GCDWebServerConnection instances keep
|
||||
* being opened), before the last HTTP request has been responded to (and the
|
||||
* server to serve a series of HTTP requests.
|
||||
*
|
||||
* A series of HTTP requests is considered ongoing as long as new HTTP requests
|
||||
* keep coming (and new GCDWebServerConnection instances keep being opened),
|
||||
* until before the last HTTP request has been responded to (and the
|
||||
* corresponding last GCDWebServerConnection closed).
|
||||
*/
|
||||
- (void)webServerDidConnect:(GCDWebServer*)server;
|
||||
@@ -226,8 +229,9 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
@end
|
||||
|
||||
/**
|
||||
* The GCDWebServer class manages the socket that listens for HTTP requests and
|
||||
* the list of handlers used to respond to them.
|
||||
* The GCDWebServer class listens for incoming HTTP requests on a given port,
|
||||
* then passes each one to a "handler" capable of generating an HTTP response
|
||||
* for it, which is then sent back to the client.
|
||||
*
|
||||
* See the README.md file for more information about the architecture of GCDWebServer.
|
||||
*/
|
||||
@@ -239,7 +243,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
@property(nonatomic, assign) id<GCDWebServerDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Indicates if the server is currently running.
|
||||
* Returns YES if the server is currently running.
|
||||
*/
|
||||
@property(nonatomic, readonly, getter=isRunning) BOOL running;
|
||||
|
||||
@@ -251,7 +255,7 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
@property(nonatomic, readonly) NSUInteger port;
|
||||
|
||||
/**
|
||||
* Returns the Bonjour name in used by the server.
|
||||
* Returns the Bonjour name used by the server.
|
||||
*
|
||||
* @warning This property is only valid if the server is running and Bonjour
|
||||
* registration has successfully completed, which can take up to a few seconds.
|
||||
@@ -265,37 +269,21 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
|
||||
/**
|
||||
* Adds a handler to the server to handle incoming HTTP requests.
|
||||
* Handlers are called in a LIFO queue, so the latest added handler overrides
|
||||
* any previously added ones.
|
||||
*
|
||||
* @warning Addling handlers while the GCDWebServer is running is not allowed.
|
||||
* Handlers are called in a LIFO queue, so if multiple handlers can potentially
|
||||
* respond to a given request, the latest added one wins.
|
||||
*
|
||||
* @warning Addling handlers while the server is running is not allowed.
|
||||
*/
|
||||
- (void)addHandlerWithMatchBlock:(GCDWebServerMatchBlock)matchBlock processBlock:(GCDWebServerProcessBlock)processBlock;
|
||||
|
||||
/**
|
||||
* Removes all handlers previously added to the server.
|
||||
*
|
||||
* @warning Removing handlers while the GCDWebServer is running is not allowed.
|
||||
* @warning Removing handlers while the server is running is not allowed.
|
||||
*/
|
||||
- (void)removeAllHandlers;
|
||||
|
||||
/**
|
||||
* Starts the server on port 8080 (OS X & iOS Simulator) or port 80 (iOS)
|
||||
* using the computer / device name for as the Bonjour name.
|
||||
*
|
||||
* Returns NO if the server failed to start.
|
||||
*/
|
||||
- (BOOL)start;
|
||||
|
||||
/**
|
||||
* Starts the server on a given port and with a specific Bonjour name.
|
||||
* Pass a nil Bonjour name to disable Bonjour entirely or an empty string to
|
||||
* use the computer / device name.
|
||||
*
|
||||
* Returns NO if the server failed to start.
|
||||
*/
|
||||
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name;
|
||||
|
||||
/**
|
||||
* Starts the server with explicit options. This method is the designated way
|
||||
* to start the server.
|
||||
@@ -308,8 +296,8 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
* Stops the server and prevents it to accepts new HTTP requests.
|
||||
*
|
||||
* @warning Stopping the server does not abort GCDWebServerConnection instances
|
||||
* handling already received HTTP requests. These connections will continue to
|
||||
* execute until the corresponding requests and responses are completed.
|
||||
* currently handling already received HTTP requests. These connections will
|
||||
* continue to execute normally until completion.
|
||||
*/
|
||||
- (void)stop;
|
||||
|
||||
@@ -332,6 +320,23 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
|
||||
*/
|
||||
@property(nonatomic, readonly) NSURL* bonjourServerURL;
|
||||
|
||||
/**
|
||||
* Starts the server on port 8080 (OS X & iOS Simulator) or port 80 (iOS)
|
||||
* using the computer / device name for as the Bonjour name.
|
||||
*
|
||||
* Returns NO if the server failed to start.
|
||||
*/
|
||||
- (BOOL)start;
|
||||
|
||||
/**
|
||||
* Starts the server on a given port and with a specific Bonjour name.
|
||||
* Pass a nil Bonjour name to disable Bonjour entirely or an empty string to
|
||||
* use the computer / device name.
|
||||
*
|
||||
* Returns NO if the server failed to start.
|
||||
*/
|
||||
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name;
|
||||
|
||||
#if !TARGET_OS_IPHONE
|
||||
|
||||
/**
|
||||
|
||||
@@ -528,17 +528,6 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL)start {
|
||||
return [self startWithPort:kDefaultPort bonjourName:@""];
|
||||
}
|
||||
|
||||
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name {
|
||||
NSMutableDictionary* options = [NSMutableDictionary dictionary];
|
||||
[options setObject:[NSNumber numberWithInteger:port] forKey:GCDWebServerOption_Port];
|
||||
[options setValue:name forKey:GCDWebServerOption_BonjourName];
|
||||
return [self startWithOptions:options];
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
- (void)_didEnterBackground:(NSNotification*)notification {
|
||||
@@ -640,6 +629,17 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)start {
|
||||
return [self startWithPort:kDefaultPort bonjourName:@""];
|
||||
}
|
||||
|
||||
- (BOOL)startWithPort:(NSUInteger)port bonjourName:(NSString*)name {
|
||||
NSMutableDictionary* options = [NSMutableDictionary dictionary];
|
||||
[options setObject:[NSNumber numberWithInteger:port] forKey:GCDWebServerOption_Port];
|
||||
[options setValue:name forKey:GCDWebServerOption_BonjourName];
|
||||
return [self startWithOptions:options];
|
||||
}
|
||||
|
||||
#if !TARGET_OS_IPHONE
|
||||
|
||||
- (BOOL)runWithPort:(NSUInteger)port bonjourName:(NSString*)name {
|
||||
@@ -846,37 +846,29 @@ static inline NSString* _EncodeBase64(NSString* string) {
|
||||
- (void)logVerbose:(NSString*)format, ... {
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
|
||||
LOG_VERBOSE(@"%@", ARC_AUTORELEASE([[NSString alloc] initWithFormat:format arguments:arguments]));
|
||||
va_end(arguments);
|
||||
LOG_VERBOSE(@"%@", message);
|
||||
ARC_RELEASE(message);
|
||||
}
|
||||
|
||||
- (void)logInfo:(NSString*)format, ... {
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
|
||||
LOG_INFO(@"%@", ARC_AUTORELEASE([[NSString alloc] initWithFormat:format arguments:arguments]));
|
||||
va_end(arguments);
|
||||
LOG_INFO(@"%@", message);
|
||||
ARC_RELEASE(message);
|
||||
}
|
||||
|
||||
- (void)logWarning:(NSString*)format, ... {
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
|
||||
LOG_WARNING(@"%@", ARC_AUTORELEASE([[NSString alloc] initWithFormat:format arguments:arguments]));
|
||||
va_end(arguments);
|
||||
LOG_WARNING(@"%@", message);
|
||||
ARC_RELEASE(message);
|
||||
}
|
||||
|
||||
- (void)logError:(NSString*)format, ... {
|
||||
va_list arguments;
|
||||
va_start(arguments, format);
|
||||
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
|
||||
LOG_ERROR(@"%@", ARC_AUTORELEASE([[NSString alloc] initWithFormat:format arguments:arguments]));
|
||||
va_end(arguments);
|
||||
LOG_ERROR(@"%@", message);
|
||||
ARC_RELEASE(message);
|
||||
}
|
||||
|
||||
- (void)logException:(NSException*)exception {
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
* subclass it to override some hooks. Use the GCDWebServerOption_ConnectionClass
|
||||
* option for GCDWebServer to install your custom subclass.
|
||||
*
|
||||
* @warning The GCDWebServerConnection retains the GCDWebServer
|
||||
* until the connection is closed.
|
||||
* @warning The GCDWebServerConnection retains the GCDWebServer until the
|
||||
* connection is closed.
|
||||
*/
|
||||
@interface GCDWebServerConnection : NSObject
|
||||
|
||||
@@ -95,6 +95,7 @@
|
||||
|
||||
/**
|
||||
* This method is called when the connection is opened.
|
||||
*
|
||||
* Return NO to reject the connection e.g. after validating the local
|
||||
* or remote address.
|
||||
*/
|
||||
@@ -103,17 +104,21 @@
|
||||
/**
|
||||
* This method is called whenever data has been received
|
||||
* from the remote peer (i.e. client).
|
||||
*
|
||||
* @warning Do not attempt to modify this data.
|
||||
*/
|
||||
- (void)didReadBytes:(const void*)bytes length:(NSUInteger)length;
|
||||
|
||||
/**
|
||||
* This method is called whenever data has been sent
|
||||
* to the remote peer (i.e. client).
|
||||
*
|
||||
* @warning Do not attempt to modify this data.
|
||||
*/
|
||||
- (void)didWriteBytes:(const void*)bytes length:(NSUInteger)length;
|
||||
|
||||
/**
|
||||
* Assuming a valid request was received, this method is called before
|
||||
* Assuming a valid HTTP request was received, this method is called before
|
||||
* the request is processed.
|
||||
*
|
||||
* Return a non-nil GCDWebServerResponse to bypass the request processing entirely.
|
||||
@@ -124,18 +129,18 @@
|
||||
- (GCDWebServerResponse*)preflightRequest:(GCDWebServerRequest*)request;
|
||||
|
||||
/**
|
||||
* Assuming a valid request was received and -preflightRequest: returned nil,
|
||||
* Assuming a valid HTTP request was received and -preflightRequest: returned nil,
|
||||
* this method is called to process the request.
|
||||
*/
|
||||
- (GCDWebServerResponse*)processRequest:(GCDWebServerRequest*)request withBlock:(GCDWebServerProcessBlock)block;
|
||||
|
||||
/**
|
||||
* Assuming a valid request was received and either -preflightRequest:
|
||||
* Assuming a valid HTTP request was received and either -preflightRequest:
|
||||
* or -processRequest:withBlock: returned a non-nil GCDWebServerResponse,
|
||||
* this method is called to override the response.
|
||||
*
|
||||
* You can either modify the current response and return it, or return a
|
||||
* completely different one.
|
||||
* completely new one.
|
||||
*
|
||||
* The default implementation replaces any response matching the "ETag" or
|
||||
* "Last-Modified-Date" header of the request by a barebone "Not-Modified" (304)
|
||||
@@ -145,7 +150,7 @@
|
||||
|
||||
/**
|
||||
* This method is called if any error happens while validing or processing
|
||||
* the request or no GCDWebServerResponse is generated.
|
||||
* the request or if no GCDWebServerResponse was generated during processing.
|
||||
*
|
||||
* @warning If the request was invalid (e.g. the HTTP headers were malformed),
|
||||
* the "request" argument will be nil.
|
||||
|
||||
@@ -675,11 +675,11 @@ static NSString* _StringFromAddressData(NSData* data) {
|
||||
_connectionIndex = OSAtomicIncrement32(&_connectionCounter);
|
||||
|
||||
_requestPath = ARC_RETAIN([NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]);
|
||||
_requestFD = open([_requestPath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY);
|
||||
_requestFD = open([_requestPath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
DCHECK(_requestFD > 0);
|
||||
|
||||
_responsePath = ARC_RETAIN([NSTemporaryDirectory() stringByAppendingPathComponent:[[NSProcessInfo processInfo] globallyUniqueString]]);
|
||||
_responseFD = open([_responsePath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY);
|
||||
_responseFD = open([_responsePath fileSystemRepresentation], O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
|
||||
DCHECK(_responseFD > 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -50,17 +50,18 @@ NSString* GCDWebServerEscapeURLString(NSString* string);
|
||||
NSString* GCDWebServerUnescapeURLString(NSString* string);
|
||||
|
||||
/**
|
||||
* Extracts the unescaped names and values
|
||||
* from a "application/x-www-form-urlencoded" form.
|
||||
* Extracts the unescaped names and values from an
|
||||
* "application/x-www-form-urlencoded" form.
|
||||
* http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1
|
||||
*/
|
||||
NSDictionary* GCDWebServerParseURLEncodedForm(NSString* form);
|
||||
|
||||
/**
|
||||
* OS X: Returns the IPv4 address as a dotted string of the primary connected
|
||||
* service or nil if not available.
|
||||
* iOS: Returns the IPv4 address as a dotted string of the WiFi interface
|
||||
* if connected or nil otherwise.
|
||||
* On OS X, returns the IPv4 address as a dotted string of the primary connected
|
||||
* service or nil if not available.
|
||||
*
|
||||
* On iOS, returns the IPv4 address as a dotted string of the WiFi interface
|
||||
* if connected or nil otherwise.
|
||||
*/
|
||||
NSString* GCDWebServerGetPrimaryIPv4Address();
|
||||
|
||||
@@ -76,7 +77,7 @@ NSString* GCDWebServerFormatRFC822(NSDate* date);
|
||||
* https://tools.ietf.org/html/rfc822#section-5
|
||||
* https://tools.ietf.org/html/rfc1123#section-5.2.14
|
||||
*
|
||||
* @warning Timezones are not supported at this time.
|
||||
* @warning Timezones other than GMT are not supported by this function.
|
||||
*/
|
||||
NSDate* GCDWebServerParseRFC822(NSString* string);
|
||||
|
||||
@@ -91,7 +92,7 @@ NSString* GCDWebServerFormatISO8601(NSDate* date);
|
||||
* http://tools.ietf.org/html/rfc3339#section-5.6
|
||||
*
|
||||
* @warning Only "calendar" variant is supported at this time and timezones
|
||||
* are not supported either.
|
||||
* other than GMT are not supported either.
|
||||
*/
|
||||
NSDate* GCDWebServerParseISO8601(NSString* string);
|
||||
|
||||
|
||||
@@ -106,8 +106,8 @@
|
||||
@property(nonatomic, readonly) NSDictionary* query;
|
||||
|
||||
/**
|
||||
* Returns the content type for the body of the request (this property is
|
||||
* automatically parsed from the HTTP headers).
|
||||
* Returns the content type for the body of the request parsed from the
|
||||
* "Content-Type" header.
|
||||
*
|
||||
* This property will be nil if the request has no body or set to
|
||||
* "application/octet-stream" if a body is present but there was no
|
||||
@@ -116,8 +116,8 @@
|
||||
@property(nonatomic, readonly) NSString* contentType;
|
||||
|
||||
/**
|
||||
* Returns the content length for the body of the request (this property is
|
||||
* automatically parsed from the HTTP headers).
|
||||
* Returns the content length for the body of the request parsed from the
|
||||
* "Content-Length" header.
|
||||
*
|
||||
* This property will be set to "NSNotFound" if the request has no body or
|
||||
* if there is a body but no "Content-Length" header, typically because
|
||||
@@ -138,13 +138,13 @@
|
||||
/**
|
||||
* Returns the parsed "Range" header or (NSNotFound, 0) if absent or malformed.
|
||||
* The range will be set to (offset, length) if expressed from the beginning
|
||||
* of the body, or (NSNotFound, -length) if expressed from the end of the body.
|
||||
* of the entity body, or (NSNotFound, -length) if expressed from its end.
|
||||
*/
|
||||
@property(nonatomic, readonly) NSRange byteRange;
|
||||
|
||||
/**
|
||||
* Indicates if the client supports gzip content encoding (this property is
|
||||
* automatically parsed from the HTTP headers).
|
||||
* Returns YES if the client supports gzip content encoding according to the
|
||||
* "Accept-Encoding" header.
|
||||
*/
|
||||
@property(nonatomic, readonly) BOOL acceptsGzipContentEncoding;
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
/**
|
||||
* This protocol is used by the GCDWebServerConnection to communicate with
|
||||
* the GCDWebServerResponse and read the sent HTTP body data.
|
||||
* the GCDWebServerResponse and read the HTTP body data to send.
|
||||
*
|
||||
* Note that multiple GCDWebServerBodyReader objects can be chained together
|
||||
* internally e.g. to automatically apply gzip encoding to the content before
|
||||
@@ -48,7 +48,7 @@
|
||||
- (BOOL)open:(NSError**)error;
|
||||
|
||||
/**
|
||||
* This method is called whenever body data is ready to be sent.
|
||||
* This method is called whenever body data is sent.
|
||||
*
|
||||
* It should return a non-empty NSData if there is body data available,
|
||||
* or an empty NSData there is no more body data, or nil on error and set
|
||||
@@ -67,7 +67,7 @@
|
||||
* The GCDWebServerResponse class is used to wrap a single HTTP response.
|
||||
* It is instantiated by the handler of the GCDWebServer that handled the request.
|
||||
* If a body is present, the methods from the GCDWebServerBodyReader protocol
|
||||
* will be called by the GCDWebServerConnection to retrieve it.
|
||||
* will be called by the GCDWebServerConnection to send it.
|
||||
*
|
||||
* The default implementation of the GCDWebServerBodyReader protocol
|
||||
* on the class simply returns an empty body.
|
||||
@@ -78,16 +78,17 @@
|
||||
|
||||
/**
|
||||
* Sets the content type for the body of the response.
|
||||
* This property must be set if a body is present.
|
||||
*
|
||||
* The default value is nil i.e. the response has no body.
|
||||
*
|
||||
* @warning This property must be set if a body is present.
|
||||
*/
|
||||
@property(nonatomic, copy) NSString* contentType;
|
||||
|
||||
/**
|
||||
* Sets the content length for the body of the response. If a body is present
|
||||
* but this property is set to "NSNotFound", this means the length of the body
|
||||
* cannot be known ahead of time and chunked transfer encoding will be
|
||||
* cannot be known ahead of time. Chunked transfer encoding will be
|
||||
* automatically enabled by the GCDWebServerConnection to comply with HTTP/1.1
|
||||
* specifications.
|
||||
*
|
||||
@@ -152,7 +153,7 @@
|
||||
* Pass a nil value to remove an additional header.
|
||||
*
|
||||
* @warning Do not attempt to override the primary headers used
|
||||
* by GCDWebServerResponse e.g. "Content-Type" or "ETag".
|
||||
* by GCDWebServerResponse like "Content-Type", "ETag", etc...
|
||||
*/
|
||||
- (void)setValue:(NSString*)value forAdditionalHeader:(NSString*)header;
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
/**
|
||||
* Initializes a data response from text encoded using UTF-8.
|
||||
*/
|
||||
- (instancetype)initWithText:(NSString*)text; // Encodes using UTF-8
|
||||
- (instancetype)initWithText:(NSString*)text;
|
||||
|
||||
/**
|
||||
* Initializes a data response from HTML encoded using UTF-8.
|
||||
@@ -87,6 +87,7 @@
|
||||
|
||||
/**
|
||||
* Initializes a data response from an HTML template encoded using UTF-8.
|
||||
*
|
||||
* All occurences of "%variable%" within the HTML template are replaced with
|
||||
* their corresponding values.
|
||||
*/
|
||||
|
||||
@@ -46,13 +46,13 @@
|
||||
|
||||
/**
|
||||
* Creates a client error response with the corresponding HTTP status code
|
||||
* and an optional underlying NSError.
|
||||
* and an underlying NSError.
|
||||
*/
|
||||
+ (instancetype)responseWithClientError:(GCDWebServerClientErrorHTTPStatusCode)errorCode underlyingError:(NSError*)underlyingError message:(NSString*)format, ... NS_FORMAT_FUNCTION(3,4);
|
||||
|
||||
/**
|
||||
* Creates a server error response with the corresponding HTTP status code
|
||||
* and an optional underlying NSError.
|
||||
* and an underlying NSError.
|
||||
*/
|
||||
+ (instancetype)responseWithServerError:(GCDWebServerServerErrorHTTPStatusCode)errorCode underlyingError:(NSError*)underlyingError message:(NSString*)format, ... NS_FORMAT_FUNCTION(3,4);
|
||||
|
||||
@@ -68,13 +68,13 @@
|
||||
|
||||
/**
|
||||
* Initializes a client error response with the corresponding HTTP status code
|
||||
* and an optional underlying NSError.
|
||||
* and an underlying NSError.
|
||||
*/
|
||||
- (instancetype)initWithClientError:(GCDWebServerClientErrorHTTPStatusCode)errorCode underlyingError:(NSError*)underlyingError message:(NSString*)format, ... NS_FORMAT_FUNCTION(3,4);
|
||||
|
||||
/**
|
||||
* Initializes a server error response with the corresponding HTTP status code
|
||||
* and an optional underlying NSError.
|
||||
* and an underlying NSError.
|
||||
*/
|
||||
- (instancetype)initWithServerError:(GCDWebServerServerErrorHTTPStatusCode)errorCode underlyingError:(NSError*)underlyingError message:(NSString*)format, ... NS_FORMAT_FUNCTION(3,4);
|
||||
|
||||
|
||||
@@ -30,18 +30,21 @@
|
||||
/**
|
||||
* The GCDWebServerFileResponse subclass of GCDWebServerResponse reads the body
|
||||
* of the HTTP response from a file on disk.
|
||||
*
|
||||
* It will automatically set the contentType, lastModifiedDate and eTag
|
||||
* properties of the GCDWebServerResponse according to the file extension and
|
||||
* metadata.
|
||||
*/
|
||||
@interface GCDWebServerFileResponse : GCDWebServerResponse
|
||||
|
||||
/**
|
||||
* Creates a response with the contents of a file and the content type
|
||||
* automatically set from the file extension.
|
||||
* Creates a response with the contents of a file.
|
||||
*/
|
||||
+ (instancetype)responseWithFile:(NSString*)path;
|
||||
|
||||
/**
|
||||
* Creates a response like +responseWithFile: but sets the "Content-Disposition"
|
||||
* HTTP header appropriately for a download if the "attachment" argument is YES.
|
||||
* Creates a response like +responseWithFile: and sets the "Content-Disposition"
|
||||
* HTTP header for a download if the "attachment" argument is YES.
|
||||
*/
|
||||
+ (instancetype)responseWithFile:(NSString*)path isAttachment:(BOOL)attachment;
|
||||
|
||||
@@ -54,21 +57,21 @@
|
||||
+ (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range;
|
||||
|
||||
/**
|
||||
* Creates a response like +responseWithFile:byteRange: but also sets the
|
||||
* "Content-Disposition" HTTP header appropriately for a download if the
|
||||
* "attachment" argument is YES.
|
||||
* Creates a response like +responseWithFile:byteRange: and sets the
|
||||
* "Content-Disposition" HTTP header for a download if the "attachment"
|
||||
* argument is YES.
|
||||
*/
|
||||
+ (instancetype)responseWithFile:(NSString*)path byteRange:(NSRange)range isAttachment:(BOOL)attachment;
|
||||
|
||||
/**
|
||||
* Initializes a response with the contents of a file and the content type
|
||||
* automatically set from the file extension.
|
||||
* Initializes a response with the contents of a file.
|
||||
*/
|
||||
- (instancetype)initWithFile:(NSString*)path;
|
||||
|
||||
/**
|
||||
* Initializes a response like -initWithFile: but sets the "Content-Disposition"
|
||||
* HTTP header appropriately for a download if the "attachment" argument is YES.
|
||||
* Initializes a response like +responseWithFile: and sets the
|
||||
* "Content-Disposition" HTTP header for a download if the "attachment"
|
||||
* argument is YES.
|
||||
*/
|
||||
- (instancetype)initWithFile:(NSString*)path isAttachment:(BOOL)attachment;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
@class GCDWebUploader;
|
||||
|
||||
/**
|
||||
* Delegate methods for GCDWebUploaderDelegate.
|
||||
* Delegate methods for GCDWebUploader.
|
||||
*
|
||||
* @warning These methods are always called on the main thread in a serialized way.
|
||||
*/
|
||||
@@ -70,37 +70,39 @@
|
||||
* or directories.
|
||||
*
|
||||
* See the README.md file for more information about the features of GCDWebUploader.
|
||||
*
|
||||
* @warning For GCDWebUploader to work, "GCDWebUploader.bundle" must be added
|
||||
* to the resources of the Xcode target.
|
||||
*/
|
||||
@interface GCDWebUploader : GCDWebServer
|
||||
|
||||
/**
|
||||
* Returns the upload directory as specified when the server was initialized.
|
||||
* Returns the upload directory as specified when the uploader was initialized.
|
||||
*/
|
||||
@property(nonatomic, readonly) NSString* uploadDirectory;
|
||||
|
||||
/**
|
||||
* Sets the delegate for the server.
|
||||
* Sets the delegate for the uploader.
|
||||
*/
|
||||
@property(nonatomic, assign) id<GCDWebUploaderDelegate> delegate;
|
||||
|
||||
/**
|
||||
* Restricts which files should be listed and allowed to be uploaded, downloaded,
|
||||
* moved or deleted depending on their extensions.
|
||||
* Sets which files are allowed to be operated on depending on their extension.
|
||||
*
|
||||
* The default value is nil i.e. all file extensions are allowed.
|
||||
*/
|
||||
@property(nonatomic, copy) NSArray* allowedFileExtensions;
|
||||
|
||||
/**
|
||||
* Sets if files and directories whose name start with a period should be
|
||||
* listed and allowed to be uploaded, downloaded, moved or deleted.
|
||||
* Sets if files and directories whose name start with a period are allowed to
|
||||
* be operated on.
|
||||
*
|
||||
* The default value is NO.
|
||||
*/
|
||||
@property(nonatomic) BOOL allowHiddenItems;
|
||||
|
||||
/**
|
||||
* Sets the title for the uploader interface.
|
||||
* Sets the title for the uploader web interface.
|
||||
*
|
||||
* The default value is the application name.
|
||||
*
|
||||
@@ -110,7 +112,7 @@
|
||||
@property(nonatomic, copy) NSString* title;
|
||||
|
||||
/**
|
||||
* Sets the header for the uploader interface.
|
||||
* Sets the header for the uploader web interface.
|
||||
*
|
||||
* The default value is the same as the title property.
|
||||
*
|
||||
@@ -120,7 +122,7 @@
|
||||
@property(nonatomic, copy) NSString* header;
|
||||
|
||||
/**
|
||||
* Sets the prologue for the uploader interface.
|
||||
* Sets the prologue for the uploader web interface.
|
||||
*
|
||||
* The default value is a short help text.
|
||||
*
|
||||
@@ -130,7 +132,7 @@
|
||||
@property(nonatomic, copy) NSString* prologue;
|
||||
|
||||
/**
|
||||
* Sets the epilogue for the uploader interface.
|
||||
* Sets the epilogue for the uploader web interface.
|
||||
*
|
||||
* The default value is nil i.e. no epilogue.
|
||||
*
|
||||
@@ -140,7 +142,7 @@
|
||||
@property(nonatomic, copy) NSString* epilogue;
|
||||
|
||||
/**
|
||||
* Sets the footer for the uploader interface.
|
||||
* Sets the footer for the uploader web interface.
|
||||
*
|
||||
* The default value is the application name and version.
|
||||
*
|
||||
@@ -164,7 +166,7 @@
|
||||
@interface GCDWebUploader (Subclassing)
|
||||
|
||||
/**
|
||||
* This method is called to check if a file is allowed to be uploaded.
|
||||
* This method is called to check if a file upload is allowed to complete.
|
||||
* The uploaded file is available for inspection at "tempPath".
|
||||
*
|
||||
* The default implementation returns YES.
|
||||
|
||||
@@ -169,7 +169,6 @@ int main(int argc, const char* argv[]) {
|
||||
GCDWebServer* webServer = [[GCDWebServer alloc] init];
|
||||
[webServer addGETHandlerForBasePath:@"/" directoryPath:NSHomeDirectory() indexFilename:nil cacheAge:3600 allowRangeRequests:YES];
|
||||
[webServer runWithPort:8080];
|
||||
[webServer release]; // Remove if using ARC
|
||||
|
||||
}
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user