Commit Graph

114 Commits

Author SHA1 Message Date
Vinnie Falco f47b66179e New HTTP interfaces (API Change):
fix #123
fix #154
fix #265

This completely replaces the HTTP parser used to read and
parse incoming messages. The new version is faster than
the old one, and written in fewer lines. A summary of
changes:

* parse and async_parse renamed to read and async_read

* basic_parser is optimized for linear buffers,
  use flat_streambuf for the best performance with these
  functions:

  - http::read
  - http::read_some
  - http::async_read
  - http::async_read_some

* The overloads of read() and async_read() which take
  just a header have been removed, since they would
  throw away important parse metadata.

* The derived class callbacks for basic_parser have
  been streamlined. All strings passed to callbacks
  are presented in their entirety, instead of being
  provided in pieces.

These changes allow use-cases that were previously
difficult or impossible, such as:

- Efficient relaying

- Late body type commitment

- Expect: 100-continue handling
2017-05-04 18:58:33 -07:00
Vinnie Falco 7e37723be0 Add flat_streambuf:
Objects of this type meet the requirements of DynamicBuffer
and offer an additional invariant: buffer sequences returned
by data() and prepare() are always of length one.
2017-05-04 18:58:33 -07:00
Vinnie Falco 3de46de96c Make websocket::close_code a proper enum:
fix #311

This changes close_code to be a proper enumeration.
2017-04-23 08:26:17 -07:00
Vinnie Falco fe3e20b645 Add write_frames unit test 2017-04-14 19:25:05 -07:00
Vinnie Falco 578dcd0a78 Add decorator unit test
fix #302
2017-04-14 19:24:57 -07:00
Vinnie Falco df661658ee Require Visual Studio 2015 Update 3 or later
fix #216
2017-04-12 18:36:59 -07:00
Sergey Lyubimov ffb17589d0 Update CMake scripts for finding packages:
These changes require CMake version 3.7.2 or later.
2017-04-10 16:47:58 -07:00
Vinnie Falco b893749e29 Remove http Writer suspend and resume feature (API Change):
fix #154

The resume_context parameter passed to instances
of Writer during HTTP serialization is removed.
2017-04-10 15:54:29 -07:00
Vinnie Falco 27864fb3dd Add io_service completion invariants tests
fix #290
2017-03-31 10:39:11 -04:00
Vinnie Falco 195f974872 Fix HTTP split parse edge case:
fix #257

This fixes a problem when doing split parsing (header then body).
The problem arises when the first buffer passed to the header
parser contains exactly the full header and nothing more. The
symptom is that when parsing the body, the parse will erroneously
be considered complete.
2017-02-07 19:59:04 -05:00
Vinnie Falco 572a0eb490 Split out and rename test stream classes 2017-02-07 19:59:03 -05:00
Vinnie Falco a6120cd8be Update copyright dates 2017-02-07 15:20:25 -05:00
Vinnie Falco f6c91ce9f5 Tidy up tests and docs:
* Add handler_ptr test and increase coverage
* Add test for prepare_buffer
* Move is_call_possible tests to a .cpp file
* Tidy up docs and declarations
2017-02-06 11:34:29 -05:00
Vinnie Falco f03985f3e8 Move basic_streambuf to streambuf.hpp (API Change):
* Also change allocator element type to char
2017-02-06 11:34:29 -05:00
Vinnie Falco b8639a791a Invoke callback on pings and pongs (API Change):
fix #248

This additionally invokes the pong callback for received pings, allowing
callers to more efficiently detect when a connection is still lively:

* pong_callback renamed to ping_callback
* Callback signature has an extra `bool` to indicate if the received
  control frame is a ping or pong.
2017-02-05 18:45:22 -05:00
Vinnie Falco 68f535f357 Tidy up warnings and tests:
* Enable WebSocket frame tests
* Remove read_message_max warning
* Remove permessage-deflate check offer warning
2017-02-02 08:57:17 -05:00
Vinnie Falco 439a224e1d WebSocket server examples and test tidying:
fix #238, fix #165

* Tidy up WebSocket echo servers
* Add WebSocket echo servers to examples
2017-02-01 20:05:39 -05:00
Vinnie Falco ca38657aab Fixes for websocket echo server:
* Decorator members are const
* Enable permessage-deflate extension
2017-01-27 20:15:31 -05:00
Vinnie Falco a4509684cc Add permessage-deflate WebSocket extension:
This implements the permessage-deflate WebSocket
extension as described in HyBi Working Group
draft-ietf-hybi-permessage-compression-28:
https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-28

This extension allows messages to be compressed using
the raw "deflate" algorithm described in RFC 1951,
"DEFLATE Compressed Data Format Specification version 1.3":
https://www.ietf.org/rfc/rfc1951.txt
2017-01-27 19:46:49 -05:00
Vinnie Falco 42899fc317 Add optional yield_to arguments 2017-01-25 09:51:31 -05:00
Vinnie Falco b05fa33402 Fix message constructor and special members
fix #196
2017-01-17 14:45:38 -05:00
Vinnie Falco b4722cc27d Add copy special members 2017-01-17 14:44:22 -05:00
Vinnie Falco 420d1c7525 Better logging in async echo server 2017-01-17 14:44:20 -05:00
Vinnie Falco 149e3a2c45 Add file and line number to thrown exceptions 2017-01-17 14:43:12 -05:00
Vinnie Falco 3e88b837db Tune websocket echo server for performance 2017-01-17 14:40:15 -05:00
Vinnie Falco 114175cd1f Implement asio dealloc-before-invoke guarantee:
fix #215

This change guarantees that temporary memory allocated
through the asio hooks by the Beast implementation is
deallocated before invoking the final handler when performing
composed operations.

The change is accomplished by replacing std::shared_ptr with
a thread-safe custom container handler_ptr to manage composed
operation state. The container tracks other instances which
manage the same object and resets them in a safe way before
invoking the final handler.

handler_ptr is provided as a public interface so that users of
this library can utilize the same idiom to write their own
composed operations.
2017-01-07 16:07:01 -05:00
Miguel Portilla 45eaa8c8da Increase utf8 checker code coverage 2016-11-15 13:09:18 -05:00
Vinnie Falco 9ff1a27160 Add zlib module:
The zlib module is a port of ZLib's raw deflate
algorithm to header-only C++11.
2016-11-15 12:04:59 -05:00
Vinnie Falco a0a335972f Refactor HTTP identifier names (API Change):
fix #171

Several names and  HTTP identifiers are renamed to be
more consistent, self-explanatory, and concise:

* "Fields" is a collection of HTTP header fields (rfc7230 section 3.2)
* "Header" is the Start Line plus Fields. Another way to look at it is,
  the HTTP message minus the body.
* `basic_fields` replaces `basic_headers`
* `fields` replaces `headers`
* `Fields` replaces `Headers` in template parameter lists
* `header` replaces `message_headers`
* `header::fields` replaces `message_headers::fields`

The changes are cosmetic and do not affect run-time behavior.
2016-11-15 12:04:44 -05:00
Vinnie Falco 4130ad4832 Better buffer_cat:
buffer_cat now determines if all of the buffer sequences in
the list of passed buffer sequences each have value types which
are convertible to mutable_buffer. The returned concatenated
sequence will be a MutableBufferSequence if all the passed
buffer sequences meet the requirements of MutableBufferSequence,
else the returned concatenated sequence will be a ConstBufferSequence.
2016-11-12 11:27:59 -05:00
Vinnie Falco f94f21db0b Fix consuming_buffers value_type (API Change):
This fixes a bug where instantiations of consuming_buffers with
buffer sequence types whose value_type is not const_buffer or
mutable_buffer can cause compilation errors.

The function consumed_buffers is removed.
2016-11-12 11:27:59 -05:00
Vinnie Falco a4af9d6769 Use boost::lexical_cast instead of std::to_string
fix #176
2016-11-12 11:27:57 -05:00
Vinnie Falco a63bd84ee3 Increase code coverage 2016-11-12 11:27:57 -05:00
Vinnie Falco 84a6775dc1 Boost library min/max guidance:
fix #170
2016-11-12 11:27:56 -05:00
Vinnie Falco 02feea5128 Add read, async_read for message_headers:
fix #172, fix #173

This provides overloads of read and async_read to allow
reading message_headers objects.
2016-11-12 11:27:56 -05:00
Vinnie Falco f22458539b Add write, async_write, operator<< for message_headers:
fix #155

This adds overloads of write, async_write, and operator<<
for message_headers.
2016-11-12 11:27:55 -05:00
Vinnie Falco ea48bcf4e6 Make chunk_encode public:
fix #154, fix #156

This adds public interfaces for transforming buffer
sequences into their chunk-encoded equivalents. The
transformations are O(1) in space and time.
2016-11-12 11:27:55 -05:00
Vinnie Falco f6dd744fd1 Refactor message and message_headers declarations:
message_headers is now a set of partial class template
specializations instead of a template class alias. This solves
a problem where template functions taking message_headers as a
parameter could not deduce argument types, since std::conditional
obscured the deduced context.

Both classes are refactored to share declarations using an #ifdef,
to eliminate an ugly set of extra declarations needed when building
the documentation.

Copy and move class special members are added.

A new function message::base() is provided which returns the
message_headers portion of a message.
2016-11-12 11:27:55 -05:00
Miguel Portilla d4dfc1ac74 Optimize utf8 validation 2016-11-12 11:27:54 -05:00
Vinnie Falco feb520414c Add websocket::stream pong and async_pong 2016-11-03 18:58:31 -04:00
Vinnie Falco 644d518db5 Move clamp to core 2016-11-01 09:01:01 -04:00
Vinnie Falco b6f3a3654d Check invariants in parse_op:
This adds more assertions, comments, and clarification.
2016-10-30 18:56:00 -04:00
Vinnie Falco 47b0fa662f Remove unused field in test 2016-10-30 18:55:19 -04:00
Andrew Whatson 95c37e23f0 Fix unused parameter warnings and missing includes:
fix #127

* Added beast::detail::ignore_unused based on boost::ignore_unused
* Added -Wextra compilation flag when building with gcc
* Fixed all unused parameter warnings with ignore_unused
* Fixed all missing includes when building each .hpp separately
2016-10-20 17:22:40 -04:00
Vinnie Falco d107ba1c1d Add headers_parser:
This allows just the HTTP headers to be parsed, and
the choice of body to be deferred to a subsequent
call to parse.
2016-10-20 17:22:39 -04:00
Vinnie Falco 658e03ca35 Add on_body_what parser callback (API Change):
These changes support parsing the headers separately from the body.

* on_headers now returns void
* on_body_what is a new required callback which returns body_what
2016-10-20 17:22:37 -04:00
Vinnie Falco ada1f60e3e Refine message class hierarchy:
Two new objects, request_headers and response_headers,
represent the portion of HTTP messages excluding the body.
2016-10-20 17:22:36 -04:00
Vinnie Falco cf43f516d2 Rework HTTP concepts (API Change):
fix #139, fix #140

* Writer uses write instead of operator()
* Refactor traits to use void_t
* Remove is_ReadableBody, is_WritableBody
* Add has_reader, has_writer, is_Reader, is_Writer
* More friendly compile errors on failed concept checks
2016-10-17 11:11:57 -04:00
Vinnie Falco 8a261ca923 HTTP Reader (API Change):
fix #114, fix #117, fix #136

* Added init() to Reader requirements
* Reader must be nothrow constructible
* Reader is now constructed right before reading the body
  - The message passed on construction is filled in
2016-10-17 11:11:57 -04:00
Vinnie Falco ebebe52612 Add basic_streambuf::alloc_size
fix #133
2016-10-17 11:11:56 -04:00