-
Notifications
You must be signed in to change notification settings - Fork 133
Support UNIX Domain Sockets #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
4932cb5
41ee04e
ac69f69
d3bbf37
bbd47f7
cb19a2d
45c443f
535303b
5233d5c
b6cf0a4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,14 +88,32 @@ extension HTTPClient { | |
|
||
/// Represent HTTP request. | ||
public struct Request { | ||
|
||
/// Represent kind of Request | ||
enum Kind { | ||
/// Remote host request. | ||
case host | ||
/// UNIX Domain Socket HTTP request. | ||
case unixSocket | ||
|
||
func isSchemeSupported(scheme: String) -> Bool { | ||
switch self { | ||
case .host: | ||
return scheme == "http" || scheme == "https" | ||
case .unixSocket: | ||
return scheme == "unix" | ||
} | ||
} | ||
} | ||
|
||
/// Request HTTP method, defaults to `GET`. | ||
public let method: HTTPMethod | ||
public var method: HTTPMethod | ||
/// Remote URL. | ||
public let url: URL | ||
public var url: URL | ||
/// Remote HTTP scheme, resolved from `URL`. | ||
public let scheme: String | ||
public var scheme: String | ||
/// Remote host, resolved from `URL`. | ||
public let host: String | ||
public var host: String | ||
/// Request custom HTTP Headers, defaults to no headers. | ||
public var headers: HTTPHeaders | ||
/// Request body, defaults to no body. | ||
|
@@ -107,6 +125,7 @@ extension HTTPClient { | |
} | ||
|
||
var redirectState: RedirectState? | ||
let kind: Kind | ||
|
||
/// Create HTTP request. | ||
/// | ||
|
@@ -133,7 +152,6 @@ extension HTTPClient { | |
/// | ||
/// - parameters: | ||
/// - url: Remote `URL`. | ||
/// - version: HTTP version. | ||
/// - method: HTTP method. | ||
/// - headers: Custom HTTP headers. | ||
/// - body: Request body. | ||
|
@@ -146,22 +164,26 @@ extension HTTPClient { | |
throw HTTPClientError.emptyScheme | ||
} | ||
|
||
guard Request.isSchemeSupported(scheme: scheme) else { | ||
throw HTTPClientError.unsupportedScheme(scheme) | ||
} | ||
if Kind.host.isSchemeSupported(scheme: scheme) { | ||
self.kind = .host | ||
guard let host = url.host else { | ||
throw HTTPClientError.emptyHost | ||
} | ||
|
||
guard let host = url.host else { | ||
throw HTTPClientError.emptyHost | ||
self.host = host | ||
} else if Kind.unixSocket.isSchemeSupported(scheme: scheme) { | ||
self.kind = .unixSocket | ||
self.host = "" | ||
} else { | ||
throw HTTPClientError.unsupportedScheme(scheme) | ||
} | ||
|
||
|
||
self.method = method | ||
self.redirectState = nil | ||
self.url = url | ||
self.method = method | ||
self.scheme = scheme | ||
self.host = host | ||
self.headers = headers | ||
self.body = body | ||
|
||
self.redirectState = nil | ||
} | ||
|
||
/// Whether request will be executed using secure socket. | ||
|
@@ -174,8 +196,8 @@ extension HTTPClient { | |
return self.url.port ?? (self.useTLS ? 443 : 80) | ||
} | ||
|
||
static func isSchemeSupported(scheme: String) -> Bool { | ||
return scheme == "http" || scheme == "https" | ||
func isSchemeSupported(scheme: String) -> Bool { | ||
return kind.isSchemeSupported(scheme: scheme) | ||
} | ||
} | ||
|
||
|
@@ -812,7 +834,7 @@ internal struct RedirectHandler<ResponseType> { | |
return nil | ||
} | ||
|
||
guard HTTPClient.Request.isSchemeSupported(scheme: self.request.scheme) else { | ||
guard request.isSchemeSupported(scheme: self.request.scheme) else { | ||
return nil | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.