15 Commits
3.5.2 ... 3.5.3

Author SHA1 Message Date
Pierre-Olivier Latour
acdb5c9262 Bumped version 2019-08-09 06:26:10 -07:00
Pierre-Olivier Latour
f54cc20bd6 Formatted source 2019-08-09 06:26:10 -07:00
Pierre-Olivier Latour
02738433bf Enforce hidden and extensions restrictions when moving and copying files in uploaders
Fixes #433
2019-08-09 06:25:37 -07:00
Pierre-Olivier Latour
c9563db0a6 Fixed GCDWebServerBodyReaderCompletionBlock not allowing null data
Fixed #434
2019-08-09 06:16:08 -07:00
Pierre-Olivier Latour
cd1eea5612 Updated to Swift 5 2019-08-09 06:08:56 -07:00
Pierre-Olivier Latour
f7c1c4eff5 Updated to Xcode 10.3 2019-08-09 06:05:19 -07:00
Pierre-Olivier Latour
fdc0feddf0 Merge pull request #426 from beazlr02/patch-1
Update swebServer.swift hello world
2019-07-03 11:46:28 +02:00
Ross Beazley
25dbee032d Update swebServer.swift hello world
looks like the example code hasn't been updated when the method signatures have changed
2019-07-03 10:43:14 +01:00
Pierre-Olivier Latour
c3c7aaad00 Revert "Merge pull request #416 from melle/app-extensions"
This reverts commit 8d0a3599ee, reversing
changes made to 7e4dd53c98.
2019-03-13 13:40:16 -07:00
Pierre-Olivier Latour
2c53064f5d Merge pull request #379 from kayak/runtime-logger
Added support to override built-in logger at runtime
2019-03-13 23:45:25 +09:00
Pierre-Olivier Latour
8d0a3599ee Merge pull request #416 from melle/app-extensions
Allow to build and run GDWebServer in app extensions.
2019-03-13 23:32:50 +09:00
Thomas Mellenthin
653dfb727b Allow to build and run GDWebServer in app extensions. 2019-03-13 15:26:52 +01:00
Pierre-Olivier Latour
7e4dd53c98 Update README.md 2019-01-06 12:25:18 -08:00
Duncan Cunningham
11254331d1 Make changes based on PR comments 2018-07-13 16:17:23 +02:00
Duncan Cunningham
9f345c6858 Added support to override built-in logger at runtime 2018-05-29 13:21:40 +02:00
11 changed files with 67 additions and 32 deletions

View File

@@ -358,9 +358,14 @@ static inline BOOL _IsMacFinder(GCDWebServerRequest* request) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Conflict message:@"Invalid destination \"%@\"", dstRelativePath];
}
NSString* itemName = [dstAbsolutePath lastPathComponent];
if ((!_allowHiddenItems && [itemName hasPrefix:@"."]) || (!isDirectory && ![self _checkFileExtension:itemName])) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"%@ to item name \"%@\" is not allowed", isMove ? @"Moving" : @"Copying", itemName];
NSString* srcName = [srcAbsolutePath lastPathComponent];
if ((!_allowHiddenItems && [srcName hasPrefix:@"."]) || (!isDirectory && ![self _checkFileExtension:srcName])) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"%@ from item name \"%@\" is not allowed", isMove ? @"Moving" : @"Copying", srcName];
}
NSString* dstName = [dstAbsolutePath lastPathComponent];
if ((!_allowHiddenItems && [dstName hasPrefix:@"."]) || (!isDirectory && ![self _checkFileExtension:dstName])) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"%@ to item name \"%@\" is not allowed", isMove ? @"Moving" : @"Copying", dstName];
}
NSString* overwriteHeader = [request.headers objectForKey:@"Overwrite"];

View File

@@ -7,7 +7,7 @@
Pod::Spec.new do |s|
s.name = 'GCDWebServer'
s.version = '3.5.2'
s.version = '3.5.3'
s.author = { 'Pierre-Olivier Latour' => 'info@pol-online.net' }
s.license = { :type => 'BSD', :file => 'LICENSE' }
s.homepage = 'https://github.com/swisspol/GCDWebServer'

View File

@@ -838,7 +838,7 @@
08FB7793FE84155DC02AAC07 /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1010;
LastUpgradeCheck = 1030;
TargetAttributes = {
CEE28CD01AE004D800F4023C = {
CreatedOnToolsVersion = 6.3;
@@ -864,13 +864,9 @@
};
buildConfigurationList = 1DEB928908733DD80010E9CD /* Build configuration list for PBXProject "GCDWebServer" */;
compatibilityVersion = "Xcode 8.0";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 1;
knownRegions = (
English,
Japanese,
French,
German,
en,
Base,
);
@@ -1180,7 +1176,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "net.pol-online.GCDWebServers";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
WARNING_CFLAGS = (
"-Wall",
"-Weverything",
@@ -1219,7 +1215,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "net.pol-online.GCDWebServers";
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
WARNING_CFLAGS = "-Wall";
};
name = Release;

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1010"
LastUpgradeVersion = "1030"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"

View File

@@ -69,6 +69,13 @@ typedef GCDWebServerResponse* _Nullable (^GCDWebServerProcessBlock)(__kindof GCD
typedef void (^GCDWebServerCompletionBlock)(GCDWebServerResponse* _Nullable response);
typedef void (^GCDWebServerAsyncProcessBlock)(__kindof GCDWebServerRequest* request, GCDWebServerCompletionBlock completionBlock);
/**
* The GCDWebServerBuiltInLoggerBlock is used to override the built-in logger at runtime.
* The block will be passed the log level and the log message, see setLogLevel for
* documentation of the log levels for the built-in logger.
*/
typedef void (^GCDWebServerBuiltInLoggerBlock)(int level, NSString* _Nonnull message);
/**
* The port used by the GCDWebServer (NSNumber / NSUInteger).
*
@@ -573,6 +580,14 @@ extern NSString* const GCDWebServerAuthenticationMethod_DigestAccess;
*/
+ (void)setLogLevel:(int)level;
/**
* Set a logger to be used instead of the built-in logger which logs to stderr.
*
* IMPORTANT: In order for this override to work, you should not be specifying
* a custom logger at compile time with "__GCDWEBSERVER_LOGGING_HEADER__".
*/
+ (void)setBuiltInLogger:(GCDWebServerBuiltInLoggerBlock)block;
/**
* Logs a message to the logging facility at the VERBOSE level.
*/

View File

@@ -85,18 +85,24 @@ static BOOL _run;
#ifdef __GCDWEBSERVER_LOGGING_FACILITY_BUILTIN__
static GCDWebServerBuiltInLoggerBlock _builtInLoggerBlock;
void GCDWebServerLogMessage(GCDWebServerLoggingLevel level, NSString* format, ...) {
static const char* levelNames[] = {"DEBUG", "VERBOSE", "INFO", "WARNING", "ERROR"};
static int enableLogging = -1;
if (enableLogging < 0) {
enableLogging = (isatty(STDERR_FILENO) ? 1 : 0);
}
if (enableLogging) {
if (_builtInLoggerBlock || enableLogging) {
va_list arguments;
va_start(arguments, format);
NSString* message = [[NSString alloc] initWithFormat:format arguments:arguments];
va_end(arguments);
fprintf(stderr, "[%s] %s\n", levelNames[level], [message UTF8String]);
if (_builtInLoggerBlock) {
_builtInLoggerBlock(level, message);
} else {
fprintf(stderr, "[%s] %s\n", levelNames[level], [message UTF8String]);
}
}
}
@@ -1071,6 +1077,14 @@ static inline NSString* _EncodeBase64(NSString* string) {
#endif
}
+ (void)setBuiltInLogger:(GCDWebServerBuiltInLoggerBlock)block {
#if defined(__GCDWEBSERVER_LOGGING_FACILITY_BUILTIN__)
_builtInLoggerBlock = block;
#else
GWS_DNOT_REACHED(); // Built-in logger must be enabled in order to override
#endif
}
- (void)logVerbose:(NSString*)format, ... {
va_list arguments;
va_start(arguments, format);

View File

@@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
* The GCDWebServerBodyReaderCompletionBlock is passed by GCDWebServer to the
* GCDWebServerBodyReader object when reading data from it asynchronously.
*/
typedef void (^GCDWebServerBodyReaderCompletionBlock)(NSData* data, NSError* _Nullable error);
typedef void (^GCDWebServerBodyReaderCompletionBlock)(NSData* _Nullable data, NSError* _Nullable error);
/**
* This protocol is used by the GCDWebServerConnection to communicate with

View File

@@ -325,12 +325,17 @@ NS_ASSUME_NONNULL_END
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_NotFound message:@"\"%@\" does not exist", oldRelativePath];
}
NSString* oldItemName = [oldAbsolutePath lastPathComponent];
if ((!_allowHiddenItems && [oldItemName hasPrefix:@"."]) || (!isDirectory && ![self _checkFileExtension:oldItemName])) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Moving from item name \"%@\" is not allowed", oldItemName];
}
NSString* newRelativePath = [request.arguments objectForKey:@"newPath"];
NSString* newAbsolutePath = [self _uniquePathForPath:[_uploadDirectory stringByAppendingPathComponent:GCDWebServerNormalizePath(newRelativePath)]];
NSString* itemName = [newAbsolutePath lastPathComponent];
if ((!_allowHiddenItems && [itemName hasPrefix:@"."]) || (!isDirectory && ![self _checkFileExtension:itemName])) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Moving to item name \"%@\" is not allowed", itemName];
NSString* newItemName = [newAbsolutePath lastPathComponent];
if ((!_allowHiddenItems && [newItemName hasPrefix:@"."]) || (!isDirectory && ![self _checkFileExtension:newItemName])) {
return [GCDWebServerErrorResponse responseWithClientError:kGCDWebServerHTTPStatusCode_Forbidden message:@"Moving to item name \"%@\" is not allowed", newItemName];
}
if (![self shouldMoveItemFromPath:oldAbsolutePath toPath:newAbsolutePath]) {

View File

@@ -6,7 +6,7 @@ Overview
[![Platform](http://cocoapod-badges.herokuapp.com/p/GCDWebServer/badge.png)](https://github.com/swisspol/GCDWebServer)
[![License](http://img.shields.io/cocoapods/l/GCDWebServer.svg)](LICENSE)
GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in OS X & iOS apps. It was written from scratch with the following goals in mind:
GCDWebServer is a modern and lightweight GCD based HTTP 1.1 server designed to be embedded in iOS, macOS & tvOS apps. It was written from scratch with the following goals in mind:
* Elegant and easy to use architecture with only 4 core classes: server, connection, request and response (see "Understanding GCDWebServer's Architecture" below)
* Well designed API with fully documented headers for easy integration and customization
* Entirely built with an event-driven design using [Grand Central Dispatch](http://en.wikipedia.org/wiki/Grand_Central_Dispatch) for best performance and concurrency
@@ -28,7 +28,7 @@ Extra built-in features:
Included extensions:
* [GCDWebUploader](GCDWebUploader/GCDWebUploader.h): subclass of ```GCDWebServer``` that implements an interface for uploading and downloading files using a web browser
* [GCDWebDAVServer](GCDWebDAVServer/GCDWebDAVServer.h): subclass of ```GCDWebServer``` that implements a class 1 [WebDAV](https://en.wikipedia.org/wiki/WebDAV) server (with partial class 2 support for OS X Finder)
* [GCDWebDAVServer](GCDWebDAVServer/GCDWebDAVServer.h): subclass of ```GCDWebServer``` that implements a class 1 [WebDAV](https://en.wikipedia.org/wiki/WebDAV) server (with partial class 2 support for macOS Finder)
What's not supported (but not really required from an embedded HTTP server):
* Keep-alive connections
@@ -81,7 +81,7 @@ These code snippets show how to implement a custom HTTP server that runs on port
**IMPORTANT:** If not using CocoaPods, be sure to add the `libz` shared system library to the Xcode target for your app.
**OS X version (command line tool):**
**macOS version (command line tool):**
```objectivec
#import "GCDWebServer.h"
#import "GCDWebServerDataResponse.h"
@@ -147,7 +147,7 @@ int main(int argc, const char* argv[]) {
@end
```
**OS X Swift version (command line tool):**
**macOS Swift version (command line tool):**
***webServer.swift***
```swift
@@ -158,12 +158,12 @@ func initWebServer() {
let webServer = GCDWebServer()
webServer.addDefaultHandlerForMethod("GET", requestClass: GCDWebServerRequest.self, processBlock: {request in
return GCDWebServerDataResponse(HTML:"<html><body><p>Hello World</p></body></html>")
webServer.addDefaultHandler(forMethod: "GET", request: GCDWebServerRequest.self, processBlock: {request in
return GCDWebServerDataResponse(html:"<html><body><p>Hello World</p></body></html>")
})
})
webServer.runWithPort(8080, bonjourName: "GCD Web Server")
webServer.start(withPort: 8080, bonjourName: "GCD Web Server")
print("Visit \(webServer.serverURL) in your web browser")
}
@@ -208,7 +208,7 @@ WebDAV Server in iOS Apps
GCDWebDAVServer is a subclass of ```GCDWebServer``` that provides a class 1 compliant [WebDAV](https://en.wikipedia.org/wiki/WebDAV) server. This lets users upload, download, delete files and create directories from a directory inside your iOS app's sandbox using any WebDAV client like [Transmit](https://panic.com/transmit/) (Mac), [ForkLift](http://binarynights.com/forklift/) (Mac) or [CyberDuck](http://cyberduck.io/) (Mac / Windows).
GCDWebDAVServer should also work with the [OS X Finder](http://support.apple.com/kb/PH13859) as it is partially class 2 compliant (but only when the client is the OS X WebDAV implementation).
GCDWebDAVServer should also work with the [macOS Finder](http://support.apple.com/kb/PH13859) as it is partially class 2 compliant (but only when the client is the macOS WebDAV implementation).
Simply instantiate and run a ```GCDWebDAVServer``` instance then connect to ```http://{YOUR-IOS-DEVICE-IP-ADDRESS}/``` using a WebDAV client:
@@ -238,7 +238,7 @@ Serving a Static Website
GCDWebServer includes a built-in handler that can recursively serve a directory (it also lets you control how the ["Cache-Control"](http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9) header should be set):
**OS X version (command line tool):**
**macOS version (command line tool):**
```objectivec
#import "GCDWebServer.h"