Skip to content

Commit 93f776e

Browse files
committed
Provide method as parameter option
1 parent dbdd226 commit 93f776e

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

lib/ld-eventsource/client.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ class Client
8484
# @param socket_factory [#open] (nil) an optional factory object for creating sockets,
8585
# if you want to use something other than the default `TCPSocket`; it must implement
8686
# `open(uri, timeout)` to return a connected `Socket`
87-
# @yieldparam [Client] client the new client instance, before opening the connection
88-
# @payload payload [String | Hash | Array] (nil) optional request payload. If payload is
89-
# provided, a POST request will be used, instead of a GET request. If payload is a Hash or
87+
# @param method [String] ("GET") the HTTP method to use for requests
88+
# @param payload [String, Hash, Array] (nil) optional request payload. If payload is a Hash or
9089
# an Array, it will be converted to JSON and sent as the request body. Also, reconnection
9190
# is disabled if payload is set.
91+
# @yieldparam [Client] client the new client instance, before opening the connection
9292
#
9393
def initialize(uri,
9494
headers: {},
@@ -100,13 +100,15 @@ def initialize(uri,
100100
proxy: nil,
101101
logger: nil,
102102
socket_factory: nil,
103+
method: "GET",
103104
payload: nil)
104105
@uri = URI(uri)
105106
@stopped = Concurrent::AtomicBoolean.new(false)
106107

107108
@headers = headers.clone
108109
@connect_timeout = connect_timeout
109110
@read_timeout = read_timeout
111+
@method = method.to_s.upcase
110112
@payload = payload
111113
@logger = logger || default_logger
112114
http_client_options = {}
@@ -270,8 +272,7 @@ def connect
270272
cxn = nil
271273
begin
272274
@logger.info { "Connecting to event stream at #{@uri}" }
273-
verb = @payload ? "POST" : "GET"
274-
cxn = @http_client.request(verb, @uri, build_opts)
275+
cxn = @http_client.request(@method, @uri, build_opts)
275276
if cxn.status.code == 200
276277
content_type = cxn.content_type.mime_type
277278
if content_type && content_type.start_with?("text/event-stream")

0 commit comments

Comments
 (0)