07_parser_buffers.qbk 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. [/
  2. Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. Official repository: https://github.com/boostorg/beast
  6. ]
  7. [section Buffer-Oriented Parsing]
  8. [block'''<?dbhtml stop-chunking?>''']
  9. A subclass of __basic_parser__ can be invoked directly, without using
  10. the provided stream operations. This could be useful for implementing
  11. algorithms on objects whose interface does not conform to __Stream__.
  12. For example, a
  13. [@http://zeromq.org/ *ZeroMQ* socket].
  14. The basic parser interface is interactive; the caller invokes the function
  15. [link beast.ref.boost__beast__http__basic_parser.put `basic_parser::put`]
  16. repeatedly with buffers until an error occurs or the parsing is done. The
  17. function
  18. [link beast.ref.boost__beast__http__basic_parser.put_eof `basic_parser::put_eof`]
  19. Is used when the caller knows that there will never be more data (for example,
  20. if the underlying connection is closed),
  21. [heading Parser Options]
  22. The parser provides a few options which may be set before parsing begins:
  23. [table Parser Options
  24. [[Name][Default][Description]]
  25. [[
  26. [link beast.ref.boost__beast__http__basic_parser.eager.overload2 `eager`]
  27. ][
  28. `false`
  29. ][
  30. Normally the parser returns after successfully parsing a structured
  31. element (header, chunk header, or chunk body) even if there are octets
  32. remaining in the input. This is necessary when attempting to parse the
  33. header first, or when the caller wants to inspect information which may
  34. be invalidated by subsequent parsing, such as a chunk extension. The
  35. `eager` option controls whether the parser keeps going after parsing
  36. structured element if there are octets remaining in the buffer and no
  37. error occurs. This option is automatically set or cleared during certain
  38. stream operations to improve performance with no change in functionality.
  39. ]]
  40. [[
  41. [link beast.ref.boost__beast__http__basic_parser.skip.overload2 `skip`]
  42. ][
  43. `false`
  44. ][
  45. This option controls whether or not the parser expects to see an HTTP
  46. body, regardless of the presence or absence of certain fields such as
  47. Content-Length or a chunked Transfer-Encoding. Depending on the request,
  48. some responses do not carry a body. For example, a 200 response to a
  49. [@https://tools.ietf.org/html/rfc7231#section-4.3.6 CONNECT] request
  50. from a tunneling proxy, or a response to a
  51. [@https://tools.ietf.org/html/rfc7231#section-4.3.2 HEAD] request.
  52. In these cases, callers may use this function inform the parser that
  53. no body is expected. The parser will consider the message complete
  54. after the header has been received.
  55. ]]
  56. [[
  57. [link beast.ref.boost__beast__http__basic_parser.body_limit `body_limit`]
  58. ][
  59. 1MB/8MB
  60. ][
  61. This function sets the maximum allowed size of the content body.
  62. When a body larger than the specified size is detected, an error
  63. is generated and parsing terminates. This setting helps protect
  64. servers from resource exhaustion attacks. The default limit when
  65. parsing requests is 1MB, and for parsing responses 8MB.
  66. ]]
  67. [[
  68. [link beast.ref.boost__beast__http__basic_parser.header_limit `header_limit`]
  69. ][
  70. 8KB
  71. ][
  72. This function sets the maximum allowed size of the header
  73. including all field name, value, and delimiter characters
  74. and also including the CRLF sequences in the serialized
  75. input.
  76. ]]
  77. ]
  78. [section:read_from_std_istream Read From std::istream __example__]
  79. The standard library provides the type `std::istream` for performing high
  80. level read operations on character streams. The variable `std::cin` is based
  81. on this input stream. This example uses the buffer oriented interface of
  82. __basic_parser__ to build a stream operation which parses an HTTP message
  83. from a `std::istream`:
  84. [example_http_read_istream]
  85. [tip
  86. Parsing from a `std::istream` could be implemented using an alternate
  87. strategy: adapt the `std::istream` interface to a __SyncReadStream__,
  88. enabling use with the library's existing stream algorithms. This is
  89. left as an exercise for the reader.
  90. ]
  91. [endsect]
  92. [endsect]