Copyright © 2007, 2008 Scott Parish <srp@srparish.net>
Authors: Scott Parish (srp@srparish.net).
This module provides functions for detecting, reading, and writing HTTP bodies and encodings such as chunking.
If you try to do chunked writes for a pre-http-1.1 client, this module will do it by falling back to writing a streamed body with nocontent-length. Obviously the connection has to be closed to
end the data stream. This means you can using a stream to
incrementally generate a webpage, or write out a large file, and
browsers such as w3m and lynx will still be able to work fine.
| done_writing/1 | Writing the closing chunk. |
| done_writing/2 | Writing the Trailers and the closing chunk. |
| has_body/1 | Does this request have a body that needs to be read? It determins
this by checking for content-length or transfer-encoding headers. |
| new_reader/1 | Return a new chunk reader. |
| new_writer/1 | Return a new chunk writer. |
| read/1 | Read and return the next available chunk. |
| read/2 | Read and return Len bytes. |
| read_all/1 | Read and return the full body. |
| with_writer/2 | Call F(Writer) with a new writer, automatically closing the
writer when F returns, and writing an error message if F throws
an exception. |
| write/2 | Write a chunk of data. |
done_writing(Crary_req::crary:crary_req()) -> ok
Writing the closing chunk. For pre-http-1.1 streaming this also closes the socket.
done_writing(Req::crary:crary_req(), Trailers::crary_headers:headerish()) -> ok
Writing the Trailers and the closing chunk.
has_body(Req::crary:crary_req()) -> bool()
Does this request have a body that needs to be read? It determins
this by checking for content-length or transfer-encoding headers.
new_reader(Req::crary:crary_req()) -> pid()
Return a new chunk reader.
new_writer(Req::crary:crary_req()) -> pid()
Return a new chunk writer.
It may be observed that currently this call just returns the sameReq that was passed to it. Don't depend on this, it will likely
be changed to a pid() or similar in the future for supporting
buffering or other encodings.
See also: with_writer/2, crary:r/4.
read(S::pid()) -> binary()
Read and return the next available chunk.
read(S::pid(), Len::integer()) -> binary()
Read and return Len bytes.
read_all(Req::crary:crary_req()) -> binary()
Read and return the full body. It doesn't matter if the body
is chunked or fixed length, this will read it all in and return it
as one binary. Probably great for PUT bodies for forms. Probably
not great for reading in a large amount of data.
with_writer(Req::crary:crary_req(), F::function()) -> pid()
Call F(Writer) with a new writer, automatically closing the
writer when F returns, and writing an error message if F throws
an exception.
F to keep
errors from making it down the stack to here.
write(Req::crary:crary_req(), Data::iolist()) -> ok
Write a chunk of data. At the moment, this data is immediately written as a chunk, regardless of the size. In the future writes may get buffered, probably with a configurable buffer size.
Generated by EDoc, Mar 14 2008, 22:35:53.