Elixir plug.conn download file






















These fields contain response information:. It is set. The response. Note, response headers. Connection fields. This data must be kept in the connection and never used directly, always. The connection state is used to track the connection lifecycle.

It starts as. Private fields. Custom status codes. Plug allows status codes to be overridden or added in order to allow new codes. Adding or overriding a status. As this configuration is Plug specific, Plug will need to be recompiled for. To recompile. The atoms that can be used in place of the status code in many functions are. With the above. Error raised when no response is sent in a request. Error raised when trying to modify or send an already sent response.

Error raised when the cookie exceeds the maximum size of bytes. Error raised when trying to send a header that has errors, for example:. Raised when the request string is malformed, for example:. Assigns a value to a key in the connection. The "assigns" storage is meant to be used to store values in the connection.

The assigns storage. Assigns multiple values to keys in the connection. This storage is meant to be used by libraries and frameworks to avoid writing. It is recommended for. Stores the given status code in the connection. The list of allowed. Sends a response to the client. Note that this function does not halt the connection, so if. If available, the file is sent directly over the socket using.

Sends the response headers as a chunked response. Sends a chunk as part of a chunked response. Sends a response with the given status and body. This is equivalent to setting the status and the body and then. Returns the request peer data if one is present. Returns the HTTP protocol and version. Deletes a request header if present.

Updates a request header if present, otherwise it sets it to an initial. Prepends the list of headers to the connection response headers. It is recommended for header keys to be in lowercase, to avoid sending. Merges a series of response headers into the connection. Deletes a response header if present. Updates a response header if present, otherwise it sets it to an initial.

Fetches query parameters from the query string. This function does not fetch parameters from the body. To fetch. Because it might be, that it is not even a Stream in elixirs understanding of the word.

The documentation claims to use the kernels sendfile if available. In theory the most efficient way to get the file from disk to socket, as this is a kernel native operation. The BEAM process that handles your request, wont get scheduled anymore until the sendfile has been finished.

Judging what you want to achieve, i. It instructs Cowboy to send the file to client, and it will be done in efficient manner, reading parts of the file from disk and sending it to the client as it receives previous parts.

This should be good enough to do basic video player for example. This may not be good enough if you want to do some smart buffering, i. But for basic streaming it will be enough and efficient enough.

I just tested it with png file. I understand phoenix handle my request but it is auto, not with custom chunked file size. There bug in Cowboy 2. The status can be an integer, an atom, or nil. See Plug. Status for more information. It expects a connection that has not been :sent yet and sets its state to :chunked afterwards. Otherwise, raises Plug.

If available, the file is sent directly over the socket using the operating system sendfile operation. It expects a connection that has not been :sent yet and sets its state to :file afterwards. Otherwise raises Plug. It expects the connection state to be :set , otherwise raises an ArgumentError for :unset connections or a Plug. AlreadySentError for already :sent connections. Note that this function does not halt the connection, so if subsequent plugs try to send another response, it will error out.

Plug v1. Conn Plug v1. Request fields These fields contain request information: host - the requested host as a binary, example: "www. This field is meant to be overwritten by plugs that understand e. Parsers parser. It is set to nil after the response is sent, except for test connections. The response charset used defaults to "utf-8". Note, response headers are expected to have lowercase keys. This data must be kept in the connection and never used directly, always use Plug.

To recompile Plug: mix deps. Link to this section Summary Types adapter. Functions assign conn, key, value. Fetches the session from the session store. Will also fetch cookies. Returns the values of the request header specified by key. Returns the values of the response header specified by key. Sends an information response to a client but raises if the adapter does not support inform. Assigns multiple private keys and values in the connection. Prepends the list of headers to the connection response headers.

Pushes a resource to the client but raises if the adapter does not support server push. Assigns a new private key and value in the connection. Registers a callback to be invoked before the response is sent. Updates a request header if present, otherwise it sets it to an initial value.

Updates a response header if present, otherwise it sets it to an initial value. Link to this type adapter View Source. Link to this type assigns View Source. Link to this type body View Source. Link to this type cookies View Source. Link to this type halted View Source. Link to this type headers View Source. Link to this type host View Source. Link to this type method View Source.



0コメント

  • 1000 / 1000