From 7728c624028db160edad2646f34d069d16af0869 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Wed, 15 Nov 2017 14:32:51 +0100 Subject: Add support for chunked transfer-encoding trailers It considers all 0-sized chunks that aren't \r\n\r\n to be trailers. There's no option for enabling/disabling the behavior (for example when the te header was sent). It doesn't parse the trailer, it's up to the user to parse it separately via the new cow_http:headers/1 functions. Note that this reuses the TotalLength part of the returned 'done' tuple to signal whether there are trailers. This value has been ignored in Cowboy since 2.0 and was just a historical leftover. I'm not aware of anyone using this module outside of Gun or Cowboy, so I don't expect this to break anything. If it does, well, it's not a documented function anyway. Your fault. --- src/cow_http.erl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/cow_http.erl') diff --git a/src/cow_http.erl b/src/cow_http.erl index de079ea..85b5d7a 100644 --- a/src/cow_http.erl +++ b/src/cow_http.erl @@ -23,6 +23,7 @@ -export([request/4]). -export([response/3]). +-export([headers/1]). -export([version/1]). -type version() :: 'HTTP/1.0' | 'HTTP/1.1'. @@ -254,8 +255,11 @@ request(Method, Path, Version, Headers) -> -spec response(status() | binary(), version(), headers()) -> iodata(). response(Status, Version, Headers) -> [version(Version), <<" ">>, status(Status), <<"\r\n">>, - [[N, <<": ">>, V, <<"\r\n">>] || {N, V} <- Headers], - <<"\r\n">>]. + headers(Headers), <<"\r\n">>]. + +-spec headers(headers()) -> iodata(). +headers(Headers) -> + [[N, <<": ">>, V, <<"\r\n">>] || {N, V} <- Headers]. %% @doc Return the version as a binary. -- cgit v1.2.3