Overview
========
[![Build Status](https://travis-ci.org/swisspol/GCDWebServer.svg?branch=master)](https://travis-ci.org/swisspol/GCDWebServer)
[![Version](http://cocoapod-badges.herokuapp.com/v/GCDWebServer/badge.png)](https://cocoapods.org/pods/GCDWebServer)
[![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 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
* No dependencies on third-party source code
* Available under a friendly [New BSD License](LICENSE)
Extra built-in features:
* Allow implementation of fully asynchronous handlers of incoming HTTP requests
* Minimize memory usage with disk streaming of large HTTP request or response bodies
* Parser for [web forms](http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4) submitted using "application/x-www-form-urlencoded" or "multipart/form-data" encodings (including file uploads)
* [JSON](http://www.json.org/) parsing and serialization for request and response HTTP bodies
* [Chunked transfer encoding](https://en.wikipedia.org/wiki/Chunked_transfer_encoding) for request and response HTTP bodies
* [HTTP compression](https://en.wikipedia.org/wiki/HTTP_compression) with gzip for request and response HTTP bodies
* [HTTP range](https://en.wikipedia.org/wiki/Byte_serving) support for requests of local files
* [Basic](https://en.wikipedia.org/wiki/Basic_access_authentication) and [Digest Access](https://en.wikipedia.org/wiki/Digest_access_authentication) authentications for password protection
* Automatically handle transitions between foreground, background and suspended modes in iOS apps
* Full support for both IPv4 and IPv6
* NAT port mapping (IPv4 only)
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 macOS Finder)
What's not supported (but not really required from an embedded HTTP server):
* Keep-alive connections
* HTTPS
Requirements:
* macOS 10.7 or later (x86_64)
* iOS 8.0 or later (armv7, armv7s or arm64)
* tvOS 9.0 or later (arm64)
* ARC memory management only (if you need MRC support use GCDWebServer 3.1 or earlier)
Getting Started
===============
Download or check out the [latest release](https://github.com/swisspol/GCDWebServer/releases) of GCDWebServer then add the entire "GCDWebServer" subfolder to your Xcode project. If you intend to use one of the extensions like GCDWebDAVServer or GCDWebUploader, add these subfolders as well. Finally link to `libz` (via Target > Build Phases > Link Binary With Libraries) and add `$(SDKROOT)/usr/include/libxml2` to your header search paths (via Target > Build Settings > HEADER_SEARCH_PATHS).
Alternatively, you can install GCDWebServer using [CocoaPods](http://cocoapods.org/) by simply adding this line to your Podfile:
```
pod "GCDWebServer", "~> 3.0"
```
If you want to use GCDWebUploader, use this line instead:
```
pod "GCDWebServer/WebUploader", "~> 3.0"
```
Or this line for GCDWebDAVServer:
```
pod "GCDWebServer/WebDAV", "~> 3.0"
```
And finally run `$ pod install`.
You can also use [Carthage](https://github.com/Carthage/Carthage) by adding this line to your Cartfile (3.2.5 is the first release with Carthage support):
```
github "swisspol/GCDWebServer" ~> 3.2.5
```
Then run `$ carthage update` and add the generated frameworks to your Xcode projects (see [Carthage instructions](https://github.com/Carthage/Carthage#adding-frameworks-to-an-application)).
Help & Support
==============
For help with using GCDWebServer, it's best to ask your question on Stack Overflow with the [`gcdwebserver`](http://stackoverflow.com/questions/tagged/gcdwebserver) tag. For bug reports and enhancement requests you can use [issues](https://github.com/swisspol/GCDWebServer/issues) in this project.
Be sure to read this entire README first though!
Hello World
===========
These code snippets show how to implement a custom HTTP server that runs on port 8080 and returns a "Hello World" HTML page to any request. Since GCDWebServer uses GCD blocks to handle requests, no subclassing or delegates are needed, which results in very clean code.
**IMPORTANT:** If not using CocoaPods, be sure to add the `libz` shared system library to the Xcode target for your app.
**macOS version (command line tool):**
```objectivec
#import "GCDWebServer.h"
#import "GCDWebServerDataResponse.h"
int main(int argc, const char* argv[]) {
@autoreleasepool {
// Create server
GCDWebServer* webServer = [[GCDWebServer alloc] init];
// Add a handler to respond to GET requests on any URL
[webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"];
}];
// Use convenience method that runs server on port 8080
// until SIGINT (Ctrl-C in Terminal) or SIGTERM is received
[webServer runWithPort:8080 bonjourName:nil];
NSLog(@"Visit %@ in your web browser", webServer.serverURL);
}
return 0;
}
```
**iOS version:**
```objectivec
#import "GCDWebServer.h"
#import "GCDWebServerDataResponse.h"
@interface AppDelegate : NSObject <UIApplicationDelegate> {
GCDWebServer* _webServer;
}
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
// Create server
_webServer = [[GCDWebServer alloc] init];
// Add a handler to respond to GET requests on any URL
[_webServer addDefaultHandlerForMethod:@"GET"
requestClass:[GCDWebServerRequest class]
processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {
return [GCDWebServerDataResponse responseWithHTML:@"<html><body><p>Hello World</p></body></html>"];
}];
// Start server on port 8080
[_webServer startWithPort:8080 bonjourName:nil];
NSLog(@"Visit %@ in your web browser", _webServer.serverURL);
return YES;
}
@end
```
**macOS Swift version (command line tool):**
***webServer.swift***
```swift
import Foundation
import GCDWebServer
func initWebServer() {
let webServer = GCDWebServer()
webServer.addDefaultHandler(forMethod: "GET", request: GCDWebServerRequest.self, processBlock: {request in
return GCDWebServerDataResponse(html:"<html><body><p>Hello World</p></body></html>")
})
webServer.start(withPort: 8080, bonjourName: "GCD Web Server")
print("Visit \(webServer.serverURL) in your web browser")
}
```
***WebServer-Bridging-Header.h***
```objectivec
#import <GCDWebServer/GCDWebServer.h>
#import <GCDWebServer/GCDWebServerDataResponse.h>
```
Web Based Uploads in iOS Apps
=============================
GCDWebUploader is a subclass of ```GCDWebServer``` that provides a ready-to-use HTML 5 file uploader & downloader. This lets users upload, download, delete files and create di
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
iOS_防截屏_基于DRM隐藏敏感信息 (328个子文件)
020bad023774a25178ba89e9e1c9c47c3e4842 388B
0217baed2fcd6178c8fb47539751f7562e67fd 28KB
028d83d457a64526138e60fb5d6e8154be321c 277B
042b21b349d02a5f5599bba6213126b599b98c 3KB
05ce766759345ce5a31dfee27bcfd1f683ff3a 1KB
0683701c8b376d4223d1a93f94d27a8d0a2bf7 3KB
0952a2b6ef8afba70d78527f7c872df032e573 59B
0ab26d98769de4e635d32ba455df3b458b9013 990B
0b6f9d8abc7b6feea2a578fc9297ad1d3965dd 10KB
0bb1834a5acf0ad5230bcc89cc58a548d2c86f 216B
0ccdd78706385da6cb21e1fca00d6a63a44fcf 135B
0fa2c376de25e8707e394078bc00ee15e3c04f 164B
0fedff806c53c98afcef425b38fbf2b13ed910 2KB
10d5bfe9647de7d58717ede375de6e26d5a9ce 1KB
11f42f352ad9a5ab131c7051de38151c9d6d9a 663B
121c336262445c829194c8eed6420d9b6bdc47 1KB
1365bfb392f5ead52121da7554cfc6479a9d9a 3KB
15a1b319804bc4976ae46317c900910d7c8289 5KB
168b76174e205ae47bdd1423882b4dd9d2f790 1KB
199aa3b7fda05e1a8615db9fac3a94b37234de 3KB
1c4b697d4404af5c71ce4490283f5576ea3e19 482B
1efa389d73b83edfeb1b603fff9a92b2c32a96 646B
1f630388aac43bbf344bf96aeaf75badf73be7 1KB
208ab94d6c21c38f8f764eb70d6d54d46f6b8d 103B
21b9bb1a35f5de270a41afa01305478221ae32 232B
22bf9b81e2e4d96d80a6743af07b7d471f2ad6 3KB
233063e08e0ce105ca51563da1b15ae18fdaef 3KB
2396c29df99fcfc29b1d5e143a0722cd2030db 51B
24c9b86c0b027347e32179169931c65c3f61ef 1KB
27bb435f2771b24e3e63db45d2737e019b8851 2KB
29252e5a2dd4179c35b5517c68ed5e9772e440 2KB
29cf8dadbd7ec6b4deff9662ebbfcf660f6f63 108B
2a40c9fc303aea0fcbcdffddbbd6115be275a8 17KB
2a72d07a41e2919fc846302530fea836adbe39 1KB
2d13383eca184133aa1bf6f1acae3d740a2646 94B
335de49bb785c55d720c2efa8ceddd261398a0 793B
3788f6b87ec8f5810a0ad66ec1447055b05457 2KB
3cc9b8ba4e4ae5c6df5ed5e3f199668b7fead0 68B
3e0d4a3b04d16d6fefda7d3d00a67096adc879 2KB
3e94af4d7d4df10ad98c1571de6f23a579eb7f 59B
3fc22df0a2d4da6ad5bdfe12a9d2170731d86a 3KB
40794598e25944fd81079e523a18956ddb5d20 8KB
40a124d90982e87bc1e7425b63ba89fc54ded4 67B
43fe6e27dc60546f37eca17f97ed75802d224f 383B
45d5e9613bcb8133ca0b5a8fb7e9039e55bf65 2KB
4646fbd289e23a3e0d5707d58d437c130f8aec 196B
46916a10a4621723e3fc7c039141532b58c238 1KB
48eff7a9858046e47033faa8c120400b9824f8 3KB
4a4605f8dd755ad43c6ddb0d837b84ef07d5da 142B
50a021fdc3c7c3c939b87848de78585783edd7 4KB
5464aaf25732fd331f83157ffed1befe0d9bca 236B
54e229b7071e14e04108cb31e9f7975808ec8d 128B
5520e37317b88ccfc9ffc26f459ae12a71decd 156B
55556ca621cbc4a8a24259b7d0e19f42525d52 4KB
575f55fcf8b8ace81ac9a9f742859279610129 145B
57935286058c3921aa6a6d7aa7f9aa79b994a0 617B
59b9f1f58c161cf9f8730cd8dda47079595a0a 2KB
5b2bda7eeb87a5b38b66655e35f62a4c265b98 12KB
5be5c32cb9ea8e8bb16e05074401024ee2bdf8 250B
5e91b44fde60edb2f5c085f00a04a9a3aa64f5 1KB
5e9329f3767a7c1dd66294b8025bf81dee7d2c 751B
5eafcf7422aad350583e810d9b035547afaf98 1KB
5f12320b9225af95de391be583e9fe02037e62 33KB
5f63f23dece610b3a574a2eebd3d7642f8db0f 736B
5fa78682557a1d232e0494645f6a667a4e4214 301B
617280c0eee67af148682bc35027bd69f97145 100B
64539d4cae33dc328b75391e2c0e37a231f6b0 2KB
68a97875c78afea8b13e4a90c5f037b7232fea 3KB
6943c8440b7bd76ed97ec5665108879081de70 225B
6a6d249256a9b3fae24281e0933e050ef38117 1KB
6aa578b8f02611751f8bfe32335d429247d302 8KB
6bd324c26d854187559f27f8194c8afd1795ac 58B
6db35461eb151f316f3255dab75cf8d133cdfc 58B
700c39a9d09733d2fd077a1af5bee786906afa 7KB
72cd74fc752c2633fac9c96550a2b7a111e8da 384B
758f5016765e02a8e9dca7956eb71ec28ec651 2KB
77b45e8cbf6018d3ab16434c00c892e8d74ec9 2KB
78b5721661e4f40f132e43c13c348dc3ae0b78 430B
7e871e632cca38af53bb6e4691a2ac8a508855 6KB
7fb143160c04d804eab448191da801bf516e36 2KB
809da9670547aba9affa72a1593e8c635ca5e4 2KB
8142dc0657f8ce457df41ed3803b9461189452 268B
8203b7bacdf44604f8161c5ed079fcfbb248a2 253B
82db7cb2f791e5d4df67371fe396f933fce8f4 326B
8789700816459c1e1480e0b34781d9fb78a1ca 104B
8a78286d7559ffed3c87355b03760d226da88c 4KB
8b4b7349fa112460589eafa41b298c14d84c8c 58B
8db5480cfbf896669f3cb4d3fb267bc3009d5f 1KB
920415991b63bfb6a8c5db39959012bf13a648 100B
92cd30c97384ebfd1fcf406cab019ecfce06d1 98B
931bc6150312f1a8b772d8502709346ff950b1 2KB
93dfe8d1e79850f407ca449207b5190ecac0d7 4KB
9434a6254f0e9651f402737811be6634a03e9c 114B
95ad25698ac72f59091e325e65088bc3f020dc 310B
966a5766f87adef3022d9c7c82ff9245afc822 2KB
982a0e3c78ecbbff72fa3f0869b9170db00dbc 3KB
98b2d4fd3acd8ffb9cf55612259ed004ac0020 51B
99934821a1b8ec62f4d9847d1e6f90912b6d83 59B
9ba56e1d4bf2d79fcd68eda1ca209f0022502a 156B
9c0b0281fd6a54b1c6372f013a21977914747f 911B
共 328 条
- 1
- 2
- 3
- 4
资源评论
ronieyx
- 粉丝: 2
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功