View Source hackney_response (hackney v1.23.0)

module handling the response

Summary

Functions

Return the full body sent with the request.

Return the full body sent with the request as long as the body length doesn't go over MaxLength.

handle Expect header

Skip a part returned by the multipart parser.

Start the response It parse the request lines and headers.

stream a multipart response

Types

response_state/0

-type response_state() :: start | waiting | on_status | on_headers | on_body.

Functions

body(Client)

-spec body(#client{start_time :: term(),
                   mod_metrics :: term(),
                   transport :: term(),
                   host :: term(),
                   port :: term(),
                   netloc :: term(),
                   options :: term(),
                   socket :: term(),
                   socket_ref :: term(),
                   request_ref :: term(),
                   dynamic :: term(),
                   pool_handler :: term(),
                   recv_timeout :: term(),
                   follow_redirect :: term(),
                   max_redirect :: term(),
                   force_redirect :: term(),
                   retries :: term(),
                   redirect :: term(),
                   location :: term(),
                   parser :: term(),
                   headers :: term(),
                   state :: term(),
                   response_state :: term(),
                   mp_boundary :: term(),
                   req_type :: term(),
                   expect :: term(),
                   async :: term(),
                   with_body :: term(),
                   max_body :: term(),
                   stream_to :: term(),
                   send_fun :: term(),
                   body_state :: term(),
                   multipart :: term(),
                   req_chunk_size :: term(),
                   buffer :: term(),
                   partial_headers :: term(),
                   version :: term(),
                   clen :: term(),
                   te :: term(),
                   connection :: term(),
                   method :: term(),
                   path :: term(),
                   ctype :: term()}) ->
              {ok,
               binary(),
               #client{start_time :: term(),
                       mod_metrics :: term(),
                       transport :: term(),
                       host :: term(),
                       port :: term(),
                       netloc :: term(),
                       options :: term(),
                       socket :: term(),
                       socket_ref :: term(),
                       request_ref :: term(),
                       dynamic :: term(),
                       pool_handler :: term(),
                       recv_timeout :: term(),
                       follow_redirect :: term(),
                       max_redirect :: term(),
                       force_redirect :: term(),
                       retries :: term(),
                       redirect :: term(),
                       location :: term(),
                       parser :: term(),
                       headers :: term(),
                       state :: term(),
                       response_state :: term(),
                       mp_boundary :: term(),
                       req_type :: term(),
                       expect :: term(),
                       async :: term(),
                       with_body :: term(),
                       max_body :: term(),
                       stream_to :: term(),
                       send_fun :: term(),
                       body_state :: term(),
                       multipart :: term(),
                       req_chunk_size :: term(),
                       buffer :: term(),
                       partial_headers :: term(),
                       version :: term(),
                       clen :: term(),
                       te :: term(),
                       connection :: term(),
                       method :: term(),
                       path :: term(),
                       ctype :: term()}} |
              {error, atom()}.
Return the full body sent with the request.

body(MaxLength, Client)

-spec body(non_neg_integer() | infinity,
           #client{start_time :: term(),
                   mod_metrics :: term(),
                   transport :: term(),
                   host :: term(),
                   port :: term(),
                   netloc :: term(),
                   options :: term(),
                   socket :: term(),
                   socket_ref :: term(),
                   request_ref :: term(),
                   dynamic :: term(),
                   pool_handler :: term(),
                   recv_timeout :: term(),
                   follow_redirect :: term(),
                   max_redirect :: term(),
                   force_redirect :: term(),
                   retries :: term(),
                   redirect :: term(),
                   location :: term(),
                   parser :: term(),
                   headers :: term(),
                   state :: term(),
                   response_state :: term(),
                   mp_boundary :: term(),
                   req_type :: term(),
                   expect :: term(),
                   async :: term(),
                   with_body :: term(),
                   max_body :: term(),
                   stream_to :: term(),
                   send_fun :: term(),
                   body_state :: term(),
                   multipart :: term(),
                   req_chunk_size :: term(),
                   buffer :: term(),
                   partial_headers :: term(),
                   version :: term(),
                   clen :: term(),
                   te :: term(),
                   connection :: term(),
                   method :: term(),
                   path :: term(),
                   ctype :: term()}) ->
              {ok,
               binary(),
               #client{start_time :: term(),
                       mod_metrics :: term(),
                       transport :: term(),
                       host :: term(),
                       port :: term(),
                       netloc :: term(),
                       options :: term(),
                       socket :: term(),
                       socket_ref :: term(),
                       request_ref :: term(),
                       dynamic :: term(),
                       pool_handler :: term(),
                       recv_timeout :: term(),
                       follow_redirect :: term(),
                       max_redirect :: term(),
                       force_redirect :: term(),
                       retries :: term(),
                       redirect :: term(),
                       location :: term(),
                       parser :: term(),
                       headers :: term(),
                       state :: term(),
                       response_state :: term(),
                       mp_boundary :: term(),
                       req_type :: term(),
                       expect :: term(),
                       async :: term(),
                       with_body :: term(),
                       max_body :: term(),
                       stream_to :: term(),
                       send_fun :: term(),
                       body_state :: term(),
                       multipart :: term(),
                       req_chunk_size :: term(),
                       buffer :: term(),
                       partial_headers :: term(),
                       version :: term(),
                       clen :: term(),
                       te :: term(),
                       connection :: term(),
                       method :: term(),
                       path :: term(),
                       ctype :: term()}} |
              {error, atom()}.

Return the full body sent with the request as long as the body length doesn't go over MaxLength.

This is most useful to quickly be able to get the full body while avoiding filling your memory with huge request bodies when you're not expecting it.

When the response is larger than MaxLength, this function will return the body it received up to the last chunk, which might be a bit more than MaxLength.

close(Client)

expect_response(Client)

handle Expect header

maybe_close(Client)

skip_body(Client)

-spec skip_body(#client{start_time :: term(),
                        mod_metrics :: term(),
                        transport :: term(),
                        host :: term(),
                        port :: term(),
                        netloc :: term(),
                        options :: term(),
                        socket :: term(),
                        socket_ref :: term(),
                        request_ref :: term(),
                        dynamic :: term(),
                        pool_handler :: term(),
                        recv_timeout :: term(),
                        follow_redirect :: term(),
                        max_redirect :: term(),
                        force_redirect :: term(),
                        retries :: term(),
                        redirect :: term(),
                        location :: term(),
                        parser :: term(),
                        headers :: term(),
                        state :: term(),
                        response_state :: term(),
                        mp_boundary :: term(),
                        req_type :: term(),
                        expect :: term(),
                        async :: term(),
                        with_body :: term(),
                        max_body :: term(),
                        stream_to :: term(),
                        send_fun :: term(),
                        body_state :: term(),
                        multipart :: term(),
                        req_chunk_size :: term(),
                        buffer :: term(),
                        partial_headers :: term(),
                        version :: term(),
                        clen :: term(),
                        te :: term(),
                        connection :: term(),
                        method :: term(),
                        path :: term(),
                        ctype :: term()}) ->
                   {ok,
                    #client{start_time :: term(),
                            mod_metrics :: term(),
                            transport :: term(),
                            host :: term(),
                            port :: term(),
                            netloc :: term(),
                            options :: term(),
                            socket :: term(),
                            socket_ref :: term(),
                            request_ref :: term(),
                            dynamic :: term(),
                            pool_handler :: term(),
                            recv_timeout :: term(),
                            follow_redirect :: term(),
                            max_redirect :: term(),
                            force_redirect :: term(),
                            retries :: term(),
                            redirect :: term(),
                            location :: term(),
                            parser :: term(),
                            headers :: term(),
                            state :: term(),
                            response_state :: term(),
                            mp_boundary :: term(),
                            req_type :: term(),
                            expect :: term(),
                            async :: term(),
                            with_body :: term(),
                            max_body :: term(),
                            stream_to :: term(),
                            send_fun :: term(),
                            body_state :: term(),
                            multipart :: term(),
                            req_chunk_size :: term(),
                            buffer :: term(),
                            partial_headers :: term(),
                            version :: term(),
                            clen :: term(),
                            te :: term(),
                            connection :: term(),
                            method :: term(),
                            path :: term(),
                            ctype :: term()}} |
                   {skip,
                    #client{start_time :: term(),
                            mod_metrics :: term(),
                            transport :: term(),
                            host :: term(),
                            port :: term(),
                            netloc :: term(),
                            options :: term(),
                            socket :: term(),
                            socket_ref :: term(),
                            request_ref :: term(),
                            dynamic :: term(),
                            pool_handler :: term(),
                            recv_timeout :: term(),
                            follow_redirect :: term(),
                            max_redirect :: term(),
                            force_redirect :: term(),
                            retries :: term(),
                            redirect :: term(),
                            location :: term(),
                            parser :: term(),
                            headers :: term(),
                            state :: term(),
                            response_state :: term(),
                            mp_boundary :: term(),
                            req_type :: term(),
                            expect :: term(),
                            async :: term(),
                            with_body :: term(),
                            max_body :: term(),
                            stream_to :: term(),
                            send_fun :: term(),
                            body_state :: term(),
                            multipart :: term(),
                            req_chunk_size :: term(),
                            buffer :: term(),
                            partial_headers :: term(),
                            version :: term(),
                            clen :: term(),
                            te :: term(),
                            connection :: term(),
                            method :: term(),
                            path :: term(),
                            ctype :: term()}} |
                   {error, atom()}.

skip_multipart(Client)

-spec skip_multipart(Client) -> {ok, Client}
                        when
                            Client ::
                                #client{start_time :: term(),
                                        mod_metrics :: term(),
                                        transport :: term(),
                                        host :: term(),
                                        port :: term(),
                                        netloc :: term(),
                                        options :: term(),
                                        socket :: term(),
                                        socket_ref :: term(),
                                        request_ref :: term(),
                                        dynamic :: term(),
                                        pool_handler :: term(),
                                        recv_timeout :: term(),
                                        follow_redirect :: term(),
                                        max_redirect :: term(),
                                        force_redirect :: term(),
                                        retries :: term(),
                                        redirect :: term(),
                                        location :: term(),
                                        parser :: term(),
                                        headers :: term(),
                                        state :: term(),
                                        response_state :: term(),
                                        mp_boundary :: term(),
                                        req_type :: term(),
                                        expect :: term(),
                                        async :: term(),
                                        with_body :: term(),
                                        max_body :: term(),
                                        stream_to :: term(),
                                        send_fun :: term(),
                                        body_state :: term(),
                                        multipart :: term(),
                                        req_chunk_size :: term(),
                                        buffer :: term(),
                                        partial_headers :: term(),
                                        version :: term(),
                                        clen :: term(),
                                        te :: term(),
                                        connection :: term(),
                                        method :: term(),
                                        path :: term(),
                                        ctype :: term()}.

Skip a part returned by the multipart parser.

This function repeatedly calls multipart_data/1 until {end_of_part, Req} or {eof, Req} is parsed.

start_response(Client)

Start the response It parse the request lines and headers.

stream_body(Client)

stream_multipart(Client)

-spec stream_multipart(#client{start_time :: term(),
                               mod_metrics :: term(),
                               transport :: term(),
                               host :: term(),
                               port :: term(),
                               netloc :: term(),
                               options :: term(),
                               socket :: term(),
                               socket_ref :: term(),
                               request_ref :: term(),
                               dynamic :: term(),
                               pool_handler :: term(),
                               recv_timeout :: term(),
                               follow_redirect :: term(),
                               max_redirect :: term(),
                               force_redirect :: term(),
                               retries :: term(),
                               redirect :: term(),
                               location :: term(),
                               parser :: term(),
                               headers :: term(),
                               state :: term(),
                               response_state :: term(),
                               mp_boundary :: term(),
                               req_type :: term(),
                               expect :: term(),
                               async :: term(),
                               with_body :: term(),
                               max_body :: term(),
                               stream_to :: term(),
                               send_fun :: term(),
                               body_state :: term(),
                               multipart :: term(),
                               req_chunk_size :: term(),
                               buffer :: term(),
                               partial_headers :: term(),
                               version :: term(),
                               clen :: term(),
                               te :: term(),
                               connection :: term(),
                               method :: term(),
                               path :: term(),
                               ctype :: term()}) ->
                          {headers,
                           list(),
                           #client{start_time :: term(),
                                   mod_metrics :: term(),
                                   transport :: term(),
                                   host :: term(),
                                   port :: term(),
                                   netloc :: term(),
                                   options :: term(),
                                   socket :: term(),
                                   socket_ref :: term(),
                                   request_ref :: term(),
                                   dynamic :: term(),
                                   pool_handler :: term(),
                                   recv_timeout :: term(),
                                   follow_redirect :: term(),
                                   max_redirect :: term(),
                                   force_redirect :: term(),
                                   retries :: term(),
                                   redirect :: term(),
                                   location :: term(),
                                   parser :: term(),
                                   headers :: term(),
                                   state :: term(),
                                   response_state :: term(),
                                   mp_boundary :: term(),
                                   req_type :: term(),
                                   expect :: term(),
                                   async :: term(),
                                   with_body :: term(),
                                   max_body :: term(),
                                   stream_to :: term(),
                                   send_fun :: term(),
                                   body_state :: term(),
                                   multipart :: term(),
                                   req_chunk_size :: term(),
                                   buffer :: term(),
                                   partial_headers :: term(),
                                   version :: term(),
                                   clen :: term(),
                                   te :: term(),
                                   connection :: term(),
                                   method :: term(),
                                   path :: term(),
                                   ctype :: term()}} |
                          {body,
                           binary(),
                           #client{start_time :: term(),
                                   mod_metrics :: term(),
                                   transport :: term(),
                                   host :: term(),
                                   port :: term(),
                                   netloc :: term(),
                                   options :: term(),
                                   socket :: term(),
                                   socket_ref :: term(),
                                   request_ref :: term(),
                                   dynamic :: term(),
                                   pool_handler :: term(),
                                   recv_timeout :: term(),
                                   follow_redirect :: term(),
                                   max_redirect :: term(),
                                   force_redirect :: term(),
                                   retries :: term(),
                                   redirect :: term(),
                                   location :: term(),
                                   parser :: term(),
                                   headers :: term(),
                                   state :: term(),
                                   response_state :: term(),
                                   mp_boundary :: term(),
                                   req_type :: term(),
                                   expect :: term(),
                                   async :: term(),
                                   with_body :: term(),
                                   max_body :: term(),
                                   stream_to :: term(),
                                   send_fun :: term(),
                                   body_state :: term(),
                                   multipart :: term(),
                                   req_chunk_size :: term(),
                                   buffer :: term(),
                                   partial_headers :: term(),
                                   version :: term(),
                                   clen :: term(),
                                   te :: term(),
                                   connection :: term(),
                                   method :: term(),
                                   path :: term(),
                                   ctype :: term()}} |
                          {eof | end_of_part | mp_mixed | mp_mixed_eof,
                           #client{start_time :: term(),
                                   mod_metrics :: term(),
                                   transport :: term(),
                                   host :: term(),
                                   port :: term(),
                                   netloc :: term(),
                                   options :: term(),
                                   socket :: term(),
                                   socket_ref :: term(),
                                   request_ref :: term(),
                                   dynamic :: term(),
                                   pool_handler :: term(),
                                   recv_timeout :: term(),
                                   follow_redirect :: term(),
                                   max_redirect :: term(),
                                   force_redirect :: term(),
                                   retries :: term(),
                                   redirect :: term(),
                                   location :: term(),
                                   parser :: term(),
                                   headers :: term(),
                                   state :: term(),
                                   response_state :: term(),
                                   mp_boundary :: term(),
                                   req_type :: term(),
                                   expect :: term(),
                                   async :: term(),
                                   with_body :: term(),
                                   max_body :: term(),
                                   stream_to :: term(),
                                   send_fun :: term(),
                                   body_state :: term(),
                                   multipart :: term(),
                                   req_chunk_size :: term(),
                                   buffer :: term(),
                                   partial_headers :: term(),
                                   version :: term(),
                                   clen :: term(),
                                   te :: term(),
                                   connection :: term(),
                                   method :: term(),
                                   path :: term(),
                                   ctype :: term()}}.

stream a multipart response

Use this function for multipart streaming. For each part in the response, this function returns {headers, Headers, Req} followed by a sequence of {body, Data, Req} tuples and finally {end_of_part, Req}. When there is no part to parse anymore, {eof, Req} is returned.