Commit Graph

1313 Commits

Author SHA1 Message Date
Vinnie Falco
f98ec17121 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.
2017-07-20 08:12:13 -07:00
Vinnie Falco
50bc9a58cd 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.
2017-07-20 08:12:13 -07:00
Vinnie Falco
595c5e0b6b Move sync_ostream to core/detail 2017-07-20 08:12:13 -07:00
Vinnie Falco
312bd6b21d Optimize mask operations 2017-07-20 08:12:13 -07:00
Miguel Portilla
d91fbd0611 Optimize utf8 validation 2017-07-20 08:12:13 -07:00
Vinnie Falco
804038095c Set version to 1.0.0-b18 2017-07-20 08:12:13 -07:00
Vinnie Falco
f904759877 Add websocket::stream pong and async_pong 2017-07-20 08:12:13 -07:00
Vinnie Falco
f56d4fe74b Close connection during async_read on close frame:
fix #163
2017-07-20 08:12:13 -07:00
Vinnie Falco
a2ea4f38c1 Move clamp to core 2017-07-20 08:12:13 -07:00
Vinnie Falco
a878165e36 Fix write_frame masking and auto-fragment handling 2017-07-20 08:12:13 -07:00
Vinnie Falco
dfb2d05be3 Write buffer option does not change capacity 2017-07-20 08:12:13 -07:00
Vinnie Falco
74e77682c7 Meet DynamicBuffer requirements for static_streambuf 2017-07-20 08:12:13 -07:00
Vinnie Falco
4e25e0f99e Reorganize source files and definitions 2017-07-20 08:12:13 -07:00
Vinnie Falco
1a53f52e34 Check invariants in parse_op:
This adds more assertions, comments, and clarification.
2017-07-20 08:12:13 -07:00
Vinnie Falco
8f6e238ab9 Clean up message docs 2017-07-20 08:12:13 -07:00
Vinnie Falco
0e1be4d2cb Set version to 1.0.0-b17 2017-07-20 08:12:13 -07:00
Vinnie Falco
48674cd482 Trim unused code 2017-07-20 08:12:13 -07:00
Vinnie Falco
4f68ec7b7b Doc fixes 2017-07-20 08:12:13 -07:00
Andrew Whatson
ed23fd5811 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
2017-07-20 08:12:13 -07:00
Miguel Portilla
0a1c24eb9f Refactor read_size_helper 2017-07-20 08:12:13 -07:00
Vinnie Falco
ae58a7f457 Engaged invokable is destructible:
fix #147
2017-07-20 08:12:13 -07:00
Vinnie Falco
f3b22f74b2 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.
2017-07-20 08:12:13 -07:00
Vinnie Falco
4ded6cff76 Fix handling of body_what::pause in basic_parser_v1 2017-07-20 08:12:13 -07:00
Vinnie Falco
6832bd57d3 Add basic_parser_v1::reset 2017-07-20 08:12:13 -07:00
Vinnie Falco
83556937f6 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
2017-07-20 08:12:13 -07:00
Vinnie Falco
ac07d0c3ed Fix parser traits detection (API Change):
basic_parser_v1 now requires that all callbacks appropriate
to the message are present and have the correct signatures.
Compile errors will result from compiling parsers which are
missing callbacks.
2017-07-20 08:12:13 -07:00
Vinnie Falco
e45a6418ee Tidy up documentation:
fix #135

* Fix broken references
* Move doc debug headers to extras/
* Add rfc7230 utility classes to quick reference
2017-07-20 08:12:13 -07:00
Vinnie Falco
81cd98ece5 Tidy up basic_headers for documentation 2017-07-20 08:12:13 -07:00
Vinnie Falco
a4d8a154b1 Refine message class hierarchy:
Two new objects, request_headers and response_headers,
represent the portion of HTTP messages excluding the body.
2017-07-20 08:12:13 -07:00
Vinnie Falco
056d6b94c2 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
2017-07-20 08:12:13 -07:00
Vinnie Falco
f110e51dd1 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
2017-07-20 08:12:13 -07:00
Vinnie Falco
35d1ee54bc Parser callbacks may not throw (API Change) 2017-07-20 08:12:13 -07:00
Vinnie Falco
6732af5822 Add basic_streambuf::alloc_size
fix #133
2017-07-20 08:12:13 -07:00
Vinnie Falco
92e7afb801 Fix basic_streambuf::capacity 2017-07-20 08:12:13 -07:00
Vinnie Falco
52be0dd06e Tidying:
fix #85

* Remove unnecessary boost/system includes
* Remove unused headers_type from write_preparation
* Use braced-init style construction
* handler_alloc doc update
2017-07-20 08:12:13 -07:00
Vinnie Falco
8918b2aceb Set version to 1.0.0-b16 2017-07-20 08:12:13 -07:00
Vinnie Falco
0eb3605232 Refactor base_parser_v1 callback traits:
When the derived class provides a member function with the
corresponding callback name, but the signature is different,
a compile error will be generated instead of silently ignoring
the member function.
2017-07-20 08:12:13 -07:00
Vinnie Falco
2106f364f6 Add pause option to on_headers interface:
* on_headers returns enum body_what
* body_what::pause lets caller receive headers during the parse
2017-07-20 08:12:12 -07:00
Vinnie Falco
ce18124566 Improve first line serialization 2017-07-20 08:12:12 -07:00
Vinnie Falco
a26a8ea433 Constrain parser_v1 constructor 2017-07-20 08:12:12 -07:00
Vinnie Falco
bca43529b0 Refine Parser concept:
* Parser is not HTTP-specific
* parse algorithms are in their own header
* Update documentation
2017-07-20 08:12:12 -07:00
Vinnie Falco
18eeddfab6 Fix on_headers called twice from basic_parser_v1 2017-07-20 08:12:12 -07:00
Vinnie Falco
5855b34d6e Make auto_fragment a boolean option 2017-07-20 08:12:12 -07:00
Vinnie Falco
1156b483c4 Rename to write_buffer_size 2017-07-20 08:12:12 -07:00
Vinnie Falco
74f9211366 Frame processing routines are member functions 2017-07-20 08:12:12 -07:00
Vinnie Falco
fbc8ddbc81 Make value optional in param-list 2017-07-20 08:12:12 -07:00
Vinnie Falco
ad966d6217 Set version to 1.0.0-b15 2017-07-20 08:12:12 -07:00
Radoslaw Zarzynski
bc665ee1ec Fix handling empty HTTP headers in parser_v1.hpp
This patch rectifies flush() of beast::http::parser_v1
to properly handle the case when an HTTP header has
empty value.

Without the fix an empty-valued HTTP header is being
concatenated with the header directly following it.
This situation can be replicated using eg. curl:

  curl <url> -H "X-First;" -H "X-Second: bla"

What Beast's client would see is a single header named
as "X-FirstX-Second".
2017-07-20 08:12:12 -07:00
Vinnie Falco
6b0b016b21 Tidy up error types:
* Restructure header material
* Clean up namespace type injections
* Remove extraneous 'success' constants
2017-07-20 08:12:12 -07:00
Vinnie Falco
f2a283ed10 Tidy up DynamicBuffer requirements 2017-07-20 08:12:12 -07:00
Vinnie Falco
9135cdff1a Fix message_v1 constructor 2017-07-20 08:12:12 -07:00
Vinnie Falco
62bd4bb13f rfc7230 section 3.3.2 compliance 2017-07-20 08:12:12 -07:00
Vinnie Falco
0a347f2b25 Set version to 1.0.0-b14 2017-07-20 08:12:12 -07:00
Vinnie Falco
9cc65c8850 Update and tidy documentation 2017-07-20 08:12:12 -07:00
Vinnie Falco
dff2751c07 Use BOOST_ASSERT 2017-07-20 08:12:09 -07:00
Vinnie Falco
58d3ea6548 Don't rely on undefined behavior 2017-07-20 08:12:09 -07:00
Vinnie Falco
41a8342d3b Better WebSocket decorator:
* Caller provided type can omit one or both overloads
* Omitted overloads yield default behavior
* Documentation no longer refers to a detail type
2017-07-20 08:12:09 -07:00
Vinnie Falco
0c0b2f2545 Add missing rebind to handler_alloc 2017-07-20 08:12:09 -07:00
Vinnie Falco
dfea8ff266 Set version to 1.0.0-b13 2017-07-20 08:12:09 -07:00
Vinnie Falco
fda1493565 Set version to 1.0.0-b12 2017-07-20 08:12:09 -07:00
Vinnie Falco
187d0c954a Set version to 1.0.0-b11 2017-07-20 08:12:09 -07:00
Vinnie Falco
3938e5d9ed Rename to DynamicBuffer (fix #47) 2017-07-20 08:12:09 -07:00
Vinnie Falco
3518e4861b Number error codes from 1 (fix #54) 2017-07-20 08:12:09 -07:00
Vinnie Falco
c17f467601 Restyle sources 2017-07-20 08:12:09 -07:00
Vinnie Falco
9c11d3fc33 Set URI in generated WebSocket Upgrade requests (fix #64):
The 'resource' parameter in the call to stream::handshake is
used when building the HTTP request to perform the upgrade.
2017-07-20 08:12:09 -07:00
Vinnie Falco
e75fb7a4d4 Fix integer warnings in 64-bit Windows build 2017-07-20 08:12:09 -07:00
Vinnie Falco
fc677536bf Set version to 1.0.0-b10 2017-07-20 08:12:07 -07:00
Ties Jan Hefting
c07ba6aeeb Fix warnings 2017-07-20 08:12:07 -07:00
Vinnie Falco
728e7f648f Set version to 1.0.0-b9 2017-07-20 08:12:07 -07:00
Vinnie Falco
e6f1a765a1 Set version to 1.0.0-b8 2017-07-20 08:12:07 -07:00
Vinnie Falco
1947cb4e30 Fix rfc2616 Section 4.2 compliance:
basic_headers no longer combines fields with the same name by appending
a comma and concatenating the two values together. This was breaking
certain header fields which expect each value to be distinct, such as
the "Set-Cookie" header.

Now the container behaves more like a multi set with respect to insertion
of multiple values with the same field name. Additional member functions
are provided to provide extra functionality.
2017-07-20 08:12:07 -07:00
Vinnie Falco
908ac75f7c Set Beast version to 1.0.0-b7 2017-07-20 08:12:07 -07:00
Vinnie Falco
344e4c942c Add skip_body parser option 2017-07-20 08:12:07 -07:00
Vinnie Falco
8b71afa63f Remove extraneous header file status.hpp 2017-07-20 08:12:07 -07:00
Vinnie Falco
2b212e8844 Add usage example to rfc7230 javadocs 2017-07-20 08:12:07 -07:00
Vinnie Falco
19f15046b0 Fixes and documentation for teardown and use with SSL:
This solves a problem where clang and gcc locate the deleted
version of teardown and async_teardown instead of the overloaded
version. It requires overloads to add `teardown_tag` into the signature
so that the rules for argument dependent lookup can find the
right function. Improve documentation of teardown requirements

The documentation is updated to clearly explain the need for including
<beast/websocket/ssl.hpp> to use SSL streams with WebSocket.

The default implementations of teardown and async_teardown now use
static_assert to alert the user of improper usage, with comments
providing guidance for resolving the error.
2017-07-20 08:12:07 -07:00
Vinnie Falco
64206b5612 Qualify some calls:
This fixes a problem where a call to read() is ambiguous because
the argument list contains objects from both boost::asio and
beast::http.

Users invoking read may need to do so fully qualified, by writing:
    beast::http::read(...);
2017-07-20 08:12:07 -07:00
Vinnie Falco
62219add69 Initialize Writer in prepare:
Writer requires a call to Writer::init to call content_length. This
changes prepare to correctly call init. A consequences is that
prepare can now throw unexpectedly for user-defined writers that
can fail their initialization.
2017-07-20 08:12:07 -07:00
Vinnie Falco
227c2b131d Set Beast version to 1.0.0-b6 2017-07-20 08:12:07 -07:00
Vinnie Falco
589e18c199 rfc7230 compliance, limits, and tests for basic_parser_v1:
New parser set_option function for controlling independent size limits
on headers and body. By default request and response parsers are set up
with reasonable limits to prevent resource exhaustion attacks.

* Parser adheres strictly to rfc7230
* Increased test coverage
* Headers and body maximum size limit options
2017-07-20 08:12:07 -07:00
Vinnie Falco
6c30ee1a98 Rename concept to DynamicBuffer (API change):
Conform to the Networking TS by renaming the Streambuf concept
to DynamicBuffer in all places. Values of types meeting the
requirements of DynamicBuffer are renamed to dynabuf.

See:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4478.html#requirements.dynamic_buffers

* Headers renamed
* Formal parameter names renamed
* Template argument types renamed
* Documentation updated
2017-07-20 08:12:07 -07:00
Vinnie Falco
e8019fa9d4 Add message swap members and free functions 2017-07-20 08:12:07 -07:00
Vinnie Falco
db68ce4d97 Add HTTP field value parsers:
ext_list:
    Iterable container of comma separated extensions, where each extension
    is a token followed an optional list of semicolon delimited parameters,
    with each parameter consisting of a name / value pair. The value can
    be a token or quoted-string.

param_list:
    Iterable container of semicolon delimited parameters, where each parameter
    is a name / value pair. The value can be a token or quoted-string.

token_list
    Iterable container of comma delimited tokens.

* Remove obsolete rfc2616 functions

* Refactor and consolidate case-insensitive string helpers
2017-07-20 08:12:07 -07:00
Vinnie Falco
8743a7a399 Tidy up use of GENERATING_DOCS 2017-07-20 08:12:07 -07:00
Vinnie Falco
3406729a8d Use beast::error_code instead of nested types 2017-07-20 08:12:07 -07:00
Vinnie Falco
8686b28cf2 Use SFINAE on return values 2017-07-20 08:12:07 -07:00
Vinnie Falco
b90aae26ab Set Beast version to 1.0.0-b5 2017-07-20 08:12:07 -07:00
Vinnie Falco
19256b85f0 HTTP improvements:
* Increased code coverage

* New Body concepts:
    is_Body
    is_ReadableBody
    is_WritableBody
2017-07-20 08:12:07 -07:00
Vinnie Falco
039244cda4 WebSocket ping, fixes, coverage:
* Improve test coverage
* tests for invokable in composed ops

* Update documentation
* Add License badge to README
* Target Windows 7 SDK and later
* Make role_type private
* Remove extra unused masking functions
* Allow stream reuse / reconnect after failure
* Restructure logic of composed operations
* Allow 0 for read_message_max meaning no limit
* Respect keep alive when building HTTP responses
* Check version in upgrade request
* Response with 426 status on unsupported WebSocket version
* Remove unnecessary Sec-WebSocket-Key in HTTP responses
* Rename to mask_buffer_size

* Remove maybe_throw
* Add ping, async_ping, async_on_pong
* Add ping_op
* Add pong_op
* Fix crash in accept_op
* Fix suspend in close_op
* Fix read_frame_op logic
* Fix crash in read_op
* Fix races in echo sync and async echo servers
2017-07-20 08:12:07 -07:00
Vinnie Falco
bfb840fe8e Fix parser off by one accessing buffer bug:
This fixed a bug where in some cases the parser could dereference
past the end of the caller provided buffer. The unit test is
improved to allocate memory in separate pieces for the split-buffer
matrix test, to give address-sanitizer more to work with.
2017-07-20 08:12:07 -07:00
Vinnie Falco
0d69868051 Fix resume of invokables in websocket composed operations:
When a suspended composed operation is resumed, the operation
now posts to the io_service to get in the correct context. Previously,
invokables resumed in the context of a different completion handler.

* asio_handler_invoke for any resumed invokable will return `true`.
2017-07-20 08:12:07 -07:00
Vinnie Falco
908794bab2 Add dstream 2017-07-20 08:12:07 -07:00
Vinnie Falco
82f1661a47 Set Beast version to 1.0.0-b4 2017-07-20 08:12:07 -07:00
seelabs
da78f3cec4 Tidying and fix warnings 2017-07-20 08:12:07 -07:00
Vinnie Falco
4f1b9089b8 Parser concept, fixes:
A new concept Parser is introduced with routines to read from a stream
into the parser. This solves a problem with the old read interface where
messages must be default constructible and move assignable.

Parser fixes:

* Fix detect invalid reason-phrase octets
* Fix write_eof to set the 'complete' state on success
* Fix consider parse complete if eof received on empty body

WebSocket:

* Increase coverage
2017-07-20 08:12:06 -07:00
Vinnie Falco
b62d1b2164 Fixes, fail testing:
Core:

* Test buffer_cat iterator move members

HTTP:

* Fixed yield / resume in writer
* Fixed message serialization with chunked encoding

* Test yield / resume in writer
* Test all conditional branches during message serialization
* Test chunked encoding
* Increase coverage on parse_error
* Add parse_error::general

WebSocket:

* Add error::general
* Increase coverage in error
2017-07-20 08:12:06 -07:00
Vinnie Falco
c49cde844b New constructors for message:
The message class now behaves like a pair with respect to the construction
of the body and headers. Additional constructors allow construction of
just the body portion from a tuple, leaving the headers default
constructed.

Previous constructors are removed as they were a notational convenience
for assembling HTTP/1 requests and responses. They are not necessary
as this library aims at library writers and not end users.
2017-07-20 08:12:06 -07:00
Vinnie Falco
3484996048 Tidy up core sources:
The core headers are moved to their own directory (but remain in
the same namespace).
2017-07-20 08:12:06 -07:00
Vinnie Falco
a59329ff8e Improvements to code coverage:
More tests and test cases are added to bring up
the percentage of library code covered by tests.
2017-07-20 08:12:06 -07:00
seelabs
427c35f5e1 Fix invalid access after async initiation 2017-07-20 08:12:06 -07:00
Vinnie Falco
b14434456c Refactor extras:
A new directory extras/ is added, and code not part of the official
public Beast interface is moved there.
2017-07-20 08:12:06 -07:00
Vinnie Falco
133e7a3b16 Improvements to increase code coverage:
* Don't include the test code in coverage reports
* Add test code for missing coverage

Other:

* Improve the README.md
* Fix warning in sha1_context
* Tidy up the examples use of namespaces
* Various fixes to documentation and javadocs
2017-07-20 08:12:06 -07:00
Vinnie Falco
4bbf393e38 Tidy up declarations and files:
* Adjust formatting
* Fix inline namespace warning in main.cpp
* Fix streambuf op ambiguous variadic constructor
* Rename variables for clarity
2017-07-20 08:12:06 -07:00
Vinnie Falco
96e1e53cdd Don't perform an extra clear 2017-07-20 08:12:06 -07:00
Vinnie Falco
79913e6759 Fix SHA1 calculation 2017-07-20 08:12:06 -07:00
Vinnie Falco
63aef56942 Set Beast version to 1.0.0-b3 2017-07-20 08:12:06 -07:00
Vinnie Falco
313620ce7e Tidy up tests, build scripts, and documentation:
* Concepts split up into individual files
* Function definitions moved to .ipp files
* Add more tests to fill gaps in coverage
* Fix documentation Xsl
2017-07-20 08:12:06 -07:00
Vinnie Falco
c309f53ed2 Distinguish HTTP/1 messages from general HTTP messages:
The version field is moved into message_v1, all public interfaces
are reworked to identify HTTP/1 wire format operations (suffix "_v1")
versus general HTTP.
2017-07-20 08:12:05 -07:00
seelabs
e552ba7c2d Fix invokable order of invocation:
The call to the final handler in a composed operation MUST be
the last thing performed, as the handler may cause the end of
object lifetimes before it returns.
2017-07-20 08:12:05 -07:00
Vinnie Falco
4104eca1f1 WebSocket refactoring and tests:
websocket:

* Move echo server to test/
* Fix warnings
* Fix maskgen being uncopyable
* Simplify utf8_checker special member declarations
* Fix stream move assignable when owning the next layer
* Add javadocs for stream special members
* Add stream unit tests
* Move throwing member definitions to the .ipp file
* Use get_lowest_layer in stream declaration
* Perform type checks at each call site instead of constructor
* Demote close_code to a non-class enum:
    Otherwise, application specific close codes
    cannot be assigned without using static_cast.

core:

* Add streambuf_readstream special members tests
* Add move assignment operator to streambuf_readstream
* Add detail/get_lowest_layer trait
* Add static_string tests
* Move static_string from websocket to core
2017-07-20 08:12:05 -07:00
Vinnie Falco
a0b04bdff2 Refactor beast core, http, tests, and examples:
* Fix warnings
* Port cmake scripts to linux
* Add command line options for running test suites
* Add examples to CMakeLists
* Return std::uint64_t from writer::content_length
* basic_parser::write takes asio::const_buffer instead of pointer and size
* Turn message test back on now that it passes
* Rename to http::headers, use std::allocator, remove http_headers
* http::message::method is now a string
* Refactor to_string for ConstBufferSequence
* Remove chunk_encode from the public interface
* Initialize members for default constructed iterators
* Disallow default construction for dependent buffer sequences

Refactor http::message serialization:

* Serialization no longer creates a copy of the
  headers and modifies them
* New function prepare(), sets Connection, Transfer-Encoding,
  Content-Length based on the body attributes and caller options.
  Callers can use prepare() to have the fields set automatically,
  or they can set the fields manually.
* Use write for operator<<
* Tests for serialization
2017-07-20 08:12:05 -07:00
seelabs
43a81ff1a7 Fix destruction of basic_headers elements:
* Add missing call to destroy
* Use traits to destroy the element
2017-07-20 08:12:05 -07:00
Vinnie Falco
9a3a42a644 Truncate history, version 1.0.0-b2 2017-07-20 08:01:46 -07:00