Skip to content

Commit 0fd0a4e

Browse files
committed
refactor: Rename Request struct fields for clarity
- Renamed to for 3rd httpc argument (request-specific) - Renamed to for 4th httpc argument (client-specific) - Updated all type specifications and documentation comments - Updated HTTP.fetch/2 to use new field names - Updated Request.to_httpc_args/1 to use new field mapping - Updated tests to use new field names This change makes the field names more intuitive and aligns them with: - : HTTP-specific options (timeout, SSL, redirects, etc.) - : General client options (sync, body_format, streaming, etc.) Maintains full backward compatibility while improving code clarity.
1 parent 3263669 commit 0fd0a4e

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

lib/http.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ defmodule HTTP do
172172
headers: HTTP.FetchOptions.get_headers(options),
173173
body: HTTP.FetchOptions.get_body(options),
174174
content_type: HTTP.FetchOptions.get_content_type(options),
175-
# Maps to Request.options (3rd arg for :httpc.request)
176-
options: options.options,
177-
# Maps to Request.opts (4th arg for :httpc.request)
178-
opts: Keyword.merge(Request.__struct__().opts, options.opts)
175+
# Maps to Request.http_options (3rd arg for :httpc.request)
176+
http_options: options.options,
177+
# Maps to Request.options (4th arg for :httpc.request)
178+
options: Keyword.merge(Request.__struct__().options, options.opts)
179179
}
180180

181181
# Extract AbortController PID from FetchOptions

lib/http/request.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ defmodule HTTP.Request do
33
Represents an HTTP request that can be serialized into :httpc.request arguments.
44
"""
55

6-
# Note: `options` are for the 3rd argument of :httpc.request (request-specific options like timeout).
7-
# `opts` are for the 4th argument of :httpc.request (client-specific options like sync/body_format).
6+
# Note: `http_options` are for the 3rd argument of :httpc.request (request-specific options like timeout).
7+
# `options` are for the 4th argument of :httpc.request (client-specific options like sync/body_format).
88
defstruct method: :get,
99
url: nil,
1010
headers: %HTTP.Headers{},
1111
# Separate field for Content-Type header
1212
content_type: nil,
1313
body: nil,
1414
# HTTPC request options (e.g., timeout)
15-
options: [],
16-
opts: [sync: false]
15+
http_options: [],
16+
options: [sync: false]
1717

1818
@type method :: :head | :get | :post | :put | :delete | :patch
1919
@type url :: URI.t()
@@ -28,8 +28,8 @@ defmodule HTTP.Request do
2828
headers: HTTP.Headers.t(),
2929
content_type: content_type,
3030
body: body_content,
31-
options: httpc_options,
32-
opts: httpc_client_opts
31+
http_options: httpc_options,
32+
options: httpc_client_opts
3333
}
3434

3535
@doc """
@@ -73,7 +73,7 @@ defmodule HTTP.Request do
7373
{url, headers, content_type, body_content}
7474
end
7575

76-
[method, request_tuple, req.options, req.opts]
76+
[method, request_tuple, req.http_options, req.options]
7777
end
7878

7979
@spec to_body(body_content()) :: charlist()

test/http/request_test.exs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ defmodule HTTP.RequestTest do
77
request = %HTTP.Request{}
88
assert request.method == :get
99
assert %HTTP.Headers{headers: []} = request.headers
10-
assert request.options == []
10+
assert request.http_options == []
11+
assert request.options == [sync: false]
1112
end
1213

1314
test "create request with custom values" do
@@ -34,7 +35,7 @@ defmodule HTTP.RequestTest do
3435
headers: HTTP.Headers.new([{"Accept", "application/json"}])
3536
}
3637

37-
[method, request_tuple, _options, _opts] = HTTP.Request.to_httpc_args(request)
38+
[method, request_tuple, _http_options, _options] = HTTP.Request.to_httpc_args(request)
3839
assert method == :get
3940
assert request_tuple == {~c"http://example.com", [{~c"Accept", ~c"application/json"}]}
4041
end

0 commit comments

Comments
 (0)