Skip to content

Commit 76db5ed

Browse files
mruosswhatyouhide
andauthored
Clarify the "type" parameter of Mint.HTTP.open?/2 (#411)
Co-authored-by: Andrea Leopardi <[email protected]>
1 parent aba76a7 commit 76db5ed

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

lib/mint/http.ex

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -496,20 +496,28 @@ defmodule Mint.HTTP do
496496
@doc """
497497
Checks whether the connection is open.
498498
499-
This function returns `true` if the connection is open, `false` otherwise. It should
500-
be used to check that a connection is open before sending requests or performing
501-
operations that involve talking to the server.
502-
503-
The `type` argument can be used to tell whether the connection is closed only for reading,
504-
only for writing, or for both. In HTTP/1, a closed connection is always closed for
505-
both reading and writing. In HTTP/2, the connection can be closed only for writing but
506-
not for reading, meaning that you cannot send any more data to the server but you can
507-
still receive data from the server. See the "Closed connection" section in the module
508-
documentation of `Mint.HTTP2`.
509-
510-
If a connection is not open for reading and writing, it has become useless and you should
511-
get rid of it. If you still need a connection to the server, start a new connection
512-
with `connect/4`.
499+
This function returns `true` if the connection is open for the given `type`,
500+
`false` otherwise. It should be used to check that a connection is open before
501+
sending requests or performing operations that involve talking to the server.
502+
503+
The `type` argument can be used to tell whether the connection is open for both reading
504+
and writing, only open for reading, or closed for both. In HTTP/1, a connection is always
505+
either open, or closed (for both reading and writing). In HTTP/2, the connection can be closed only
506+
for writing but not for reading, meaning that you cannot send any more data to the
507+
server but you can still receive data from the server. In this case, `Mint.HTTP.open?(conn, :read)`
508+
would return `true` but `Mint.HTTP.open?(conn, :read_write)` would return `false`.
509+
See the "Closed connection" section in the module documentation of `Mint.HTTP2`.
510+
511+
If a connection is *completely closed* (that is, `Mint.HTTP.open?(conn, :read)` returns `false`),
512+
it has become useless and you should get rid of it. If you still need a connection
513+
to the server, start a new connection with `connect/4`.
514+
515+
> #### The default value of `type` is `:read_write` {: .warning}
516+
>
517+
> With the default value of `type` being `:read_write`, a call to
518+
> `Mint.HTTP.open?(conn)` will return `false` if `conn` was closed for writing
519+
> but is still open for reading. If you need to make sure the connection is
520+
> completely closed, check that `Mint.HTTP.open?(conn, :read)` returns `false`.
513521
514522
## Examples
515523

0 commit comments

Comments
 (0)