Imported Upstream version 1.0.0
[platform/upstream/nghttp2.git] / doc / nghttp2_submit_response.rst
1
2 nghttp2_submit_response
3 =======================
4
5 Synopsis
6 --------
7
8 *#include <nghttp2/nghttp2.h>*
9
10 .. function:: int nghttp2_submit_response(nghttp2_session *session, int32_t stream_id, const nghttp2_nv *nva, size_t nvlen, const nghttp2_data_provider *data_prd)
11
12     
13     Submits response HEADERS frame and optionally one or more DATA
14     frames against the stream *stream_id*.
15     
16     The *nva* is an array of name/value pair :type:`nghttp2_nv` with
17     *nvlen* elements.  The application is responsible to include
18     required pseudo-header fields (header field whose name starts with
19     ":") in *nva* and must place pseudo-headers before regular header
20     fields.
21     
22     This function creates copies of all name/value pairs in *nva*.  It
23     also lower-cases all names in *nva*.  The order of elements in
24     *nva* is preserved.
25     
26     HTTP/2 specification has requirement about header fields in the
27     response HEADERS.  See the specification for more details.
28     
29     If *data_prd* is not ``NULL``, it provides data which will be sent
30     in subsequent DATA frames.  This function does not take ownership
31     of the *data_prd*.  The function copies the members of the
32     *data_prd*.  If *data_prd* is ``NULL``, HEADERS will have
33     END_STREAM flag set.
34     
35     This method can be used as normal HTTP response and push response.
36     When pushing a resource using this function, the *session* must be
37     configured using `nghttp2_session_server_new()` or its variants and
38     the target stream denoted by the *stream_id* must be reserved using
39     `nghttp2_submit_push_promise()`.
40     
41     To send non-final response headers (e.g., HTTP status 101), don't
42     use this function because this function half-closes the outbound
43     stream.  Instead, use `nghttp2_submit_headers()` for this purpose.
44     
45     This function returns 0 if it succeeds, or one of the following
46     negative error codes:
47     
48     :macro:`NGHTTP2_ERR_NOMEM`
49         Out of memory.
50     :macro:`NGHTTP2_ERR_INVALID_ARGUMENT`
51         The *stream_id* is 0.
52     
53     .. warning::
54     
55       Calling this function twice for the same stream ID may lead to
56       program crash.  It is generally considered to a programming error
57       to commit response twice.