Skip to content

Commit 80d8b6c

Browse files
committed
Accept request options for all http methods
Before this PR, this was only done for http_post as a workaround to allow disabling the automatic JSON conversion of "body" to support CSV, NDJSON, and possible other future payload types. This must be done for at least http_put at least, since there are update_* methods to go along with the add_* methods for the various payload types. I added the option to all of the http methods to prevent any future surprises.
1 parent 259abfe commit 80d8b6c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

lib/meilisearch/http_request.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ def initialize(url, api_key = nil, options = {})
2222
@headers = build_default_options_headers
2323
end
2424

25-
def http_get(relative_path = '', query_params = {})
25+
def http_get(relative_path = '', query_params = {}, options = {})
2626
send_request(
2727
proc { |path, config| self.class.get(path, config) },
2828
relative_path,
2929
config: {
3030
query_params: query_params,
31-
headers: remove_headers(@headers.dup, 'Content-Type'),
32-
options: @options
31+
headers: remove_headers(@headers.dup.merge(options[:headers] || {}), 'Content-Type'),
32+
options: @options.merge(options)
3333
}
3434
)
3535
end
@@ -47,40 +47,40 @@ def http_post(relative_path = '', body = nil, query_params = nil, options = {})
4747
)
4848
end
4949

50-
def http_put(relative_path = '', body = nil, query_params = nil)
50+
def http_put(relative_path = '', body = nil, query_params = nil, options = {})
5151
send_request(
5252
proc { |path, config| self.class.put(path, config) },
5353
relative_path,
5454
config: {
5555
query_params: query_params,
5656
body: body,
57-
headers: @headers,
58-
options: @options
57+
headers: @headers.dup.merge(options[:headers] || {}),
58+
options: @options.merge(options)
5959
}
6060
)
6161
end
6262

63-
def http_patch(relative_path = '', body = nil, query_params = nil)
63+
def http_patch(relative_path = '', body = nil, query_params = nil, options = {})
6464
send_request(
6565
proc { |path, config| self.class.patch(path, config) },
6666
relative_path,
6767
config: {
6868
query_params: query_params,
6969
body: body,
70-
headers: @headers,
71-
options: @options
70+
headers: @headers.dup.merge(options[:headers] || {}),
71+
options: @options.merge(options)
7272
}
7373
)
7474
end
7575

76-
def http_delete(relative_path = '', query_params = nil)
76+
def http_delete(relative_path = '', query_params = nil, options = {})
7777
send_request(
7878
proc { |path, config| self.class.delete(path, config) },
7979
relative_path,
8080
config: {
8181
query_params: query_params,
82-
headers: remove_headers(@headers.dup, 'Content-Type'),
83-
options: @options
82+
headers: remove_headers(@headers.dup.merge(options[:headers] || {}), 'Content-Type'),
83+
options: @options.merge(options)
8484
}
8585
)
8686
end

0 commit comments

Comments
 (0)