@@ -83,6 +83,8 @@ defmodule Mint.HTTP1 do
8383 """
8484 @ type error_reason ( ) :: term ( )
8585
86+ @ optional_responses_opts [ :status_reason ]
87+
8688 defstruct [
8789 :host ,
8890 :port ,
@@ -130,10 +132,11 @@ defmodule Mint.HTTP1 do
130132 conforming URIs but need to preserve them. The default is to validate the request
131133 target. *Available since v1.7.0*.
132134 * `:optional_responses` - (list of atoms) a list of optional responses to return.
133- The possible values in the list are `:status_reason` which will return the
134- [reason-phrase](https://datatracker.ietf.org/doc/html/rfc9112#name-status-line)
135- for the status code, if it is returned by the server in status-line.
136- This is only available for HTTP/1.1 connections. *Available since v1.7.2*.
135+ The possible values in the list are -
136+ * `:status_reason` which will return the
137+ [reason-phrase](https://datatracker.ietf.org/doc/html/rfc9112#name-status-line)
138+ for the status code, if it is returned by the server in status-line.
139+ This is only available for HTTP/1.1 connections. *Available since v1.7.2*.
137140
138141 """
139142 @ spec connect ( Types . scheme ( ) , Types . address ( ) , :inet . port_number ( ) , keyword ( ) ) ::
@@ -213,7 +216,7 @@ defmodule Mint.HTTP1 do
213216 log: log? ,
214217 case_sensitive_headers: Keyword . get ( opts , :case_sensitive_headers , false ) ,
215218 skip_target_validation: Keyword . get ( opts , :skip_target_validation , false ) ,
216- optional_responses: Keyword . get ( opts , :optional_responses , [ ] )
219+ optional_responses: validate_optional_response_values ( opts )
217220 }
218221
219222 { :ok , conn }
@@ -224,6 +227,21 @@ defmodule Mint.HTTP1 do
224227 end
225228 end
226229
230+ defp validate_optional_response_values ( opts ) do
231+ opts
232+ |> Keyword . get ( :optional_responses , [ ] )
233+ |> Enum . map ( fn opt ->
234+ if opt not in @ optional_responses_opts do
235+ raise ArgumentError , """
236+ invalid :optional_responses value #{ opt } .
237+ allowed values are - #{ inspect ( @ optional_responses_opts ) }
238+ """
239+ end
240+
241+ opt
242+ end )
243+ end
244+
227245 @ doc """
228246 See `Mint.HTTP.close/1`.
229247 """
0 commit comments