forked from swift-server/http
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPRequest.swift
More file actions
49 lines (44 loc) · 2.07 KB
/
HTTPRequest.swift
File metadata and controls
49 lines (44 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// This source file is part of the Swift.org Server APIs open source project
//
// Copyright (c) 2017 Swift Server API project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
//
import Dispatch
import Foundation
/// A structure representing the headers from a HTTP request, without the body of the request.
public struct HTTPRequest {
/// HTTP request method.
public var method: HTTPMethod
/// HTTP request URI, eg. "/foo/bar?buz=qux"
public var target: String
/// HTTP request version
public var httpVersion: HTTPVersion
/// HTTP request headers
public var headers: HTTPHeaders
}
/// Method that takes a chunk of request body and is expected to write to the `HTTPResponseWriter`
/// - Parameter HTTPBodyChunk: `HTTPBodyChunk` representing some or all of the incoming request body
/// - Parameter Bool: A boolean flag that can be set to true in order to prevent further processing
public typealias HTTPBodyHandler = (HTTPBodyChunk, inout Bool) -> Void
/// Indicates whether the body is going to be processed or ignored
public enum HTTPBodyProcessing {
/// Used to discard the body data associated with the incoming HTTP request
case discardBody
/// Used to process the body data associated with the imcoming HTTP request using a `HTTPBodyHandler`
case processBody(handler: HTTPBodyHandler)
}
/// Part or all of the incoming request body
public enum HTTPBodyChunk {
/// A new chunk of the incoming HTTP reqest body data has arrived. `finishedProcessing()` must be called when
/// that chunk has been processed.
case chunk(data: DispatchData, finishedProcessing: () -> Void)
/// An error has occurred whilst streaming the incoming HTTP request data, eg. the connection closed
case failed(error: Error)
/// A trailer header has arrived during the processing of the incoming HTTP request data.
/// This is currently unimplemented.
case trailer(key: String, value: String)
/// The stream of incoming HTTP request data has completed.
case end
}