https://www.example.com/path/to/file.txt?userid=1001&page=2&results=full
You are viewing the master version of this library.
The master and develop pages are shown here to provide access to the newest in-development in-progress documentation. See the "Documentation" link on this page.
Other aspects of the page will reflect the previous official version, or not be available until the next release.
| Branch | master |
develop |
|---|---|---|
Docs |
||
Matrix |
Boost.URL is a portable C++ library which provides containers and algorithms which model a ``URL'', more formally described using the Uniform Resource Identifier (URI) specification (henceforth referred to as rfc3986). A URL is a compact sequence of characters that identifies an abstract or physical resource. For example, this is a valid URL which satisfies the absolute-URI grammar:
https://www.example.com/path/to/file.txt?userid=1001&page=2&results=full
This library understands the various grammars related to URLs and provides for validating and parsing of strings, manipulation of URL strings, and algorithms operating on URLs such as normalization and resolution. While the library is general purpose, special care has been taken to ensure that the implementation and data representation are friendly to network programs which need to handle URLs efficiently and securely, including the case where the inputs come from untrusted sources. Interfaces are provided for using error codes instead of exceptions as needed, and all algorithms provide a mechanism for avoiding memory allocations entirely if desired. Another feature of the library is that all container mutations leave the URL in a valid state. Code which uses Boost.URL will be easy to read, flexible, and performant.
Network programs such as those using Boost.Asio or Boost.Beast often encounter the need to process, generate, or modify URLs. This library provides a very much needed modular component for handling these use-cases.
using namespace boost::urls;
// Parse a URL. This allocates no memory. The view
// references the character buffer without taking ownership.
//
url_view uv( "https://www.example.com/path/to/file.txt?id=1001&name=John%20Doe&results=full" );
// Print the query parameters with percent-decoding applied
//
for( auto v : uv.params() )
std::cout << v.key << "=" << v.value << " ";
// Prints: id=1001 name=John Doe results=full
// Create a modifiable copy of `uv`, with ownership of the buffer
//
url u = uv;
// Change some elements in the URL
//
u.set_scheme( "http" )
.set_encoded_host( "boost.org" )
.set_encoded_path( "/index.htm" )
.remove_query()
.remove_fragment()
.params().append( {"key", "value"} );
std::cout << u;
// Prints: http://boost.org/index.htm?key=value
The library achieves these goals:
Require only C++11
Works without exceptions
Fast compilation, no templates
Strict compliance with rfc3986
Allocate memory or use inline storage
Optional header-only, without linking to a library
Requires Boost and a compiler supporting at least C++11
Aliases for standard types use their Boost equivalents
Link to a built static or dynamic Boost library, or use header-only (see below)
Supports -fno-exceptions, detected automatically
To use as header-only; that is, to eliminate the requirement to link a program to a static or dynamic Boost.URL library, simply place the following line in exactly one new or existing source file in your project.
#include <boost/url/src.hpp>
Boost.URL works great on embedded devices. It can be used in a way that avoids all dynamic memory allocations. Furthermore it is designed to work without exceptions if desired.
Boost.URL is tested with the following compilers:
clang: 3.8, 4, 5, 6, 7, 8, 9, 10, 11, 12
gcc: 4.8, 4.9, 5, 6, 7, 8, 9, 10, 11
msvc: 14.0, 14.1, 14.2, 14.3
and these architectures: x86, x64, ARM64, S390x
The development infrastructure for the library includes these per-commit analyses:
Coverage reports
Benchmark performance comparisons
Compilation and tests on Drone.io
cmake -G "Visual Studio 16 2019" -A Win32 -B bin -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/msvc.cmake cmake -G "Visual Studio 16 2019" -A x64 -B bin64 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/msvc.cmake
Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
<div class="paragraph"> <p><a href="http://master.url.cpp.al/"><span class="image"><img src="https://raw.githubusercontent.com/vinniefalco/url/master/doc/images/repo-logo.png" alt="Boost.URL"></span></a></p> </div> <table class="tableblock frame-all grid-all stretch"> <colgroup> <col style="width: 7%;"> <col style="width: 66%;"> <col style="width: 27%;"> </colgroup> <thead> <tr> <th class="tableblock halign-left valign-top">Branch</th> <th class="tableblock halign-left valign-top"><a href="https://github.com/boostorg/url/tree/master"><code>master</code></a></th> <th class="tableblock halign-left valign-top"><a href="https://github.com/boostorg/url/tree/develop"><code>develop</code></a></th> </tr> </thead> <tbody> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Docs</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://master.url.cpp.al/"><span class="image"><img src="https://img.shields.io/badge/docs-master-brightgreen.svg" alt="Documentation"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://develop.url.cpp.al/"><span class="image"><img src="https://img.shields.io/badge/docs-develop-brightgreen.svg" alt="Documentation"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://drone.io/">Drone</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://drone.cpp.al/boostorg/url"><span class="image"><img src="https://drone.cpp.al/api/badges/boostorg/url/status.svg?ref=refs/heads/master" alt="Build Status"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://drone.cpp.al/boostorg/url"><span class="image"><img src="https://drone.cpp.al/api/badges/boostorg/url/status.svg?ref=refs/heads/develop" alt="Build Status"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://github.com/">GitHub Actions</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://github.com/boostorg/url/actions/workflows/ci.yml"><span class="image"><img src="https://github.com/boostorg/url/actions/workflows/ci.yml/badge.svg?branch=master" alt="CI"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://github.com/boostorg/url/actions/workflows/ci.yml"><span class="image"><img src="https://github.com/boostorg/url/actions/workflows/ci.yml/badge.svg?branch=develop" alt="CI"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://codecov.io">codecov.io</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://codecov.io/gh/boostorg/url/branch/master"><span class="image"><img src="https://codecov.io/gh/boostorg/url/branch/master/graph/badge.svg" alt="codecov"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://codecov.io/gh/boostorg/url/branch/develop"><span class="image"><img src="https://codecov.io/gh/boostorg/url/branch/develop/graph/badge.svg" alt="codecov"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Matrix</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://www.boost.org/development/tests/master/developer/url.html"><span class="image"><img src="https://img.shields.io/badge/matrix-master-brightgreen.svg" alt="Matrix"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://www.boost.org/development/tests/develop/developer/url.html"><span class="image"><img src="https://img.shields.io/badge/matrix-develop-brightgreen.svg" alt="Matrix"></span></a></p></td> </tr> </tbody> </table> <div class="sect1"> <h2 id="_boost_url">Boost.URL</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_overview">Overview</h3> <div class="paragraph"> <p>Boost.URL is a portable C++ library which provides containers and algorithms which model a ``URL'', more formally described using the Uniform Resource Identifier (URI) specification (henceforth referred to as rfc3986). A URL is a compact sequence of characters that identifies an abstract or physical resource. For example, this is a valid URL which satisfies the absolute-URI grammar:</p> </div> <div class="literalblock"> <div class="content"> <pre>https://www.example.com/path/to/file.txt?userid=1001&page=2&results=full</pre> </div> </div> <div class="paragraph"> <p>This library understands the various grammars related to URLs and provides for validating and parsing of strings, manipulation of URL strings, and algorithms operating on URLs such as normalization and resolution. While the library is general purpose, special care has been taken to ensure that the implementation and data representation are friendly to network programs which need to handle URLs efficiently and securely, including the case where the inputs come from untrusted sources. Interfaces are provided for using error codes instead of exceptions as needed, and all algorithms provide a mechanism for avoiding memory allocations entirely if desired. Another feature of the library is that all container mutations leave the URL in a valid state. Code which uses Boost.URL will be easy to read, flexible, and performant.</p> </div> <div class="paragraph"> <p>Network programs such as those using Boost.Asio or Boost.Beast often encounter the need to process, generate, or modify URLs. This library provides a very much needed modular component for handling these use-cases.</p> </div> </div> <div class="sect2"> <h3 id="_example">Example</h3> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-cpp" data-lang="cpp">using namespace boost::urls; // Parse a URL. This allocates no memory. The view // references the character buffer without taking ownership. // url_view uv( "https://www.example.com/path/to/file.txt?id=1001&name=John%20Doe&results=full" ); // Print the query parameters with percent-decoding applied // for( auto v : uv.params() ) std::cout << v.key << "=" << v.value << " "; // Prints: id=1001 name=John Doe results=full // Create a modifiable copy of `uv`, with ownership of the buffer // url u = uv; // Change some elements in the URL // u.set_scheme( "http" ) .set_encoded_host( "boost.org" ) .set_encoded_path( "/index.htm" ) .remove_query() .remove_fragment() .params().append( {"key", "value"} ); std::cout << u; // Prints: http://boost.org/index.htm?key=value</code></pre> </div> </div> </div> <div class="sect2"> <h3 id="_design_goals">Design Goals</h3> <div class="paragraph"> <p>The library achieves these goals:</p> </div> <div class="ulist"> <ul> <li> <p>Require only C++11</p> </li> <li> <p>Works without exceptions</p> </li> <li> <p>Fast compilation, no templates</p> </li> <li> <p>Strict compliance with rfc3986</p> </li> <li> <p>Allocate memory or use inline storage</p> </li> <li> <p>Optional header-only, without linking to a library</p> </li> </ul> </div> </div> <div class="sect2"> <h3 id="_requirements">Requirements</h3> <div class="ulist"> <ul> <li> <p>Requires Boost and a compiler supporting at least C++11</p> </li> <li> <p>Aliases for standard types use their Boost equivalents</p> </li> <li> <p>Link to a built static or dynamic Boost library, or use header-only (see below)</p> </li> <li> <p>Supports -fno-exceptions, detected automatically</p> </li> </ul> </div> <div class="sect3"> <h4 id="_header_only">Header-Only</h4> <div class="paragraph"> <p>To use as header-only; that is, to eliminate the requirement to link a program to a static or dynamic Boost.URL library, simply place the following line in exactly one new or existing source file in your project.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-cpp" data-lang="cpp">#include <boost/url/src.hpp></code></pre> </div> </div> </div> <div class="sect3"> <h4 id="_embedded">Embedded</h4> <div class="paragraph"> <p>Boost.URL works great on embedded devices. It can be used in a way that avoids all dynamic memory allocations. Furthermore it is designed to work without exceptions if desired.</p> </div> </div> <div class="sect3"> <h4 id="_supported_compilers">Supported Compilers</h4> <div class="paragraph"> <p>Boost.URL is tested with the following compilers:</p> </div> <div class="ulist"> <ul> <li> <p>clang: 3.8, 4, 5, 6, 7, 8, 9, 10, 11, 12</p> </li> <li> <p>gcc: 4.8, 4.9, 5, 6, 7, 8, 9, 10, 11</p> </li> <li> <p>msvc: 14.0, 14.1, 14.2, 14.3</p> </li> </ul> </div> <div class="paragraph"> <p>and these architectures: x86, x64, ARM64, S390x</p> </div> </div> <div class="sect3"> <h4 id="_quality_assurance">Quality Assurance</h4> <div class="paragraph"> <p>The development infrastructure for the library includes these per-commit analyses:</p> </div> <div class="ulist"> <ul> <li> <p>Coverage reports</p> </li> <li> <p>Benchmark performance comparisons</p> </li> <li> <p>Compilation and tests on Drone.io</p> </li> </ul> </div> </div> </div> <div class="sect2"> <h3 id="_visual_studio_solution_generation">Visual Studio Solution Generation</h3> <div class="literalblock"> <div class="content"> <pre>cmake -G "Visual Studio 16 2019" -A Win32 -B bin -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/msvc.cmake cmake -G "Visual Studio 16 2019" -A x64 -B bin64 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/msvc.cmake</pre> </div> </div> </div> <div class="sect2"> <h3 id="_license">License</h3> <div class="paragraph"> <p>Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <a href="https://www.boost.org/LICENSE_1_0.txt" class="bare">https://www.boost.org/LICENSE_1_0.txt</a>)</p> </div> </div> </div> </div>
<div class="paragraph"> <p><a href="http://master.url.cpp.al/"><span class="image"><img src="https://raw.githubusercontent.com/vinniefalco/url/master/doc/images/repo-logo.png" alt="Boost.URL"></span></a></p> </div> <table class="tableblock frame-all grid-all stretch"> <colgroup> <col style="width: 7%;"> <col style="width: 66%;"> <col style="width: 27%;"> </colgroup> <thead> <tr> <th class="tableblock halign-left valign-top">Branch</th> <th class="tableblock halign-left valign-top"><a href="https://github.com/boostorg/url/tree/master"><code>master</code></a></th> <th class="tableblock halign-left valign-top"><a href="https://github.com/boostorg/url/tree/develop"><code>develop</code></a></th> </tr> </thead> <tbody> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Docs</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://master.url.cpp.al/"><span class="image"><img src="https://img.shields.io/badge/docs-master-brightgreen.svg" alt="Documentation"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://develop.url.cpp.al/"><span class="image"><img src="https://img.shields.io/badge/docs-develop-brightgreen.svg" alt="Documentation"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://drone.io/">Drone</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://drone.cpp.al/boostorg/url"><span class="image"><img src="https://drone.cpp.al/api/badges/boostorg/url/status.svg?ref=refs/heads/master" alt="Build Status"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://drone.cpp.al/boostorg/url"><span class="image"><img src="https://drone.cpp.al/api/badges/boostorg/url/status.svg?ref=refs/heads/develop" alt="Build Status"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://github.com/">GitHub Actions</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://github.com/boostorg/url/actions/workflows/ci.yml"><span class="image"><img src="https://github.com/boostorg/url/actions/workflows/ci.yml/badge.svg?branch=master" alt="CI"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://github.com/boostorg/url/actions/workflows/ci.yml"><span class="image"><img src="https://github.com/boostorg/url/actions/workflows/ci.yml/badge.svg?branch=develop" alt="CI"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://codecov.io">codecov.io</a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://codecov.io/gh/boostorg/url/branch/master"><span class="image"><img src="https://codecov.io/gh/boostorg/url/branch/master/graph/badge.svg" alt="codecov"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="https://codecov.io/gh/boostorg/url/branch/develop"><span class="image"><img src="https://codecov.io/gh/boostorg/url/branch/develop/graph/badge.svg" alt="codecov"></span></a></p></td> </tr> <tr> <td class="tableblock halign-left valign-top"><p class="tableblock">Matrix</p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://www.boost.org/development/tests/master/developer/url.html"><span class="image"><img src="https://img.shields.io/badge/matrix-master-brightgreen.svg" alt="Matrix"></span></a></p></td> <td class="tableblock halign-left valign-top"><p class="tableblock"><a href="http://www.boost.org/development/tests/develop/developer/url.html"><span class="image"><img src="https://img.shields.io/badge/matrix-develop-brightgreen.svg" alt="Matrix"></span></a></p></td> </tr> </tbody> </table> <div class="sect1"> <h2 id="_boost_url">Boost.URL</h2> <div class="sectionbody"> <div class="sect2"> <h3 id="_overview">Overview</h3> <div class="paragraph"> <p>Boost.URL is a portable C++ library which provides containers and algorithms which model a ``URL'', more formally described using the Uniform Resource Identifier (URI) specification (henceforth referred to as rfc3986). A URL is a compact sequence of characters that identifies an abstract or physical resource. For example, this is a valid URL which satisfies the absolute-URI grammar:</p> </div> <div class="literalblock"> <div class="content"> <pre>https://www.example.com/path/to/file.txt?userid=1001&page=2&results=full</pre> </div> </div> <div class="paragraph"> <p>This library understands the various grammars related to URLs and provides for validating and parsing of strings, manipulation of URL strings, and algorithms operating on URLs such as normalization and resolution. While the library is general purpose, special care has been taken to ensure that the implementation and data representation are friendly to network programs which need to handle URLs efficiently and securely, including the case where the inputs come from untrusted sources. Interfaces are provided for using error codes instead of exceptions as needed, and all algorithms provide a mechanism for avoiding memory allocations entirely if desired. Another feature of the library is that all container mutations leave the URL in a valid state. Code which uses Boost.URL will be easy to read, flexible, and performant.</p> </div> <div class="paragraph"> <p>Network programs such as those using Boost.Asio or Boost.Beast often encounter the need to process, generate, or modify URLs. This library provides a very much needed modular component for handling these use-cases.</p> </div> </div> <div class="sect2"> <h3 id="_example">Example</h3> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-cpp" data-lang="cpp">using namespace boost::urls; // Parse a URL. This allocates no memory. The view // references the character buffer without taking ownership. // url_view uv( "https://www.example.com/path/to/file.txt?id=1001&name=John%20Doe&results=full" ); // Print the query parameters with percent-decoding applied // for( auto v : uv.params() ) std::cout << v.key << "=" << v.value << " "; // Prints: id=1001 name=John Doe results=full // Create a modifiable copy of `uv`, with ownership of the buffer // url u = uv; // Change some elements in the URL // u.set_scheme( "http" ) .set_encoded_host( "boost.org" ) .set_encoded_path( "/index.htm" ) .remove_query() .remove_fragment() .params().append( {"key", "value"} ); std::cout << u; // Prints: http://boost.org/index.htm?key=value</code></pre> </div> </div> </div> <div class="sect2"> <h3 id="_design_goals">Design Goals</h3> <div class="paragraph"> <p>The library achieves these goals:</p> </div> <div class="ulist"> <ul> <li> <p>Require only C++11</p> </li> <li> <p>Works without exceptions</p> </li> <li> <p>Fast compilation, no templates</p> </li> <li> <p>Strict compliance with rfc3986</p> </li> <li> <p>Allocate memory or use inline storage</p> </li> <li> <p>Optional header-only, without linking to a library</p> </li> </ul> </div> </div> <div class="sect2"> <h3 id="_requirements">Requirements</h3> <div class="ulist"> <ul> <li> <p>Requires Boost and a compiler supporting at least C++11</p> </li> <li> <p>Aliases for standard types use their Boost equivalents</p> </li> <li> <p>Link to a built static or dynamic Boost library, or use header-only (see below)</p> </li> <li> <p>Supports -fno-exceptions, detected automatically</p> </li> </ul> </div> <div class="sect3"> <h4 id="_header_only">Header-Only</h4> <div class="paragraph"> <p>To use as header-only; that is, to eliminate the requirement to link a program to a static or dynamic Boost.URL library, simply place the following line in exactly one new or existing source file in your project.</p> </div> <div class="listingblock"> <div class="content"> <pre class="highlight"><code class="language-cpp" data-lang="cpp">#include <boost/url/src.hpp></code></pre> </div> </div> </div> <div class="sect3"> <h4 id="_embedded">Embedded</h4> <div class="paragraph"> <p>Boost.URL works great on embedded devices. It can be used in a way that avoids all dynamic memory allocations. Furthermore it is designed to work without exceptions if desired.</p> </div> </div> <div class="sect3"> <h4 id="_supported_compilers">Supported Compilers</h4> <div class="paragraph"> <p>Boost.URL is tested with the following compilers:</p> </div> <div class="ulist"> <ul> <li> <p>clang: 3.8, 4, 5, 6, 7, 8, 9, 10, 11, 12</p> </li> <li> <p>gcc: 4.8, 4.9, 5, 6, 7, 8, 9, 10, 11</p> </li> <li> <p>msvc: 14.0, 14.1, 14.2, 14.3</p> </li> </ul> </div> <div class="paragraph"> <p>and these architectures: x86, x64, ARM64, S390x</p> </div> </div> <div class="sect3"> <h4 id="_quality_assurance">Quality Assurance</h4> <div class="paragraph"> <p>The development infrastructure for the library includes these per-commit analyses:</p> </div> <div class="ulist"> <ul> <li> <p>Coverage reports</p> </li> <li> <p>Benchmark performance comparisons</p> </li> <li> <p>Compilation and tests on Drone.io</p> </li> </ul> </div> </div> </div> <div class="sect2"> <h3 id="_visual_studio_solution_generation">Visual Studio Solution Generation</h3> <div class="literalblock"> <div class="content"> <pre>cmake -G "Visual Studio 16 2019" -A Win32 -B bin -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/msvc.cmake cmake -G "Visual Studio 16 2019" -A x64 -B bin64 -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/msvc.cmake</pre> </div> </div> </div> <div class="sect2"> <h3 id="_license">License</h3> <div class="paragraph"> <p>Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at <a href="https://www.boost.org/LICENSE_1_0.txt" class="bare">https://www.boost.org/LICENSE_1_0.txt</a>)</p> </div> </div> </div> </div>