You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+37-5Lines changed: 37 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,15 +42,15 @@ Download or check out the [latest release](https://github.com/swisspol/GCDWebSer
42
42
43
43
Alternatively, you can install GCDWebServer using [CocoaPods](http://cocoapods.org/) by simply adding this line to your Xcode project's Podfile:
44
44
```
45
-
pod "GCDWebServer", "~> 2.0"
45
+
pod "GCDWebServer", "~> 3.0"
46
46
```
47
47
If you want to use GCDWebUploader, use this line instead:
48
48
```
49
-
pod "GCDWebServer/WebUploader", "~> 2.0"
49
+
pod "GCDWebServer/WebUploader", "~> 3.0"
50
50
```
51
51
Or this line for GCDWebDAVServer:
52
52
```
53
-
pod "GCDWebServer/WebDAV", "~> 2.0"
53
+
pod "GCDWebServer/WebDAV", "~> 3.0"
54
54
```
55
55
56
56
Hello World
@@ -147,6 +147,38 @@ println("Visit \(webServer.serverURL) in your web browser")
147
147
#import"GCDWebServerDataResponse.h"
148
148
```
149
149
150
+
Asynchronous HTTP Responses
151
+
===========================
152
+
153
+
New in GCDWebServer 3.0 is the ability to process HTTP requests aysnchronously i.e. add handlers to the server that generate their ```GCDWebServerResponse``` asynchronously. This is achieved by adding handlers that use a ```GCDWebServerAsyncProcessBlock``` instead of a ```GCDWebServerProcessBlock```. Here's an example:
@@ -250,9 +282,9 @@ GCDWebServer relies on "handlers" to process incoming web requests and generatin
250
282
251
283
Handlers require 2 GCD blocks:
252
284
* The ```GCDWebServerMatchBlock``` is called on every handler added to the ```GCDWebServer``` instance whenever a web request has started (i.e. HTTP headers have been received). It is passed the basic info for the web request (HTTP method, URL, headers...) and must decide if it wants to handle it or not. If yes, it must return a new ```GCDWebServerRequest``` instance (see above) created with this info. Otherwise, it simply returns nil.
253
-
* The ```GCDWebServerProcessBlock``` is called after the web request has been fully received and is passed the ```GCDWebServerRequest``` instance created at the previous step. It must return a ```GCDWebServerResponse``` instance (see above) or nil on error, which will result in a 500 HTTP status code returned to the client. It's however recommended to return an instance of [GCDWebServerErrorResponse](GCDWebServer/Responses/GCDWebServerErrorResponse.h) on error so more useful information can be returned to the client.
285
+
* The ```GCDWebServerProcessBlock``` or ```GCDWebServerAsyncProcessBlock``` is called after the web request has been fully received and is passed the ```GCDWebServerRequest``` instance created at the previous step. It must return synchronously (if using ```GCDWebServerProcessBlock```) or asynchronously (if using ```GCDWebServerAsyncProcessBlock```) a ```GCDWebServerResponse``` instance (see above) or nil on error, which will result in a 500 HTTP status code returned to the client. It's however recommended to return an instance of [GCDWebServerErrorResponse](GCDWebServer/Responses/GCDWebServerErrorResponse.h) on error so more useful information can be returned to the client.
254
286
255
-
Note that most methods on ```GCDWebServer``` to add handlers only require the ```GCDWebServerProcessBlock``` as they already provide a built-in ```GCDWebServerMatchBlock``` e.g. to match a URL path with a Regex.
287
+
Note that most methods on ```GCDWebServer``` to add handlers only require the ```GCDWebServerProcessBlock``` or ```GCDWebServerAsyncProcessBlock``` as they already provide a built-in ```GCDWebServerMatchBlock``` e.g. to match a URL path with a Regex.
0 commit comments