HTTP请求的消息体长度

阅读更多

1、Transfer-Encoding = chunked
2、Content-Length = integer()
3、undefined | 0


mochiweb_request.erl

 

 

%% @spec body_length() -> undefined | chunked | unknown_transfer_encoding | integer()
%% @doc  Infer body length from transfer-encoding and content-length headers.
body_length() ->
    case get_header_value("transfer-encoding") of
        undefined ->
            case get_header_value("content-length") of
                undefined ->
                    undefined;
                Length ->
                    list_to_integer(Length)
            end;
        "chunked" ->
            chunked;
        Unknown ->
            {unknown_transfer_encoding, Unknown}
    end.
 

头域完全使用小写:
mochiweb_headers.erl

 

normalize(K) when is_list(K) ->
    string:to_lower(K);
normalize(K) when is_atom(K) ->
    normalize(atom_to_list(K));
normalize(K) when is_binary(K) ->
    normalize(binary_to_list(K)).
 

 

 

 

你可能感兴趣的:(HTTP请求的消息体长度)