Skip to content

Latest commit

 

History

History
127 lines (72 loc) · 5.5 KB

Utilities.rst

File metadata and controls

127 lines (72 loc) · 5.5 KB

Separate Utilities

These are some useful utilities included with SHOW, but in their own header files so they're optional.

Base-64 Encoding

These are utilities for handling base64-encoded strings, very commonly used for transporting binary data in web applications. They are included in show/base64.hpp.

Multipart Content Support

Multipart content is used to send a number of data segments each with their own separate headers. As such, text and binary data can be mixed in the same message.

SHOW provides the following utilities for parsing multipart requests in show/multipart.hpp. Typically, the Content-Type header for these types of requests will look something like:

Content-Type: multipart/form-data; boundary=AaB03x

The boundary string must be extracted from the header to pass to :cppmultipart's constructor. A simple example with no error handling:

const auto& header_value = request.headers()[ "Content-Type" ][ 0 ];
auto content_supertype = header_value.substr( 0, header_value.find( "/" ) )
if( content_supertype == "multipart" )
{
    show::multipart parser{
        request,
        header_value.substr( header_value.find( "boundary=" ) + 9 )
    };

    // Iterate over multipart data ...
}
else
    // Process data as single message ...