This repository was archived by the owner on Dec 15, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +49
-21
lines changed
Expand file tree Collapse file tree 6 files changed +49
-21
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ public extension HTTP {
7878
7979 response. headers = urlResponse!. allHeaderFields as! [ String : String ]
8080
81+ response. url = urlResponse!. url
82+
8183 return response
8284 }
8385 }
@@ -97,15 +99,13 @@ public extension Foundation.URLRequest {
9799
98100 init ? ( request: HTTP . Request ) {
99101
100- guard let url = NSURL ( string: request. URL) else { return nil }
101-
102102 guard request. version == HTTP . Version ( 1 , 1 ) else { return nil }
103103
104- self . init ( url: url as Foundation . URL , timeoutInterval: request. timeoutInterval)
104+ self . init ( url: request . url , timeoutInterval: request. timeoutInterval)
105105
106- if let data = request. body {
106+ if request. body. isEmpty == false {
107107
108- self . httpBody = data
108+ self . httpBody = request . body
109109 }
110110
111111 self . allHTTPHeaderFields = request. headers
Original file line number Diff line number Diff line change @@ -11,21 +11,31 @@ public extension HTTP {
1111 /// HTTP request.
1212 public struct Request : URLRequest {
1313
14- public var URL : String
14+ public var url : URL
1515
16- public var timeoutInterval : TimeInterval = 30
16+ public var timeoutInterval : TimeInterval
1717
18- public var body : Data ?
18+ public var body : Data
1919
20- public var headers = [ String: String] ( )
20+ public var headers : [ String : String ]
2121
22- public var method : HTTP . Method = . GET
22+ public var method : HTTP . Method
2323
24- public var version : HTTP . Version = HTTP . Version ( )
24+ public var version : HTTP . Version
2525
26- public init ( URL: String ) {
26+ public init ( url: URL ,
27+ timeoutInterval: TimeInterval = 30 ,
28+ body: Data = Data ( ) ,
29+ headers: [ String : String ] = [ : ] ,
30+ method: HTTP . Method = . GET,
31+ version: HTTP . Version = HTTP . Version ( ) ) {
2732
28- self . URL = URL
33+ self . url = url
34+ self . timeoutInterval = timeoutInterval
35+ self . body = body
36+ self . headers = headers
37+ self . method = method
38+ self . version = version
2939 }
3040 }
3141}
Original file line number Diff line number Diff line change @@ -12,15 +12,29 @@ public extension HTTP {
1212 public struct Response : URLResponse {
1313
1414 /// Returns a dictionary containing all the HTTP header fields.
15- public var headers = [ String: String] ( )
15+ public var headers : [ String : String ]
1616
1717 /// Returns the HTTP status code for the response.
18- public var statusCode : Int = HTTP . StatusCode . OK . rawValue
18+ public var statusCode : Int
1919
2020 /// The HTTP response body.
21- public var body = Data ( )
21+ public var body : Data
2222
23- public init ( ) { }
23+ /// The URL for the response.
24+ ///
25+ /// Returned with 302 Found response.
26+ public var url : URL ?
27+
28+ public init ( headers: [ String : String ] = [ String: String] ( ) ,
29+ statusCode: Int = HTTP . StatusCode. OK. rawValue,
30+ body: Data = Data ( ) ,
31+ url: URL ? = nil ) {
32+
33+ self . headers = headers
34+ self . statusCode = statusCode
35+ self . body = body
36+ self . url = url
37+ }
2438 }
2539}
2640
Original file line number Diff line number Diff line change 66// Copyright © 2015 PureSwift. All rights reserved.
77//
88
9+ #if os(Linux) || XcodeLinux
10+
911/// Encapsulates the components of an URL.
1012public struct URL : CustomStringConvertible {
1113
@@ -172,3 +174,4 @@ public struct URL: CustomStringConvertible {
172174 }
173175}
174176
177+ #endif
Original file line number Diff line number Diff line change 88
99public protocol URLRequest {
1010
11- var URL : String { get }
11+ var url : URL { get }
1212
1313 var timeoutInterval : TimeInterval { get }
14- }
14+ }
Original file line number Diff line number Diff line change 66// Copyright © 2015 PureSwift. All rights reserved.
77//
88
9- /// Encapsulates the metadata associated with the response to a a URL load request in a manner independent of protocol and URL scheme.
9+ /// Encapsulates the metadata associated with the response to a a URL load request
10+ /// in a manner independent of protocol and URL scheme.
1011public protocol URLResponse {
1112
1213
13- }
14+ }
You can’t perform that action at this time.
0 commit comments