2017-06-02 19:12:39 -07:00
|
|
|
[/
|
2017-07-28 19:32:33 -07:00
|
|
|
Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
|
2017-06-02 19:12:39 -07:00
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
2017-07-28 19:32:33 -07:00
|
|
|
|
|
|
|
|
Official repository: https://github.com/boostorg/beast
|
2017-06-02 19:12:39 -07:00
|
|
|
]
|
|
|
|
|
|
2017-06-16 19:27:00 -07:00
|
|
|
[section Custom Parsers]
|
2017-06-02 19:12:39 -07:00
|
|
|
|
2017-06-03 09:45:09 -07:00
|
|
|
While the parsers included in the library will handle a broad number of
|
|
|
|
|
use-cases, the __basic_parser__ interface can be subclassed to implement
|
2017-10-26 16:05:50 -07:00
|
|
|
custom strategies for storing parsed results: the basic parser processes
|
|
|
|
|
the incoming octets into elements according to the HTTP/1 protocol
|
|
|
|
|
specification, while the derived class decides what to do with those
|
|
|
|
|
elements. In particular, users who create exotic containers for [*Fields]
|
|
|
|
|
may need to also create their own parser. Custom parsers will work with
|
|
|
|
|
all of the stream read operations that work on parsers, as those algorithms
|
|
|
|
|
use only the basic parser interface. Some use cases for implementing custom
|
|
|
|
|
parsers are:
|
2017-06-03 09:45:09 -07:00
|
|
|
|
2017-06-11 09:59:13 -07:00
|
|
|
* Inspect incoming header fields and keep or discard them.
|
|
|
|
|
|
|
|
|
|
* Use a container provided by an external interface.
|
|
|
|
|
|
|
|
|
|
* Store header data in a user-defined __Fields__ type.
|
2017-06-03 09:45:09 -07:00
|
|
|
|
2017-10-26 16:05:50 -07:00
|
|
|
The basic parser uses the
|
|
|
|
|
[@https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern Curiously Recurring Template Pattern].
|
2017-06-05 15:44:47 -07:00
|
|
|
To declare your user defined parser, derive it from __basic_parser__.
|
2017-06-03 09:45:09 -07:00
|
|
|
The interface to the parser is event-driven. Member functions of the derived
|
|
|
|
|
class (termed "callbacks" in this context) are invoked with parsed elements
|
|
|
|
|
as they become available, requiring either the `friend` declaration as shown
|
|
|
|
|
above or that the member functions are declared public (not recommended).
|
2017-06-11 09:59:13 -07:00
|
|
|
Buffers provided by the parser are non-owning references; it is the
|
2017-06-03 09:45:09 -07:00
|
|
|
responsibility of the derived class to copy any information it needs before
|
|
|
|
|
returning from the callback.
|
|
|
|
|
|
2017-06-14 20:26:44 -07:00
|
|
|
[example_http_custom_parser]
|
2017-06-03 09:45:09 -07:00
|
|
|
|
2017-06-02 19:12:39 -07:00
|
|
|
[endsect]
|