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
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Android、iOS、Flutter App 的 Xtream IPTV 播放器 (2000个子文件)
005d0c23f0a855bc2468975b7093daf193b397 160B
00de78fd0fd1162523ccd442db5fd2a5293111 180B
00df978535e07e8f3bbf97045747deb643f5db 178B
014cbe2c578c028b19f970b22fa7c8d91862f3 186B
0183d9b8cdbc93c6b1ee32947abb1a3a43b612 208B
030996b63d7574e6558088632624acdf755ef0 91B
036a9aca96611d5d9a849234c0b55f49132fac 2KB
03700f4caa94fb6f042223e6a967534cf4b740 160B
044263b97039b3dd6a68a4a67c046ad804b9db 1KB
044410602ab1c365131fb2e8cf235cd3471c38 322B
046c43ef623438b9ea8bd2509877fc4b4c423b 110B
04761740b072eb3e1a27f078d59889908f6e23 121B
04e4327100be38f8b7b6f87efa96fd44bda59b 227B
051db44ba33e632b884a2c8807d41524c9d57a 188B
0629a57403d052f5816c5977a551e60fbaa727 979B
062baa75d4da7df663afa4a37d95c28c88a13e 275B
06646452d0b6ae30dc739f70b43d6001d09375 120B
069ac419ba5f660fe7e2d51858bc09812bcb58 187B
06e89683c35cb9471a6eb0eb7365e051b47cc6 60B
070fa97a06c6e6823fa294a6947e7a36172bae 168B
0777465e9d1b80a62910c6309127b54efe82c1 816B
085363984e127ad5170b529515acd0b971d56a 3KB
08fedd73d67b155df091548f189cc637264a3d 811B
0a2fb1e66d1f03c70042cae32d655a0ab78287 188B
0a65c08825a4d5cc2449b8b5ad8b2ea2cef180 187B
0b9b93e9c268d62cb6abacf02798a631ce8b19 164B
0bca09b0381ebebd400b4ff8b1e7358b21b9b0 169B
0c3ac8b34ca3d9beb7fcd2ca101d68aeb2b536 314B
0c838f55450169d7563a5924e5fdcf1a3c0e30 129B
0d1bedea1137a1542d0aa3a583452227bfee98 79B
0d2071a324ee6050cccd87a14495557b63416f 1KB
0e0e398c8b6ebfe403bc654250fa7180c4f1f4 158B
0e15721b5554ae1d99ee420843ef89fc43ee36 280B
0e4c441073dd7f5f238a5b97a78f2654c37d5f 125B
0ec7b86bb8364e35dd18d33a23a679bd8fd5ee 321B
0f08dc7da60c948c794965285a3fc9a649c9f2 3KB
0f29a3d906400329d609f4225fcb66c28cf99d 246B
0f39a8c8426c7940f5c633c705e6a060d5138e 818B
0f9334bb9772563c8f1b35a96ab6b02343b897 2KB
0faaad2072be9d6a23008ace825da4ea22c1c4 285B
0feb9599ac16cc7b4b8c8f0d2f1303fb9e398d 174B
102c57dc6690169d6e8ea65bbce07a2660407e 187B
102d02b65f41f00f4e9ba53b715014c4fa3b81 236B
103a3372b907dd27b5c57032316ea36f608d42 46B
10fabee4b903b16f631ef65bd533d785995e38 456B
111ac91c64e50e9fdca06eb92cd90808b70e2b 1KB
12319fb3fcbcfbd41c71895b006900b9114197 266B
12edd540ecfb3cc5438bf600d300308ae65640 2KB
12f888dd10bebee03efad5b8f18f44a5f078dd 876B
139d85a93101cc0f6e9db03a3e1a9f68e8dd7e 198B
13fd67598d8b89b273be6fb5602b284360a136 125B
14183d0762484a8b4dec6a3eb03d7cfb953666 125B
146414d46977bd8a413e07ac991c2490f9a1d7 349B
14e1a2d3a2aeb783a5715e77571b15dd1bac3d 80B
15ae7a3114eae16b67c4d50099e50a051096a1 2KB
160376ade12c3c2d28bb664c756bd2e6c258c3 6KB
1632cfddf3d9dade342351e627a0a75609fb46 2KB
1773345a2537093d744cf6be69bb1e99fa08b8 2KB
18677dff3ed40a0295a2999a3493b7db3bfdb0 2KB
192c8497428b4e53d9f55a7ed5ba38fb8828df 5KB
1964a4677eb0b4885d74719e459f0874bbd6ec 59B
19843f55e60c2fc168fe9f0afc867c44799a04 168B
1a16d23d05881b554326e645083799ab9bfc5e 138B
1a363738fea0d15162f3c1cee537022d6573a9 2KB
1a7b457b9ad71c454ba6f1b1d9515b77909c72 430B
1ab1a7bdf578e38b84618bdbe5488751d8d566 127B
1ab2ae35c23cb8c80f1182a2c440c3c969b988 78B
1af6cb8a5856456c407391ed19cfbeb6fcbce2 106B
1b8e3496f3dde7cef5d70fa48e5931e7de718c 2KB
1ba9dfa34aeb5800604de5f188b1a03651f4a0 713B
1bd388c5378f8ab1f658897b1c998702599101 457B
1cc054f7ae64a3198815de08489cd58c02755b 157B
1d2de1fd576e9cb86741f65b137154f3f78db2 178B
1d646b0f80e7dc5928a254a6e505f3bec55ec4 96B
1e289631b33c20edabca092aa504d4abbba7c1 2KB
1f75b08ad26853760501ba9bb4bce0d4318fc0 48B
1f951abe50e0e354d9f8388da0379697788cc2 95B
1f9b0917026f0aa5dd05c96408e950ed9acf7c 427B
205ad70a0448b852bfe85153ec973f2925377b 105B
205eb9b273c3a662c607685f13cbde494fb580 2KB
2126f48f49ec088ca08a3055fcd22bb1fef43d 238B
216af029d1c6bdf7542fe6f5a9acceb5677374 187B
21ada2a80fb43301f5fd63401f369546ee2f55 308B
21cdf7519f8865a815cbfd4dc57f7cac0836d8 852B
220c4b8896d8184dc3bf1b4c6d58950adcb2f0 80B
221d88a53f63dc7ea929888d8b19533149e501 80B
22837ec9181c3c1b2f1c1298870185c03ba354 228B
238eaabda3397165a0a58cbbec8680be2e6b9e 144B
2462950f6ffd8b52218dfc07c5e40dd8819194 235B
248418d819304baca0a96179b45a6d9cf2bfeb 59B
248face90823c200191271b27ffe34755afeb2 81B
24992bcba85c5cd7f78809651e7d5a3173cb31 458B
24c185a08d09054bed4d28527f7c4bd241e85b 621B
24fe5349ade0bfd0562864777556b3bcd2df20 129B
251f3c6ade59ef65053bb7206143cc653ab4ed 86B
25cd4262e5b44ca528c5796abd74bea89d6499 304B
25dbdd1c0be5d2907920c45ae70d08d43549ec 2KB
25e105df39e8429814f3189a8015087720cba1 333B
25f62b1ee56c7acceb3f1f186a374492688a17 349B
26513a9af4676142273ada630cfacc2b01088d 225B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
荻酷社区
- 粉丝: 210
- 资源: 16
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功