Skip to content

Commit 9d621ac

Browse files
Removed some of the new public methods added for creating a socket-path based request
Motivation: I previously added too much new public API that will most likely not be necessary, and can be better accessed using a generic execute method. Modifications: Removed the get/post/patch/put/delete methods that were specific to socket paths. Result: Less new public API.
1 parent affa03f commit 9d621ac

File tree

3 files changed

+6
-128
lines changed

3 files changed

+6
-128
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ httpClient.execute(request: request, delegate: delegate).futureResult.whenSucces
162162
Connecting to servers bound to socket paths is easy:
163163
```swift
164164
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
165-
httpClient.get(socketPath: "/tmp/myServer.socket", url: "/path/to/resource").whenComplete (...)
165+
httpClient.execute(socketPath: "/tmp/myServer.socket", url: "/path/to/resource", method: .GET).whenComplete (...)
166166
```
167167

168168
Connecting over TLS to a unix domain socket path is possible as well:
169169
```swift
170170
let httpClient = HTTPClient(eventLoopGroupProvider: .createNew)
171-
httpClient.post(secureSocketPath: "/tmp/myServer.socket", url: "/path/to/resource", body: .string("hello")).whenComplete (...)
171+
httpClient.execute(secureSocketPath: "/tmp/myServer.socket", url: "/path/to/resource", body: .string("hello"), method: .POST).whenComplete (...)
172172
```
173173

174174
Direct URLs can easily be contructed to be executed in other scenarios:

Diff for: Sources/AsyncHTTPClient/HTTPClient.swift

-106
Original file line numberDiff line numberDiff line change
@@ -197,26 +197,6 @@ public class HTTPClient {
197197
return self.execute(url: url, method: .GET, deadline: deadline)
198198
}
199199

200-
/// Execute `GET` request to a unix domain socket path, using the specified URL as the request to send to the server.
201-
///
202-
/// - parameters:
203-
/// - socketPath: The path to the unix domain socket to connect to.
204-
/// - url: The URL path and query that will be sent to the server.
205-
/// - deadline: Point in time by which the request must complete.
206-
public func get(socketPath: String, url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
207-
return self.execute(socketPath: socketPath, url: url, method: .GET, deadline: deadline)
208-
}
209-
210-
/// Execute `GET` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
211-
///
212-
/// - parameters:
213-
/// - secureSocketPath: The path to the unix domain socket to connect to.
214-
/// - url: The URL path and query that will be sent to the server.
215-
/// - deadline: Point in time by which the request must complete.
216-
public func get(secureSocketPath: String, url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
217-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .GET, deadline: deadline)
218-
}
219-
220200
/// Execute `POST` request using specified URL.
221201
///
222202
/// - parameters:
@@ -227,28 +207,6 @@ public class HTTPClient {
227207
return self.execute(url: url, method: .POST, body: body, deadline: deadline)
228208
}
229209

230-
/// Execute `POST` request to a unix domain socket path, using the specified URL as the request to send to the server.
231-
///
232-
/// - parameters:
233-
/// - socketPath: The path to the unix domain socket to connect to.
234-
/// - url: The URL path and query that will be sent to the server.
235-
/// - body: Request body.
236-
/// - deadline: Point in time by which the request must complete.
237-
public func post(socketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
238-
return self.execute(socketPath: socketPath, url: url, method: .POST, body: body, deadline: deadline)
239-
}
240-
241-
/// Execute `POST` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
242-
///
243-
/// - parameters:
244-
/// - secureSocketPath: The path to the unix domain socket to connect to.
245-
/// - url: The URL path and query that will be sent to the server.
246-
/// - body: Request body.
247-
/// - deadline: Point in time by which the request must complete.
248-
public func post(secureSocketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
249-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .POST, body: body, deadline: deadline)
250-
}
251-
252210
/// Execute `PATCH` request using specified URL.
253211
///
254212
/// - parameters:
@@ -259,28 +217,6 @@ public class HTTPClient {
259217
return self.execute(url: url, method: .PATCH, body: body, deadline: deadline)
260218
}
261219

262-
/// Execute `PATCH` request to a unix domain socket path, using the specified URL as the request to send to the server.
263-
///
264-
/// - parameters:
265-
/// - socketPath: The path to the unix domain socket to connect to.
266-
/// - url: The URL path and query that will be sent to the server.
267-
/// - body: Request body.
268-
/// - deadline: Point in time by which the request must complete.
269-
public func patch(socketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
270-
return self.execute(socketPath: socketPath, url: url, method: .PATCH, body: body, deadline: deadline)
271-
}
272-
273-
/// Execute `PATCH` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
274-
///
275-
/// - parameters:
276-
/// - secureSocketPath: The path to the unix domain socket to connect to.
277-
/// - url: The URL path and query that will be sent to the server.
278-
/// - body: Request body.
279-
/// - deadline: Point in time by which the request must complete.
280-
public func patch(secureSocketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
281-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .PATCH, body: body, deadline: deadline)
282-
}
283-
284220
/// Execute `PUT` request using specified URL.
285221
///
286222
/// - parameters:
@@ -291,28 +227,6 @@ public class HTTPClient {
291227
return self.execute(url: url, method: .PUT, body: body, deadline: deadline)
292228
}
293229

294-
/// Execute `PUT` request to a unix domain socket path, using the specified URL as the request to send to the server.
295-
///
296-
/// - parameters:
297-
/// - socketPath: The path to the unix domain socket to connect to.
298-
/// - url: The URL path and query that will be sent to the server.
299-
/// - body: Request body.
300-
/// - deadline: Point in time by which the request must complete.
301-
public func put(socketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
302-
return self.execute(socketPath: socketPath, url: url, method: .PUT, body: body, deadline: deadline)
303-
}
304-
305-
/// Execute `PUT` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
306-
///
307-
/// - parameters:
308-
/// - secureSocketPath: The path to the unix domain socket to connect to.
309-
/// - url: The URL path and query that will be sent to the server.
310-
/// - body: Request body.
311-
/// - deadline: Point in time by which the request must complete.
312-
public func put(secureSocketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
313-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .PUT, body: body, deadline: deadline)
314-
}
315-
316230
/// Execute `DELETE` request using specified URL.
317231
///
318232
/// - parameters:
@@ -322,26 +236,6 @@ public class HTTPClient {
322236
return self.execute(url: url, method: .DELETE, deadline: deadline)
323237
}
324238

325-
/// Execute `DELETE` request to a unix domain socket path, using the specified URL as the request to send to the server.
326-
///
327-
/// - parameters:
328-
/// - socketPath: The path to the unix domain socket to connect to.
329-
/// - url: The URL path and query that will be sent to the server.
330-
/// - deadline: The time when the request must have been completed by.
331-
public func delete(socketPath: String, url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
332-
return self.execute(socketPath: socketPath, url: url, method: .DELETE, deadline: deadline)
333-
}
334-
335-
/// Execute `DELETE` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
336-
///
337-
/// - parameters:
338-
/// - secureSocketPath: The path to the unix domain socket to connect to.
339-
/// - url: The URL path and query that will be sent to the server.
340-
/// - deadline: The time when the request must have been completed by.
341-
public func delete(secureSocketPath: String, url: String, deadline: NIODeadline? = nil) -> EventLoopFuture<Response> {
342-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .DELETE, deadline: deadline)
343-
}
344-
345239
/// Execute arbitrary HTTP request using specified URL.
346240
///
347241
/// - parameters:

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+4-20
Original file line numberDiff line numberDiff line change
@@ -223,17 +223,9 @@ class HTTPClientTests: XCTestCase {
223223
}
224224

225225
XCTAssertNoThrow(XCTAssertEqual(["GET"[...]],
226-
try self.defaultClient.get(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
226+
try self.defaultClient.execute(socketPath: path, url: "echo-method", method: .GET).wait().headers[canonicalForm: "X-Method-Used"]))
227227
XCTAssertNoThrow(XCTAssertEqual(["POST"[...]],
228-
try self.defaultClient.post(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
229-
XCTAssertNoThrow(XCTAssertEqual(["PATCH"[...]],
230-
try self.defaultClient.patch(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
231-
XCTAssertNoThrow(XCTAssertEqual(["PUT"[...]],
232-
try self.defaultClient.put(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
233-
XCTAssertNoThrow(XCTAssertEqual(["DELETE"[...]],
234-
try self.defaultClient.delete(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
235-
XCTAssertNoThrow(XCTAssertEqual(["CHECKOUT"[...]],
236-
try self.defaultClient.execute(socketPath: path, url: "echo-method", method: .CHECKOUT).wait().headers[canonicalForm: "X-Method-Used"]))
228+
try self.defaultClient.execute(socketPath: path, url: "echo-method", method: .POST).wait().headers[canonicalForm: "X-Method-Used"]))
237229
})
238230
}
239231

@@ -248,17 +240,9 @@ class HTTPClientTests: XCTestCase {
248240
}
249241

250242
XCTAssertNoThrow(XCTAssertEqual(["GET"[...]],
251-
try localClient.get(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
243+
try localClient.execute(secureSocketPath: path, url: "echo-method", method: .GET).wait().headers[canonicalForm: "X-Method-Used"]))
252244
XCTAssertNoThrow(XCTAssertEqual(["POST"[...]],
253-
try localClient.post(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
254-
XCTAssertNoThrow(XCTAssertEqual(["PATCH"[...]],
255-
try localClient.patch(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
256-
XCTAssertNoThrow(XCTAssertEqual(["PUT"[...]],
257-
try localClient.put(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
258-
XCTAssertNoThrow(XCTAssertEqual(["DELETE"[...]],
259-
try localClient.delete(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
260-
XCTAssertNoThrow(XCTAssertEqual(["CHECKOUT"[...]],
261-
try localClient.execute(secureSocketPath: path, url: "echo-method", method: .CHECKOUT).wait().headers[canonicalForm: "X-Method-Used"]))
245+
try localClient.execute(secureSocketPath: path, url: "echo-method", method: .POST).wait().headers[canonicalForm: "X-Method-Used"]))
262246
})
263247
}
264248

0 commit comments

Comments
 (0)