nghttp2_http.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * nghttp2 - HTTP/2 C Library
  3. *
  4. * Copyright (c) 2015 Tatsuhiro Tsujikawa
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining
  7. * a copy of this software and associated documentation files (the
  8. * "Software"), to deal in the Software without restriction, including
  9. * without limitation the rights to use, copy, modify, merge, publish,
  10. * distribute, sublicense, and/or sell copies of the Software, and to
  11. * permit persons to whom the Software is furnished to do so, subject to
  12. * the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be
  15. * included in all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. */
  25. #ifndef NGHTTP2_HTTP_H
  26. #define NGHTTP2_HTTP_H
  27. #ifdef HAVE_CONFIG_H
  28. # include <config.h>
  29. #endif /* HAVE_CONFIG_H */
  30. #include <nghttp2/nghttp2.h>
  31. #include "nghttp2_session.h"
  32. #include "nghttp2_stream.h"
  33. /*
  34. * This function is called when HTTP header field |nv| in |frame| is
  35. * received for |stream|. This function will validate |nv| against
  36. * the current state of stream.
  37. *
  38. * This function returns 0 if it succeeds, or one of the following
  39. * negative error codes:
  40. *
  41. * NGHTTP2_ERR_HTTP_HEADER
  42. * Invalid HTTP header field was received.
  43. * NGHTTP2_ERR_IGN_HTTP_HEADER
  44. * Invalid HTTP header field was received but it can be treated as
  45. * if it was not received because of compatibility reasons.
  46. */
  47. int nghttp2_http_on_header(nghttp2_session *session, nghttp2_stream *stream,
  48. nghttp2_frame *frame, nghttp2_hd_nv *nv,
  49. int trailer);
  50. /*
  51. * This function is called when request header is received. This
  52. * function performs validation and returns 0 if it succeeds, or -1.
  53. */
  54. int nghttp2_http_on_request_headers(nghttp2_stream *stream,
  55. nghttp2_frame *frame);
  56. /*
  57. * This function is called when response header is received. This
  58. * function performs validation and returns 0 if it succeeds, or -1.
  59. */
  60. int nghttp2_http_on_response_headers(nghttp2_stream *stream);
  61. /*
  62. * This function is called trailer header (for both request and
  63. * response) is received. This function performs validation and
  64. * returns 0 if it succeeds, or -1.
  65. */
  66. int nghttp2_http_on_trailer_headers(nghttp2_stream *stream,
  67. nghttp2_frame *frame);
  68. /*
  69. * This function is called when END_STREAM flag is seen in incoming
  70. * frame. This function performs validation and returns 0 if it
  71. * succeeds, or -1.
  72. */
  73. int nghttp2_http_on_remote_end_stream(nghttp2_stream *stream);
  74. /*
  75. * This function is called when chunk of data is received. This
  76. * function performs validation and returns 0 if it succeeds, or -1.
  77. */
  78. int nghttp2_http_on_data_chunk(nghttp2_stream *stream, size_t n);
  79. /*
  80. * This function inspects header field in |frame| and records its
  81. * method in stream->http_flags. If frame->hd.type is neither
  82. * NGHTTP2_HEADERS nor NGHTTP2_PUSH_PROMISE, this function does
  83. * nothing.
  84. */
  85. void nghttp2_http_record_request_method(nghttp2_stream *stream,
  86. nghttp2_frame *frame);
  87. /*
  88. * RFC 8941 Structured Field Values.
  89. */
  90. typedef enum nghttp2_sf_value_type {
  91. NGHTTP2_SF_VALUE_TYPE_BOOLEAN,
  92. NGHTTP2_SF_VALUE_TYPE_INTEGER,
  93. NGHTTP2_SF_VALUE_TYPE_DECIMAL,
  94. NGHTTP2_SF_VALUE_TYPE_STRING,
  95. NGHTTP2_SF_VALUE_TYPE_TOKEN,
  96. NGHTTP2_SF_VALUE_TYPE_BYTESEQ,
  97. NGHTTP2_SF_VALUE_TYPE_INNER_LIST,
  98. } nghttp2_sf_value_type;
  99. /*
  100. * nghttp2_sf_value stores Structured Field Values item. For Inner
  101. * List, only type is set to NGHTTP2_SF_VALUE_TYPE_INNER_LIST.
  102. */
  103. typedef struct nghttp2_sf_value {
  104. uint8_t type;
  105. union {
  106. int b;
  107. int64_t i;
  108. double d;
  109. struct {
  110. const uint8_t *base;
  111. size_t len;
  112. } s;
  113. };
  114. } nghttp2_sf_value;
  115. /*
  116. * nghttp2_sf_parse_item parses the input sequence [|begin|, |end|)
  117. * and stores the parsed an Item in |dest|. It returns the number of
  118. * bytes consumed if it succeeds, or -1. This function is declared
  119. * here for unit tests.
  120. */
  121. ssize_t nghttp2_sf_parse_item(nghttp2_sf_value *dest, const uint8_t *begin,
  122. const uint8_t *end);
  123. /*
  124. * nghttp2_sf_parse_inner_list parses the input sequence [|begin|, |end|)
  125. * and stores the parsed an Inner List in |dest|. It returns the number of
  126. * bytes consumed if it succeeds, or -1. This function is declared
  127. * here for unit tests.
  128. */
  129. ssize_t nghttp2_sf_parse_inner_list(nghttp2_sf_value *dest,
  130. const uint8_t *begin, const uint8_t *end);
  131. int nghttp2_http_parse_priority(nghttp2_extpri *dest, const uint8_t *value,
  132. size_t valuelen);
  133. #endif /* NGHTTP2_HTTP_H */