Skip to content

Commit 10b0e01

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 f314a6f commit 10b0e01

File tree

3 files changed

+6
-138
lines changed

3 files changed

+6
-138
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

-116
Original file line numberDiff line numberDiff line change
@@ -240,28 +240,6 @@ public class HTTPClient {
240240
return self.execute(url: url, method: .GET, deadline: deadline, logger: logger)
241241
}
242242

243-
/// Execute `GET` request to a unix domain socket path, using the specified URL as the request to send to the server.
244-
///
245-
/// - parameters:
246-
/// - socketPath: The path to the unix domain socket to connect to.
247-
/// - url: The URL path and query that will be sent to the server.
248-
/// - deadline: Point in time by which the request must complete.
249-
/// - logger: The logger to use for this request.
250-
public func get(socketPath: String, url: String, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
251-
return self.execute(socketPath: socketPath, url: url, method: .GET, deadline: deadline, logger: logger)
252-
}
253-
254-
/// Execute `GET` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
255-
///
256-
/// - parameters:
257-
/// - secureSocketPath: The path to the unix domain socket to connect to.
258-
/// - url: The URL path and query that will be sent to the server.
259-
/// - deadline: Point in time by which the request must complete.
260-
/// - logger: The logger to use for this request.
261-
public func get(secureSocketPath: String, url: String, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
262-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .GET, deadline: deadline, logger: logger)
263-
}
264-
265243
/// Execute `POST` request using specified URL.
266244
///
267245
/// - parameters:
@@ -283,30 +261,6 @@ public class HTTPClient {
283261
return self.execute(url: url, method: .POST, body: body, deadline: deadline, logger: logger)
284262
}
285263

286-
/// Execute `POST` request to a unix domain socket path, using the specified URL as the request to send to the server.
287-
///
288-
/// - parameters:
289-
/// - socketPath: The path to the unix domain socket to connect to.
290-
/// - url: The URL path and query that will be sent to the server.
291-
/// - body: Request body.
292-
/// - deadline: Point in time by which the request must complete.
293-
/// - logger: The logger to use for this request.
294-
public func post(socketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
295-
return self.execute(socketPath: socketPath, url: url, method: .POST, body: body, deadline: deadline, logger: logger)
296-
}
297-
298-
/// Execute `POST` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
299-
///
300-
/// - parameters:
301-
/// - secureSocketPath: The path to the unix domain socket to connect to.
302-
/// - url: The URL path and query that will be sent to the server.
303-
/// - body: Request body.
304-
/// - deadline: Point in time by which the request must complete.
305-
/// - logger: The logger to use for this request.
306-
public func post(secureSocketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
307-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .POST, body: body, deadline: deadline, logger: logger)
308-
}
309-
310264
/// Execute `PATCH` request using specified URL.
311265
///
312266
/// - parameters:
@@ -328,30 +282,6 @@ public class HTTPClient {
328282
return self.execute(url: url, method: .PATCH, body: body, deadline: deadline, logger: logger)
329283
}
330284

331-
/// Execute `PATCH` request to a unix domain socket path, using the specified URL as the request to send to the server.
332-
///
333-
/// - parameters:
334-
/// - socketPath: The path to the unix domain socket to connect to.
335-
/// - url: The URL path and query that will be sent to the server.
336-
/// - body: Request body.
337-
/// - deadline: Point in time by which the request must complete.
338-
/// - logger: The logger to use for this request.
339-
public func patch(socketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
340-
return self.execute(socketPath: socketPath, url: url, method: .PATCH, body: body, deadline: deadline, logger: logger)
341-
}
342-
343-
/// Execute `PATCH` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
344-
///
345-
/// - parameters:
346-
/// - secureSocketPath: The path to the unix domain socket to connect to.
347-
/// - url: The URL path and query that will be sent to the server.
348-
/// - body: Request body.
349-
/// - deadline: Point in time by which the request must complete.
350-
/// - logger: The logger to use for this request.
351-
public func patch(secureSocketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
352-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .PATCH, body: body, deadline: deadline, logger: logger)
353-
}
354-
355285
/// Execute `PUT` request using specified URL.
356286
///
357287
/// - parameters:
@@ -373,30 +303,6 @@ public class HTTPClient {
373303
return self.execute(url: url, method: .PUT, body: body, deadline: deadline, logger: logger)
374304
}
375305

376-
/// Execute `PUT` request to a unix domain socket path, using the specified URL as the request to send to the server.
377-
///
378-
/// - parameters:
379-
/// - socketPath: The path to the unix domain socket to connect to.
380-
/// - url: The URL path and query that will be sent to the server.
381-
/// - body: Request body.
382-
/// - deadline: Point in time by which the request must complete.
383-
/// - logger: The logger to use for this request.
384-
public func put(socketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
385-
return self.execute(socketPath: socketPath, url: url, method: .PUT, body: body, deadline: deadline, logger: logger)
386-
}
387-
388-
/// Execute `PUT` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
389-
///
390-
/// - parameters:
391-
/// - secureSocketPath: The path to the unix domain socket to connect to.
392-
/// - url: The URL path and query that will be sent to the server.
393-
/// - body: Request body.
394-
/// - deadline: Point in time by which the request must complete.
395-
/// - logger: The logger to use for this request.
396-
public func put(secureSocketPath: String, url: String, body: Body? = nil, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
397-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .PUT, body: body, deadline: deadline, logger: logger)
398-
}
399-
400306
/// Execute `DELETE` request using specified URL.
401307
///
402308
/// - parameters:
@@ -416,28 +322,6 @@ public class HTTPClient {
416322
return self.execute(url: url, method: .DELETE, deadline: deadline, logger: logger)
417323
}
418324

419-
/// Execute `DELETE` request to a unix domain socket path, using the specified URL as the request to send to the server.
420-
///
421-
/// - parameters:
422-
/// - socketPath: The path to the unix domain socket to connect to.
423-
/// - url: The URL path and query that will be sent to the server.
424-
/// - deadline: The time when the request must have been completed by.
425-
/// - logger: The logger to use for this request.
426-
public func delete(socketPath: String, url: String, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
427-
return self.execute(socketPath: socketPath, url: url, method: .DELETE, deadline: deadline, logger: logger)
428-
}
429-
430-
/// Execute `DELETE` request to a unix domain socket path over TLS, using the specified URL as the request to send to the server.
431-
///
432-
/// - parameters:
433-
/// - secureSocketPath: The path to the unix domain socket to connect to.
434-
/// - url: The URL path and query that will be sent to the server.
435-
/// - deadline: The time when the request must have been completed by.
436-
/// - logger: The logger to use for this request.
437-
public func delete(secureSocketPath: String, url: String, deadline: NIODeadline? = nil, logger: Logger? = nil) -> EventLoopFuture<Response> {
438-
return self.execute(secureSocketPath: secureSocketPath, url: url, method: .DELETE, deadline: deadline, logger: logger)
439-
}
440-
441325
/// Execute arbitrary HTTP request using specified URL.
442326
///
443327
/// - parameters:

Diff for: Tests/AsyncHTTPClientTests/HTTPClientTests.swift

+4-20
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,9 @@ class HTTPClientTests: XCTestCase {
237237
}
238238

239239
XCTAssertNoThrow(XCTAssertEqual(["GET"[...]],
240-
try self.defaultClient.get(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
240+
try self.defaultClient.execute(socketPath: path, url: "echo-method", method: .GET).wait().headers[canonicalForm: "X-Method-Used"]))
241241
XCTAssertNoThrow(XCTAssertEqual(["POST"[...]],
242-
try self.defaultClient.post(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
243-
XCTAssertNoThrow(XCTAssertEqual(["PATCH"[...]],
244-
try self.defaultClient.patch(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
245-
XCTAssertNoThrow(XCTAssertEqual(["PUT"[...]],
246-
try self.defaultClient.put(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
247-
XCTAssertNoThrow(XCTAssertEqual(["DELETE"[...]],
248-
try self.defaultClient.delete(socketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
249-
XCTAssertNoThrow(XCTAssertEqual(["CHECKOUT"[...]],
250-
try self.defaultClient.execute(socketPath: path, url: "echo-method", method: .CHECKOUT).wait().headers[canonicalForm: "X-Method-Used"]))
242+
try self.defaultClient.execute(socketPath: path, url: "echo-method", method: .POST).wait().headers[canonicalForm: "X-Method-Used"]))
251243
})
252244
}
253245

@@ -262,17 +254,9 @@ class HTTPClientTests: XCTestCase {
262254
}
263255

264256
XCTAssertNoThrow(XCTAssertEqual(["GET"[...]],
265-
try localClient.get(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
257+
try localClient.execute(secureSocketPath: path, url: "echo-method", method: .GET).wait().headers[canonicalForm: "X-Method-Used"]))
266258
XCTAssertNoThrow(XCTAssertEqual(["POST"[...]],
267-
try localClient.post(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
268-
XCTAssertNoThrow(XCTAssertEqual(["PATCH"[...]],
269-
try localClient.patch(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
270-
XCTAssertNoThrow(XCTAssertEqual(["PUT"[...]],
271-
try localClient.put(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
272-
XCTAssertNoThrow(XCTAssertEqual(["DELETE"[...]],
273-
try localClient.delete(secureSocketPath: path, url: "echo-method").wait().headers[canonicalForm: "X-Method-Used"]))
274-
XCTAssertNoThrow(XCTAssertEqual(["CHECKOUT"[...]],
275-
try localClient.execute(secureSocketPath: path, url: "echo-method", method: .CHECKOUT).wait().headers[canonicalForm: "X-Method-Used"]))
259+
try localClient.execute(secureSocketPath: path, url: "echo-method", method: .POST).wait().headers[canonicalForm: "X-Method-Used"]))
276260
})
277261
}
278262

0 commit comments

Comments
 (0)