Skip to content

Commit

Permalink
Make socketPath addition non-breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
djones6 committed Mar 21, 2019
1 parent e23d004 commit 357806e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
18 changes: 9 additions & 9 deletions Sources/KituraNet/ClientRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,7 @@ public class ClientRequest {

/// If present, the client will try to use HTTP/2 protocol for the connection.
case useHTTP2

/// If present, the client will connect using the Unix Socket
case socketPath(String)


}

/**
Expand Down Expand Up @@ -245,9 +242,10 @@ public class ClientRequest {

/// Initializes a `ClientRequest` instance
///
/// - Parameter options: An array of `Options' describing the request
/// - Parameter options: An array of `Options' describing the request.
/// - Parameter socketPath: Specifies a Unix socket that the client should connect to.
/// - Parameter callback: The closure of type `Callback` to be used for the callback.
init(options: [Options], callback: @escaping Callback) {
init(options: [Options], socketPath: String? = nil, callback: @escaping Callback) {

self.callback = callback

Expand All @@ -256,10 +254,14 @@ public class ClientRequest {
var path = ""
var port = ""

if let socketPath = socketPath {
self.socketPath = socketPath
}

for option in options {
switch(option) {

case .method, .headers, .maxRedirects, .disableSSLVerification, .useHTTP2, .socketPath:
case .method, .headers, .maxRedirects, .disableSSLVerification, .useHTTP2:
// call set() for Options that do not construct the URL
set(option)
case .schema(var schema):
Expand Down Expand Up @@ -327,8 +329,6 @@ public class ClientRequest {
self.disableSSLVerification = true
case .useHTTP2:
self.useHTTP2 = true
case .socketPath(let socketPath):
self.socketPath = socketPath
}
}

Expand Down
5 changes: 3 additions & 2 deletions Sources/KituraNet/HTTP/HTTP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public class HTTP {
Create a new `ClientRequest` using a list of options.

- Parameter options: a list of `ClientRequest.Options`.
- Parameter socketPath: a Unix socket path that this client should connect to (defaults to `nil`).
- Parameter callback: closure to run after the request.
- Returns: a `ClientRequest` instance

Expand All @@ -125,8 +126,8 @@ public class HTTP {
}
````
*/
public static func request(_ options: [ClientRequest.Options], callback: @escaping ClientRequest.Callback) -> ClientRequest {
return ClientRequest(options: options, callback: callback)
public static func request(_ options: [ClientRequest.Options], socketPath: String? = nil, callback: @escaping ClientRequest.Callback) -> ClientRequest {
return ClientRequest(options: options, socketPath: socketPath, callback: callback)
}

/**
Expand Down

0 comments on commit 357806e

Please sign in to comment.