nghttp3_http.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*
  2. * nghttp3
  3. *
  4. * Copyright (c) 2019 nghttp3 contributors
  5. * Copyright (c) 2015 nghttp2 contributors
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining
  8. * a copy of this software and associated documentation files (the
  9. * "Software"), to deal in the Software without restriction, including
  10. * without limitation the rights to use, copy, modify, merge, publish,
  11. * distribute, sublicense, and/or sell copies of the Software, and to
  12. * permit persons to whom the Software is furnished to do so, subject to
  13. * the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. */
  26. #ifndef NGHTTP3_HTTP_H
  27. #define NGHTTP3_HTTP_H
  28. #ifdef HAVE_CONFIG_H
  29. # include <config.h>
  30. #endif /* defined(HAVE_CONFIG_H) */
  31. #include <nghttp3/nghttp3.h>
  32. typedef struct nghttp3_stream nghttp3_stream;
  33. typedef struct nghttp3_http_state nghttp3_http_state;
  34. /* HTTP related flags to enforce HTTP semantics */
  35. /* NGHTTP3_HTTP_FLAG_NONE indicates that no flag is set. */
  36. #define NGHTTP3_HTTP_FLAG_NONE 0x00u
  37. /* header field seen so far */
  38. #define NGHTTP3_HTTP_FLAG__AUTHORITY 0x01u
  39. #define NGHTTP3_HTTP_FLAG__PATH 0x02u
  40. #define NGHTTP3_HTTP_FLAG__METHOD 0x04u
  41. #define NGHTTP3_HTTP_FLAG__SCHEME 0x08u
  42. /* host is not pseudo header, but we require either host or
  43. :authority */
  44. #define NGHTTP3_HTTP_FLAG_HOST 0x10u
  45. #define NGHTTP3_HTTP_FLAG__STATUS 0x20u
  46. /* required header fields for HTTP request except for CONNECT
  47. method. */
  48. #define NGHTTP3_HTTP_FLAG_REQ_HEADERS \
  49. (NGHTTP3_HTTP_FLAG__METHOD | NGHTTP3_HTTP_FLAG__PATH | \
  50. NGHTTP3_HTTP_FLAG__SCHEME)
  51. #define NGHTTP3_HTTP_FLAG_PSEUDO_HEADER_DISALLOWED 0x40u
  52. /* HTTP method flags */
  53. #define NGHTTP3_HTTP_FLAG_METH_CONNECT 0x80u
  54. #define NGHTTP3_HTTP_FLAG_METH_HEAD 0x0100u
  55. #define NGHTTP3_HTTP_FLAG_METH_OPTIONS 0x0200u
  56. #define NGHTTP3_HTTP_FLAG_METH_ALL \
  57. (NGHTTP3_HTTP_FLAG_METH_CONNECT | NGHTTP3_HTTP_FLAG_METH_HEAD | \
  58. NGHTTP3_HTTP_FLAG_METH_OPTIONS)
  59. /* :path category */
  60. /* path starts with "/" */
  61. #define NGHTTP3_HTTP_FLAG_PATH_REGULAR 0x0400u
  62. /* path "*" */
  63. #define NGHTTP3_HTTP_FLAG_PATH_ASTERISK 0x0800u
  64. /* scheme */
  65. /* "http" or "https" scheme */
  66. #define NGHTTP3_HTTP_FLAG_SCHEME_HTTP 0x1000u
  67. /* set if final response is expected */
  68. #define NGHTTP3_HTTP_FLAG_EXPECT_FINAL_RESPONSE 0x2000u
  69. /* NGHTTP3_HTTP_FLAG__PROTOCOL is set when :protocol pseudo header
  70. field is seen. */
  71. #define NGHTTP3_HTTP_FLAG__PROTOCOL 0x4000u
  72. /* NGHTTP3_HTTP_FLAG_PRIORITY is set when priority header field is
  73. processed. */
  74. #define NGHTTP3_HTTP_FLAG_PRIORITY 0x8000u
  75. /* NGHTTP3_HTTP_FLAG_BAD_PRIORITY is set when an error is encountered
  76. while parsing priority header field. */
  77. #define NGHTTP3_HTTP_FLAG_BAD_PRIORITY 0x010000u
  78. /*
  79. * This function is called when HTTP header field |nv| received for
  80. * |http|. This function will validate |nv| against the current state
  81. * of stream. Pass nonzero if this is request headers. Pass nonzero
  82. * to |trailers| if |nv| is included in trailers. |connect_protocol|
  83. * is nonzero if Extended CONNECT Method is enabled.
  84. *
  85. * This function returns 0 if it succeeds, or one of the following
  86. * negative error codes:
  87. *
  88. * NGHTTP3_ERR_MALFORMED_HTTP_HEADER
  89. * Invalid HTTP header field was received.
  90. * NGHTTP3_ERR_REMOVE_HTTP_HEADER
  91. * Invalid HTTP header field was received but it can be treated as
  92. * if it was not received because of compatibility reasons.
  93. */
  94. int nghttp3_http_on_header(nghttp3_http_state *http, nghttp3_qpack_nv *nv,
  95. int request, int trailers, int connect_protocol);
  96. /*
  97. * This function is called when request header is received. This
  98. * function performs validation and returns 0 if it succeeds, or one
  99. * of the following negative error codes:
  100. *
  101. * NGHTTP3_ERR_MALFORMED_HTTP_HEADER
  102. * Required HTTP header field was not received; or an invalid
  103. * header field was received.
  104. */
  105. int nghttp3_http_on_request_headers(nghttp3_http_state *http);
  106. /*
  107. * This function is called when response header is received. This
  108. * function performs validation and returns 0 if it succeeds, or one
  109. * of the following negative error codes:
  110. *
  111. * NGHTTP3_ERR_MALFORMED_HTTP_HEADER
  112. * Required HTTP header field was not received; or an invalid
  113. * header field was received.
  114. */
  115. int nghttp3_http_on_response_headers(nghttp3_http_state *http);
  116. /*
  117. * This function is called when read side stream is closed. This
  118. * function performs validation and returns 0 if it succeeds, or one
  119. * of the following negative error codes:
  120. *
  121. * NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING
  122. * HTTP messaging is violated.
  123. */
  124. int nghttp3_http_on_remote_end_stream(nghttp3_stream *stream);
  125. /*
  126. * This function is called when chunk of data is received. This
  127. * function performs validation and returns 0 if it succeeds, or one
  128. * of the following negative error codes:
  129. *
  130. * NGHTTP3_ERR_MALFORMED_HTTP_MESSAGING
  131. * HTTP messaging is violated.
  132. */
  133. int nghttp3_http_on_data_chunk(nghttp3_stream *stream, size_t n);
  134. /*
  135. * This function inspects header fields in |nva| of length |nvlen| and
  136. * records its method in stream->http_flags.
  137. */
  138. void nghttp3_http_record_request_method(nghttp3_stream *stream,
  139. const nghttp3_nv *nva, size_t nvlen);
  140. /**
  141. * @function
  142. *
  143. * `nghttp3_http_parse_priority` parses priority HTTP header field
  144. * stored in the buffer pointed by |value| of length |len|. If it
  145. * successfully processed header field value, it stores the result
  146. * into |*dest|. This function just overwrites what it sees in the
  147. * header field value and does not initialize any field in |*dest|.
  148. *
  149. * This function returns 0 if it succeeds, or one of the following
  150. * negative error codes:
  151. *
  152. * :macro:`NGHTTP3_ERR_INVALID_ARGUMENT`
  153. * The function could not parse the provided value.
  154. */
  155. int nghttp3_http_parse_priority(nghttp3_pri *dest, const uint8_t *value,
  156. size_t len);
  157. int nghttp3_pri_eq(const nghttp3_pri *a, const nghttp3_pri *b);
  158. #endif /* !defined(NGHTTP3_HTTP_H) */