123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925 |
- //
- // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
- // Copyright (c) 2022 Alan de Freitas (alandefreitas@gmail.com)
- //
- // 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)
- //
- // Official repository: https://github.com/boostorg/url
- //
- #ifndef BOOST_URL_URL_BASE_HPP
- #define BOOST_URL_URL_BASE_HPP
- #include <boost/url/detail/config.hpp>
- #include <boost/url/ipv4_address.hpp>
- #include <boost/url/ipv6_address.hpp>
- #include <boost/url/params_encoded_ref.hpp>
- #include <boost/url/params_ref.hpp>
- #include <boost/url/pct_string_view.hpp>
- #include <boost/url/scheme.hpp>
- #include <boost/url/segments_encoded_ref.hpp>
- #include <boost/url/segments_ref.hpp>
- #include <boost/url/url_view_base.hpp>
- #include <cstdint>
- #include <initializer_list>
- #include <memory>
- #include <string>
- #include <utility>
- namespace boost {
- namespace urls {
- #ifndef BOOST_URL_DOCS
- namespace detail {
- struct any_params_iter;
- struct any_segments_iter;
- struct params_iter_impl;
- struct segments_iter_impl;
- struct pattern;
- }
- #endif
- /** Common functionality for containers
- This base class is used by the library
- to provide common member functions for
- containers. This cannot be instantiated
- directly; Instead, use one of the
- containers or functions:
- @par Containers
- @li @ref url
- @li @ref url_view
- @li @ref static_url
- @par Functions
- @li @ref parse_absolute_uri
- @li @ref parse_origin_form
- @li @ref parse_relative_ref
- @li @ref parse_uri
- @li @ref parse_uri_reference
- */
- class BOOST_URL_DECL
- url_base
- : public url_view_base
- {
- char* s_ = nullptr;
- std::size_t cap_ = 0;
- friend class url;
- friend class static_url_base;
- friend class params_ref;
- friend class segments_ref;
- friend class segments_encoded_ref;
- friend class params_encoded_ref;
- #ifndef BOOST_URL_DOCS
- friend struct detail::pattern;
- #endif
- struct op_t
- {
- ~op_t();
- op_t(url_base&,
- core::string_view* = nullptr,
- core::string_view* = nullptr) noexcept;
- void move(char*, char const*,
- std::size_t) noexcept;
- url_base& u;
- core::string_view* s0 = nullptr;
- core::string_view* s1 = nullptr;
- char* old = nullptr;
- };
- virtual ~url_base() noexcept = default;
- url_base() noexcept = default;
- url_base(detail::url_impl const&) noexcept;
- explicit url_base(core::string_view);
- void reserve_impl(std::size_t n);
- void copy(url_view_base const&);
- virtual void clear_impl() noexcept = 0;
- virtual void reserve_impl(
- std::size_t, op_t&) = 0;
- virtual void cleanup(op_t&) = 0;
- public:
- //--------------------------------------------
- //
- // Observers
- //
- //--------------------------------------------
- /** Return the url as a null-terminated string
- This function returns a pointer to a null
- terminated string representing the url,
- which may contain percent escapes.
- @par Example
- @code
- assert( std::strlen( url( "http://www.example.com" ).c_str() ) == 22 );
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- */
- char const*
- c_str() const noexcept
- {
- return pi_->cs_;
- }
- /** Return the number of characters that can be stored without reallocating
- This does not include the null terminator,
- which is always present.
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- */
- std::size_t
- capacity() const noexcept
- {
- return cap_;
- }
- /** Clear the contents while preserving the capacity
- @par Postconditions
- @code
- this->empty() == true
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- No-throw guarantee.
- */
- void
- clear() noexcept
- {
- this->clear_impl();
- }
- /** Adjust the capacity without changing the size
- This function adjusts the capacity
- of the container in characters, without
- affecting the current contents. Has
- no effect if `n <= this->capacity()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @throw bad_alloc Allocation failure
- @param n The capacity in characters,
- excluding any null terminator.
- */
- void
- reserve(std::size_t n)
- {
- reserve_impl(n);
- }
- //--------------------------------------------
- //
- // Fluent API
- //
- //--------------------------------------------
- //
- // Scheme
- //
- //--------------------------------------------
- /** Set the scheme
- The scheme is set to the specified
- string, which must contain a valid
- scheme without any trailing colon
- (':').
- Note that schemes are case-insensitive,
- and the canonical form is lowercased.
- @par Example
- @code
- assert( url( "http://www.example.com" ).set_scheme( "https" ).scheme_id() == scheme::https );
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid scheme.
- @param s The scheme to set.
- @par BNF
- @code
- scheme = ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">
- 3.1. Scheme (rfc3986)</a>
- @see
- @ref remove_scheme.
- */
- url_base&
- set_scheme(core::string_view s);
- /** Set the scheme
- This function sets the scheme to the specified
- known @ref urls::scheme id, which may not be
- @ref scheme::unknown or else an exception is
- thrown. If the id is @ref scheme::none, this
- function behaves as if @ref remove_scheme
- were called.
- @par Example
- @code
- assert( url( "http://example.com/echo.cgi" ).set_scheme_id( scheme::wss ).buffer() == "wss://example.com/echo.cgi" );
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- The scheme is invalid.
- @param id The scheme to set.
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">
- 3.1. Scheme (rfc3986)</a>
- */
- url_base&
- #ifndef BOOST_URL_DOCS
- set_scheme_id(urls::scheme id);
- #else
- set_scheme_id(scheme id);
- #endif
- /** Remove the scheme
- This function removes the scheme if it
- is present.
- @par Example
- @code
- assert( url("http://www.example.com/index.htm" ).remove_scheme().buffer() == "//www.example.com/index.htm" );
- @endcode
- @par Postconditions
- @code
- this->has_scheme() == false && this->scheme_id() == scheme::none
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.1">
- 3.1. Scheme (rfc3986)</a>
- @see
- @ref set_scheme.
- */
- url_base&
- remove_scheme();
- //--------------------------------------------
- //
- // Authority
- //
- //--------------------------------------------
- /** Set the authority
- This function sets the authority
- to the specified string.
- The string may contain percent-escapes.
- @par Example
- @code
- assert( url().set_encoded_authority( "My%20Computer" ).has_authority() );
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_eror
- The string contains an invalid percent-encoding.
- @param s The authority string to set.
- @par BNF
- @code
- authority = [ userinfo "@" ] host [ ":" port ]
- userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
- host = IP-literal / IPv4address / reg-name
- port = *DIGIT
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">
- 3.2. Authority (rfc3986)</a>
- @see
- @ref remove_authority.
- */
- url_base&
- set_encoded_authority(
- pct_string_view s);
- /** Remove the authority
- This function removes the authority,
- which includes the userinfo, host, and
- a port if present.
- @par Example
- @code
- assert( url( "http://example.com/echo.cgi" ).remove_authority().buffer() == "http:/echo.cgi" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == false && this->has_userinfo() == false && this->has_port() == false
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- authority = [ userinfo "@" ] host [ ":" port ]
- userinfo = *( unreserved / pct-encoded / sub-delims / ":" )
- host = IP-literal / IPv4address / reg-name
- port = *DIGIT
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2">
- 3.2. Authority (rfc3986)</a>
- @see
- @ref set_encoded_authority.
- */
- url_base&
- remove_authority();
- //--------------------------------------------
- //
- // Userinfo
- //
- //--------------------------------------------
- /** Set the userinfo
- The userinfo is set to the given string,
- which may contain percent-escapes.
- Any special or reserved characters in the
- string are automatically percent-encoded.
- The effects on the user and password
- depend on the presence of a colon (':')
- in the string:
- @li If an unescaped colon exists, the
- characters up to the colon become
- the user and the rest of the characters
- after the colon become the password.
- In this case @ref has_password returns
- true. Otherwise,
- @li If there is no colon, the user is
- set to the string. The function
- @ref has_password returns false.
- @note
- The interpretation of the userinfo as
- individual user and password components
- is scheme-dependent. Transmitting
- passwords in URLs is deprecated.
- @par Example
- @code
- assert( url( "http://example.com" ).set_userinfo( "user:pass" ).encoded_user() == "user" );
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref remove_userinfo,
- @ref set_encoded_userinfo.
- */
- url_base&
- set_userinfo(
- core::string_view s);
- /** Set the userinfo.
- The userinfo is set to the given string,
- which may contain percent-escapes.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- The effects on the user and password
- depend on the presence of a colon (':')
- in the string:
- @li If an unescaped colon exists, the
- characters up to the colon become
- the user and the rest of the characters
- after the colon become the password.
- In this case @ref has_password returns
- true. Otherwise,
- @li If there is no colon, the user is
- set to the string. The function
- @ref has_password returns false.
- @note
- The interpretation of the userinfo as
- individual user and password components
- is scheme-dependent. Transmitting
- passwords in URLs is deprecated.
- @par Example
- @code
- assert( url( "http://example.com" ).set_encoded_userinfo( "john%20doe" ).user() == "john doe" );
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref remove_userinfo,
- @ref set_userinfo.
- */
- url_base&
- set_encoded_userinfo(
- pct_string_view s);
- /** Remove the userinfo
- This function removes the userinfo if
- present, without removing any authority.
- @par Example
- @code
- assert( url( "http://user@example.com" ).remove_userinfo().has_userinfo() == false );
- @endcode
- @par Postconditions
- @code
- this->has_userinfo() == false && this->encoded_userinfo().empty == true
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref set_encoded_userinfo,
- @ref set_userinfo.
- */
- url_base&
- remove_userinfo() noexcept;
- //--------------------------------------------
- /** Set the user
- This function sets the user part of the
- userinfo to the string.
- Any special or reserved characters in the
- string are automatically percent-encoded.
- @par Example
- @code
- assert( url().set_user("john doe").encoded_userinfo() == "john%20doe" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true && this->has_userinfo() == true
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref remove_password,
- @ref set_encoded_password,
- @ref set_encoded_user,
- @ref set_password.
- */
- url_base&
- set_user(
- core::string_view s);
- /** Set the user
- This function sets the user part of the
- userinfo the the string, which may
- contain percent-escapes.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- @par Example
- @code
- assert( url().set_encoded_user("john%20doe").userinfo() == "john doe" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true && this->has_userinfo() == true
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref remove_password,
- @ref set_encoded_password,
- @ref set_password,
- @ref set_user.
- */
- url_base&
- set_encoded_user(
- pct_string_view s);
- /** Set the password.
- This function sets the password in
- the userinfo to the string.
- Reserved characters in the string are
- percent-escaped in the result.
- @note
- The interpretation of the userinfo as
- individual user and password components
- is scheme-dependent. Transmitting
- passwords in URLs is deprecated.
- @par Example
- @code
- assert( url("http://user@example.com").set_password( "pass" ).encoded_userinfo() == "user:pass" );
- @endcode
- @par Postconditions
- @code
- this->has_password() == true && this->password() == s
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set. This string may
- contain any characters, including nulls.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref remove_password,
- @ref set_encoded_password,
- @ref set_encoded_user,
- @ref set_user.
- */
- url_base&
- set_password(
- core::string_view s);
- /** Set the password.
- This function sets the password in
- the userinfo to the string, which
- may contain percent-escapes.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- @note
- The interpretation of the userinfo as
- individual user and password components
- is scheme-dependent. Transmitting
- passwords in URLs is deprecated.
- @par Example
- @code
- assert( url("http://user@example.com").set_encoded_password( "pass" ).encoded_userinfo() == "user:pass" );
- @endcode
- @par Postconditions
- @code
- this->has_password() == true
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set. This string may
- contain any characters, including nulls.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref remove_password,
- @ref set_encoded_password,
- @ref set_encoded_user,
- @ref set_user.
- */
- url_base&
- set_encoded_password(
- pct_string_view s);
- /** Remove the password
- This function removes the password from
- the userinfo if a password exists. If
- there is no userinfo or no authority,
- the call has no effect.
- @note
- The interpretation of the userinfo as
- individual user and password components
- is scheme-dependent. Transmitting
- passwords in URLs is deprecated.
- @par Example
- @code
- assert( url( "http://user:pass@example.com" ).remove_password().authority().buffer() == "user@example.com" );
- @endcode
- @par Postconditions
- @code
- this->has_password() == false && this->encoded_password().empty() == true
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- userinfo = [ [ user ] [ ':' password ] ]
- user = *( unreserved / pct-encoded / sub-delims )
- password = *( unreserved / pct-encoded / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1">
- 3.2.1. User Information (rfc3986)</a>
- @see
- @ref set_encoded_password,
- @ref set_encoded_user,
- @ref set_password,
- @ref set_user.
- */
- url_base&
- remove_password() noexcept;
- //--------------------------------------------
- //
- // Host
- //
- //--------------------------------------------
- /** Set the host
- Depending on the contents of the passed
- string, this function sets the host:
- @li If the string is a valid IPv4 address,
- then the host is set to the address.
- The host type is @ref host_type::ipv4.
- @li If the string is a valid IPv6 address
- enclosed in square brackets, then the
- host is set to that address.
- The host type is @ref host_type::ipv6.
- @li If the string is a valid IPvFuture
- address enclosed in square brackets, then
- the host is set to that address.
- The host type is @ref host_type::ipvfuture.
- @li Otherwise, the host name is set to
- the string, which may be empty.
- Reserved characters in the string are
- percent-escaped in the result.
- The host type is @ref host_type::name.
- In all cases, when this function returns,
- the URL contains an authority.
- @par Example
- @code
- assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- host = IP-literal / IPv4address / reg-name
- IP-literal = "[" ( IPv6address / IPvFuture ) "]"
- reg-name = *( unreserved / pct-encoded / "-" / ".")
- @endcode
- @par Specification
- @li <a href="https://en.wikipedia.org/wiki/IPv4"
- >IPv4 (Wikipedia)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc4291"
- >IP Version 6 Addressing Architecture (rfc4291)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_address,
- @ref set_encoded_host_name,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipv6,
- @ref set_host_ipvfuture,
- @ref set_host_name.
- */
- url_base&
- set_host(
- core::string_view s);
- /** Set the host
- Depending on the contents of the passed
- string, this function sets the host:
- @li If the string is a valid IPv4 address,
- then the host is set to the address.
- The host type is @ref host_type::ipv4.
- @li If the string is a valid IPv6 address
- enclosed in square brackets, then the
- host is set to that address.
- The host type is @ref host_type::ipv6.
- @li If the string is a valid IPvFuture
- address enclosed in square brackets, then
- the host is set to that address.
- The host type is @ref host_type::ipvfuture.
- @li Otherwise, the host name is set to
- the string. This string can contain percent
- escapes, or can be empty.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- The host type is @ref host_type::name.
- In all cases, when this function returns,
- the URL contains an authority.
- @par Example
- @code
- assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- host = IP-literal / IPv4address / reg-name
- IP-literal = "[" ( IPv6address / IPvFuture ) "]"
- reg-name = *( unreserved / pct-encoded / "-" / ".")
- @endcode
- @par Specification
- @li <a href="https://en.wikipedia.org/wiki/IPv4"
- >IPv4 (Wikipedia)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc4291"
- >IP Version 6 Addressing Architecture (rfc4291)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host_address,
- @ref set_encoded_host_name,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipv6,
- @ref set_host_ipvfuture,
- @ref set_host_name.
- */
- url_base&
- set_encoded_host(pct_string_view s);
- /** Set the host to an address
- Depending on the contents of the passed
- string, this function sets the host:
- @li If the string is a valid IPv4 address,
- then the host is set to the address.
- The host type is @ref host_type::ipv4.
- @li If the string is a valid IPv6 address,
- then the host is set to that address.
- The host type is @ref host_type::ipv6.
- @li If the string is a valid IPvFuture,
- then the host is set to that address.
- The host type is @ref host_type::ipvfuture.
- @li Otherwise, the host name is set to
- the string, which may be empty.
- Reserved characters in the string are
- percent-escaped in the result.
- The host type is @ref host_type::name.
- In all cases, when this function returns,
- the URL contains an authority.
- @par Example
- @code
- assert( url( "http://www.example.com" ).set_host_address( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true
- @endcode
- @par Complexity
- Linear in `s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
- dec-octet = DIGIT ; 0-9
- / %x31-39 DIGIT ; 10-99
- / "1" 2DIGIT ; 100-199
- / "2" %x30-34 DIGIT ; 200-249
- / "25" %x30-35 ; 250-255
- IPv6address = 6( h16 ":" ) ls32
- / "::" 5( h16 ":" ) ls32
- / [ h16 ] "::" 4( h16 ":" ) ls32
- / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
- / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
- / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
- / [ *4( h16 ":" ) h16 ] "::" ls32
- / [ *5( h16 ":" ) h16 ] "::" h16
- / [ *6( h16 ":" ) h16 ] "::"
- ls32 = ( h16 ":" h16 ) / IPv4address
- ; least-significant 32 bits of address
- h16 = 1*4HEXDIG
- ; 16 bits of address represented in hexadecimal
- IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
- reg-name = *( unreserved / pct-encoded / "-" / ".")
- @endcode
- @par Specification
- @li <a href="https://en.wikipedia.org/wiki/IPv4"
- >IPv4 (Wikipedia)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc4291"
- >IP Version 6 Addressing Architecture (rfc4291)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_address,
- @ref set_encoded_host_name,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipv6,
- @ref set_host_ipvfuture,
- @ref set_host_name.
- */
- url_base&
- set_host_address(core::string_view s);
- /** Set the host to an address
- Depending on the contents of the passed
- string, this function sets the host:
- @li If the string is a valid IPv4 address,
- then the host is set to the address.
- The host type is @ref host_type::ipv4.
- @li If the string is a valid IPv6 address,
- then the host is set to that address.
- The host type is @ref host_type::ipv6.
- @li If the string is a valid IPvFuture,
- then the host is set to that address.
- The host type is @ref host_type::ipvfuture.
- @li Otherwise, the host name is set to
- the string. This string can contain percent
- escapes, or can be empty.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- The host type is @ref host_type::name.
- In all cases, when this function returns,
- the URL contains an authority.
- @par Example
- @code
- assert( url( "http://www.example.com" ).set_host( "127.0.0.1" ).buffer() == "http://127.0.0.1" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
- dec-octet = DIGIT ; 0-9
- / %x31-39 DIGIT ; 10-99
- / "1" 2DIGIT ; 100-199
- / "2" %x30-34 DIGIT ; 200-249
- / "25" %x30-35 ; 250-255
- IPv6address = 6( h16 ":" ) ls32
- / "::" 5( h16 ":" ) ls32
- / [ h16 ] "::" 4( h16 ":" ) ls32
- / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
- / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
- / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
- / [ *4( h16 ":" ) h16 ] "::" ls32
- / [ *5( h16 ":" ) h16 ] "::" h16
- / [ *6( h16 ":" ) h16 ] "::"
- ls32 = ( h16 ":" h16 ) / IPv4address
- ; least-significant 32 bits of address
- h16 = 1*4HEXDIG
- ; 16 bits of address represented in hexadecimal
- IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
- reg-name = *( unreserved / pct-encoded / "-" / ".")
- @endcode
- @par Specification
- @li <a href="https://en.wikipedia.org/wiki/IPv4"
- >IPv4 (Wikipedia)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc4291"
- >IP Version 6 Addressing Architecture (rfc4291)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_name,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipv6,
- @ref set_host_ipvfuture,
- @ref set_host_name.
- */
- url_base&
- set_encoded_host_address(
- pct_string_view s);
- /** Set the host to an address
- The host is set to the specified IPv4
- address.
- The host type is @ref host_type::ipv4.
- @par Example
- @code
- assert( url("http://www.example.com").set_host_ipv4( ipv4_address( "127.0.0.1" ) ).buffer() == "http://127.0.0.1" );
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Postconditions
- @code
- this->has_authority() == true && this->host_ipv4_address() == addr && this->host_type() == host_type::ipv4
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param addr The address to set.
- @par BNF
- @code
- IPv4address = dec-octet "." dec-octet "." dec-octet "." dec-octet
- dec-octet = DIGIT ; 0-9
- / %x31-39 DIGIT ; 10-99
- / "1" 2DIGIT ; 100-199
- / "2" %x30-34 DIGIT ; 200-249
- / "25" %x30-35 ; 250-255
- @endcode
- @par Specification
- @li <a href="https://en.wikipedia.org/wiki/IPv4"
- >IPv4 (Wikipedia)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_address,
- @ref set_encoded_host_name,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv6,
- @ref set_host_ipvfuture,
- @ref set_host_name.
- */
- url_base&
- set_host_ipv4(
- ipv4_address const& addr);
- /** Set the host to an address
- The host is set to the specified IPv6
- address.
- The host type is @ref host_type::ipv6.
- @par Example
- @code
- assert( url().set_host_ipv6( ipv6_address( "1::6:c0a8:1" ) ).authority().buffer() == "[1::6:c0a8:1]" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::ipv6
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param addr The address to set.
- @par BNF
- @code
- IPv6address = 6( h16 ":" ) ls32
- / "::" 5( h16 ":" ) ls32
- / [ h16 ] "::" 4( h16 ":" ) ls32
- / [ *1( h16 ":" ) h16 ] "::" 3( h16 ":" ) ls32
- / [ *2( h16 ":" ) h16 ] "::" 2( h16 ":" ) ls32
- / [ *3( h16 ":" ) h16 ] "::" h16 ":" ls32
- / [ *4( h16 ":" ) h16 ] "::" ls32
- / [ *5( h16 ":" ) h16 ] "::" h16
- / [ *6( h16 ":" ) h16 ] "::"
- ls32 = ( h16 ":" h16 ) / IPv4address
- ; least-significant 32 bits of address
- h16 = 1*4HEXDIG
- ; 16 bits of address represented in hexadecimal
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc4291"
- >IP Version 6 Addressing Architecture (rfc4291)</a>
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_address,
- @ref set_encoded_host_name,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipvfuture,
- @ref set_host_name.
- */
- url_base&
- set_host_ipv6(
- ipv6_address const& addr);
- /** Set the host to an address
- The host is set to the specified IPvFuture
- string.
- The host type is @ref host_type::ipvfuture.
- @par Example
- @code
- assert( url().set_host_ipvfuture( "v42.bis" ).buffer() == "//[v42.bis]" );
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Postconditions
- @code
- this->has_authority() == true && this->host_ipvfuture) == s && this->host_type() == host_type::ipvfuture
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- IPvFuture = "v" 1*HEXDIG "." 1*( unreserved / sub-delims / ":" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_address,
- @ref set_encoded_host_name,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipv6,
- @ref set_host_name.
- */
- url_base&
- set_host_ipvfuture(
- core::string_view s);
- /** Set the host to a name
- The host is set to the specified string,
- which may be empty.
- Reserved characters in the string are
- percent-escaped in the result.
- The host type is @ref host_type::name.
- @par Example
- @code
- assert( url( "http://www.example.com/index.htm").set_host_name( "localhost" ).host_address() == "localhost" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- reg-name = *( unreserved / pct-encoded / "-" / ".")
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_address,
- @ref set_encoded_host_name,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipv6,
- @ref set_host_ipvfuture.
- */
- url_base&
- set_host_name(
- core::string_view s);
- /** Set the host to a name
- The host is set to the specified string,
- which may contain percent-escapes and
- can be empty.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- The host type is @ref host_type::name.
- @par Example
- @code
- assert( url( "http://www.example.com/index.htm").set_encoded_host_name( "localhost" ).host_address() == "localhost" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true && this->host_ipv6_address() == addr && this->host_type() == host_type::name
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- reg-name = *( unreserved / pct-encoded / "-" / ".")
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.2">
- 3.2.2. Host (rfc3986)</a>
- @see
- @ref set_encoded_host,
- @ref set_encoded_host_address,
- @ref set_host,
- @ref set_host_address,
- @ref set_host_ipv4,
- @ref set_host_ipv6,
- @ref set_host_ipvfuture,
- @ref set_host_name.
- */
- url_base&
- set_encoded_host_name(
- pct_string_view s);
- //--------------------------------------------
- /** Set the port
- The port is set to the specified integer.
- @par Example
- @code
- assert( url( "http://www.example.com" ).set_port_number( 8080 ).authority().buffer() == "www.example.com:8080" );
- @endcode
- @par Postconditions
- @code
- this->has_authority() == true && this->has_port() == true && this->port_number() == n
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param n The port number to set.
- @par BNF
- @code
- authority = [ userinfo "@" ] host [ ":" port ]
- port = *DIGIT
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">
- 3.2.3. Port (rfc3986)</a>
- @see
- @ref remove_port,
- @ref set_port.
- */
- url_base&
- set_port_number(std::uint16_t n);
- /** Set the port
- This port is set to the string, which
- must contain only digits or be empty.
- An empty port string is distinct from
- having no port.
- @par Example
- @code
- assert( url( "http://www.example.com" ).set_port( "8080" ).authority().buffer() == "www.example.com:8080" );
- @endcode
- @par Postconditions
- @code
- this->has_port() == true && this->port_number() == n && this->port() == std::to_string(n)
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` does not contain a valid port.
- @param s The port string to set.
- @par BNF
- @code
- port = *DIGIT
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">
- 3.2.3. Port (rfc3986)</a>
- @see
- @ref remove_port,
- @ref set_port.
- */
- url_base&
- set_port(core::string_view s);
- /** Remove the port
- If a port exists, it is removed. The rest
- of the authority is unchanged.
- @par Example
- @code
- assert( url( "http://www.example.com:80" ).remove_port().authority().buffer() == "www.example.com" );
- @endcode
- @par Postconditions
- @code
- this->has_port() == false && this->port_number() == 0 && this->port() == ""
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- authority = [ userinfo "@" ] host [ ":" port ]
- port = *DIGIT
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3">
- 3.2.3. Port (rfc3986)</a>
- @see
- @ref set_port.
- */
- url_base&
- remove_port() noexcept;
- //--------------------------------------------
- //
- // Path
- //
- //--------------------------------------------
- /** Set if the path is absolute
- This function adjusts the path to make
- it absolute or not, depending on the
- parameter.
- @note
- If an authority is present, the path
- is always absolute. In this case, the
- function has no effect.
- @par Example
- @code
- url u( "path/to/file.txt" );
- assert( u.set_path_absolute( true ) );
- assert( u.buffer() == "/path/to/file.txt" );
- @endcode
- @par Postconditions
- @code
- this->is_path_absolute() == true && this->encoded_path().front() == '/'
- @endcode
- @return true on success.
- @par Complexity
- Linear in `this->size()`.
- @par BNF
- @code
- path = path-abempty ; begins with "/" or is empty
- / path-absolute ; begins with "/" but not "//"
- / path-noscheme ; begins with a non-colon segment
- / path-rootless ; begins with a segment
- / path-empty ; zero characters
- path-abempty = *( "/" segment )
- path-absolute = "/" [ segment-nz *( "/" segment ) ]
- path-noscheme = segment-nz-nc *( "/" segment )
- path-rootless = segment-nz *( "/" segment )
- path-empty = 0<pchar>
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3"
- >3.3. Path (rfc3986)</a>
- @see
- @ref encoded_segments,
- @ref segments,
- @ref set_encoded_path,
- @ref set_path.
- */
- bool
- set_path_absolute(bool absolute);
- /** Set the path.
- This function sets the path to the
- string, which may be empty.
- Reserved characters in the string are
- percent-escaped in the result.
- @note
- The library may adjust the final result
- to ensure that no other parts of the url
- is semantically affected.
- @note
- This function does not encode '/' chars, which
- are unreserved for paths but reserved for
- path segments. If a path segment should include
- encoded '/'s to differentiate it from path separators,
- the functions @ref set_encoded_path or @ref segments
- should be used instead.
- @par Example
- @code
- url u( "http://www.example.com" );
- u.set_path( "path/to/file.txt" );
- assert( u.path() == "/path/to/file.txt" );
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- path = path-abempty ; begins with "/" or is empty
- / path-absolute ; begins with "/" but not "//"
- / path-noscheme ; begins with a non-colon segment
- / path-rootless ; begins with a segment
- / path-empty ; zero characters
- path-abempty = *( "/" segment )
- path-absolute = "/" [ segment-nz *( "/" segment ) ]
- path-noscheme = segment-nz-nc *( "/" segment )
- path-rootless = segment-nz *( "/" segment )
- path-empty = 0<pchar>
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3"
- >3.3. Path (rfc3986)</a>
- @see
- @ref encoded_segments,
- @ref segments,
- @ref set_encoded_path,
- @ref set_path_absolute.
- */
- url_base&
- set_path(
- core::string_view s);
- /** Set the path.
- This function sets the path to the
- string, which may contain percent-escapes
- and can be empty.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- @note
- The library may adjust the final result
- to ensure that no other parts of the url
- is semantically affected.
- @par Example
- @code
- url u( "http://www.example.com" );
- u.set_encoded_path( "path/to/file.txt" );
- assert( u.encoded_path() == "/path/to/file.txt" );
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- path = path-abempty ; begins with "/" or is empty
- / path-absolute ; begins with "/" but not "//"
- / path-noscheme ; begins with a non-colon segment
- / path-rootless ; begins with a segment
- / path-empty ; zero characters
- path-abempty = *( "/" segment )
- path-absolute = "/" [ segment-nz *( "/" segment ) ]
- path-noscheme = segment-nz-nc *( "/" segment )
- path-rootless = segment-nz *( "/" segment )
- path-empty = 0<pchar>
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3"
- >3.3. Path (rfc3986)</a>
- @see
- @ref encoded_segments,
- @ref segments,
- @ref set_path,
- @ref set_path_absolute.
- */
- url_base&
- set_encoded_path(
- pct_string_view s);
- /** Return the path as a container of segments
- This function returns a bidirectional
- view of segments over the path.
- The returned view references the same
- underlying character buffer; ownership
- is not transferred.
- Any percent-escapes in strings returned
- when iterating the view are decoded first.
- The container is modifiable; changes
- to the container are reflected in the
- underlying URL.
- @par Example
- @code
- url u( "http://example.com/path/to/file.txt" );
- segments sv = u.segments();
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- path = path-abempty ; begins with "/" or is empty
- / path-absolute ; begins with "/" but not "//"
- / path-noscheme ; begins with a non-colon segment
- / path-rootless ; begins with a segment
- / path-empty ; zero characters
- path-abempty = *( "/" segment )
- path-absolute = "/" [ segment-nz *( "/" segment ) ]
- path-noscheme = segment-nz-nc *( "/" segment )
- path-rootless = segment-nz *( "/" segment )
- path-empty = 0<pchar>
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3"
- >3.3. Path (rfc3986)</a>
- @see
- @ref encoded_segments,
- @ref set_encoded_path,
- @ref set_path,
- @ref set_path_absolute.
- */
- urls::segments_ref
- segments() noexcept;
- /// @copydoc url_view_base::segments
- segments_view
- segments() const noexcept
- {
- return url_view_base::segments();
- }
- /** Return the path as a container of segments
- This function returns a bidirectional
- view of segments over the path.
- The returned view references the same
- underlying character buffer; ownership
- is not transferred.
- Strings returned when iterating the
- range may contain percent escapes.
- The container is modifiable; changes
- to the container are reflected in the
- underlying URL.
- @par Example
- @code
- url u( "http://example.com/path/to/file.txt" );
- segments_encoded_ref sv = u.encoded_segments();
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- path = path-abempty ; begins with "/" or is empty
- / path-absolute ; begins with "/" but not "//"
- / path-noscheme ; begins with a non-colon segment
- / path-rootless ; begins with a segment
- / path-empty ; zero characters
- path-abempty = *( "/" segment )
- path-absolute = "/" [ segment-nz *( "/" segment ) ]
- path-noscheme = segment-nz-nc *( "/" segment )
- path-rootless = segment-nz *( "/" segment )
- path-empty = 0<pchar>
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.3"
- >3.3. Path (rfc3986)</a>
- @see
- @ref encoded_segments,
- @ref set_encoded_path,
- @ref set_path,
- @ref set_path_absolute.
- */
- segments_encoded_ref
- encoded_segments() noexcept;
- /// @copydoc url_view_base::encoded_segments
- segments_encoded_view
- encoded_segments() const noexcept
- {
- return url_view_base::encoded_segments();
- }
- //--------------------------------------------
- //
- // Query
- //
- //--------------------------------------------
- /** Set the query
- This sets the query to the string, which
- can be empty.
- An empty query is distinct from having
- no query.
- Reserved characters in the string are
- percent-escaped in the result.
- @par Example
- @code
- assert( url( "http://example.com" ).set_query( "id=42" ).query() == "id=42" );
- @endcode
- @par Postconditions
- @code
- this->has_query() == true && this->query() == s
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref encoded_params,
- @ref params,
- @ref remove_query,
- @ref set_encoded_query.
- */
- url_base&
- set_query(
- core::string_view s);
- /** Set the query
- This sets the query to the string, which
- may contain percent-escapes and can be
- empty.
- An empty query is distinct from having
- no query.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- @par Example
- @code
- assert( url( "http://example.com" ).set_encoded_query( "id=42" ).encoded_query() == "id=42" );
- @endcode
- @par Postconditions
- @code
- this->has_query() == true && this->query() == decode_view( s );
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @param s The string to set.
- @throws system_error
- `s` contains an invalid percent-encoding.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref encoded_params,
- @ref params,
- @ref remove_query,
- @ref set_query.
- */
- url_base&
- set_encoded_query(
- pct_string_view s);
- /** Return the query as a container of parameters
- This function returns a bidirectional
- view of key/value pairs over the query.
- The returned view references the same
- underlying character buffer; ownership
- is not transferred.
- Any percent-escapes in strings returned
- when iterating the view are decoded first.
- The container is modifiable; changes
- to the container are reflected in the
- underlying URL.
- @par Example
- @code
- params_ref pv = url( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).params();
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref encoded_params,
- @ref remove_query,
- @ref set_encoded_query,
- @ref set_query.
- */
- params_ref
- params() noexcept;
- /// @copydoc url_view_base::params
- params_view
- params() const noexcept
- {
- return url_view_base::params();
- }
- /** Return the query as a container of parameters
- This function returns a bidirectional
- view of key/value pairs over the query.
- The returned view references the same
- underlying character buffer; ownership
- is not transferred.
- Any percent-escapes in strings returned
- when iterating the view are decoded first.
- The container is modifiable; changes
- to the container are reflected in the
- underlying URL.
- @par Example
- @code
- encoding_opts opt;
- opt.space_as_plus = true;
- params_ref pv = url( "/sql?id=42&name=jane+doe&page+size=20" ).params(opt);
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- @param opt The options for decoding. If
- this parameter is omitted, the `space_as_plus`
- is used.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref encoded_params,
- @ref remove_query,
- @ref set_encoded_query,
- @ref set_query.
- */
- params_ref
- params(encoding_opts opt) noexcept;
- /// @copydoc url_view_base::encoded_params
- params_encoded_view
- encoded_params() const noexcept
- {
- return url_view_base::encoded_params();
- }
- /** Return the query as a container of parameters
- This function returns a bidirectional
- view of key/value pairs over the query.
- The returned view references the same
- underlying character buffer; ownership
- is not transferred.
- Strings returned when iterating the
- range may contain percent escapes.
- The container is modifiable; changes
- to the container are reflected in the
- underlying URL.
- @par Example
- @code
- params_encoded_ref pv = url( "/sql?id=42&name=jane%2Ddoe&page+size=20" ).encoded_params();
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref params,
- @ref remove_query,
- @ref set_encoded_query,
- @ref set_query.
- */
- params_encoded_ref
- encoded_params() noexcept;
- /** Set the query params
- This sets the query params to the list
- of param_view, which can be empty.
- An empty list of params is distinct from
- having no params.
- Reserved characters in the string are
- percent-escaped in the result.
- @par Example
- @code
- assert( url( "http://example.com" ).set_params( {"id", "42"} ).query() == "id=42" );
- @endcode
- @par Postconditions
- @code
- this->has_query() == true
- @endcode
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @par Complexity
- Linear.
- @param ps The params to set.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref encoded_params,
- @ref remove_query,
- @ref set_encoded_query,
- @ref set_query.
- */
- url_base&
- set_params( std::initializer_list<param_view> ps ) noexcept;
- /** Set the query params
- This sets the query params to the elements
- in the list, which may contain
- percent-escapes and can be empty.
- An empty list of params is distinct from
- having no query.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- @par Example
- @code
- assert( url( "http://example.com" ).set_encoded_params( {"id", "42"} ).encoded_query() == "id=42" );
- @endcode
- @par Postconditions
- @code
- this->has_query() == true
- @endcode
- @par Complexity
- Linear.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @param ps The params to set.
- @throws system_error
- some element in `ps` contains an invalid percent-encoding.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref set_params,
- @ref params,
- @ref remove_query,
- @ref set_encoded_query,
- @ref set_query.
- */
- url_base&
- set_encoded_params( std::initializer_list< param_pct_view > ps ) noexcept;
- /** Remove the query
- If a query is present, it is removed.
- An empty query is distinct from having
- no query.
- @par Example
- @code
- assert( url( "http://www.example.com?id=42" ).remove_query().buffer() == "http://www.example.com" );
- @endcode
- @par Postconditions
- @code
- this->has_query() == false && this->params().empty()
- @endcode
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- query = *( pchar / "/" / "?" )
- query-param = key [ "=" value ]
- query-params = [ query-param ] *( "&" query-param )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.4"
- >3.4. Query (rfc3986)</a>
- @li <a href="https://en.wikipedia.org/wiki/Query_string"
- >Query string (Wikipedia)</a>
- @see
- @ref encoded_params,
- @ref params,
- @ref set_encoded_query,
- @ref set_query.
- */
- url_base&
- remove_query() noexcept;
- //--------------------------------------------
- //
- // Fragment
- //
- //--------------------------------------------
- /** Remove the fragment
- This function removes the fragment.
- An empty fragment is distinct from
- having no fragment.
- @par Example
- @code
- assert( url( "?first=john&last=doe#anchor" ).remove_fragment().buffer() == "?first=john&last=doe" );
- @endcode
- @par Postconditions
- @code
- this->has_fragment() == false && this->encoded_fragment() == ""
- @endcode
- @par Complexity
- Constant.
- @par Exception Safety
- Throws nothing.
- @par BNF
- @code
- fragment = *( pchar / "/" / "?" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5"
- >3.5. Fragment</a>
- @see
- @ref remove_fragment,
- @ref set_encoded_fragment,
- @ref set_fragment.
- */
- url_base&
- remove_fragment() noexcept;
- /** Set the fragment.
- This function sets the fragment to the
- specified string, which may be empty.
- An empty fragment is distinct from
- having no fragment.
- Reserved characters in the string are
- percent-escaped in the result.
- @par Example
- @code
- assert( url("?first=john&last=doe" ).set_encoded_fragment( "john doe" ).encoded_fragment() == "john%20doe" );
- @endcode
- @par Postconditions
- @code
- this->has_fragment() == true && this->fragment() == s
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @param s The string to set.
- @par BNF
- @code
- fragment = *( pchar / "/" / "?" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5"
- >3.5. Fragment</a>
- @see
- @ref remove_fragment,
- @ref set_encoded_fragment.
- */
- url_base&
- set_fragment(
- core::string_view s);
- /** Set the fragment.
- This function sets the fragment to the
- specified string, which may contain
- percent-escapes and which may be empty.
- An empty fragment is distinct from
- having no fragment.
- Escapes in the string are preserved,
- and reserved characters in the string
- are percent-escaped in the result.
- @par Example
- @code
- assert( url("?first=john&last=doe" ).set_encoded_fragment( "john%2Ddoe" ).fragment() == "john-doe" );
- @endcode
- @par Postconditions
- @code
- this->has_fragment() == true && this->fragment() == decode_view( s )
- @endcode
- @par Complexity
- Linear in `this->size() + s.size()`.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- Exceptions thrown on invalid input.
- @throw system_error
- `s` contains an invalid percent-encoding.
- @param s The string to set.
- @par BNF
- @code
- fragment = *( pchar / "/" / "?" )
- @endcode
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-3.5"
- >3.5. Fragment</a>
- @see
- @ref remove_fragment,
- @ref set_fragment.
- */
- url_base&
- set_encoded_fragment(
- pct_string_view s);
- //--------------------------------------------
- //
- // Compound Fields
- //
- //--------------------------------------------
- /** Remove the origin component
- This function removes the origin, which
- consists of the scheme and authority.
- @par Example
- @code
- assert( url( "http://www.example.com/index.htm" ).remove_origin().buffer() == "/index.htm" );
- @endcode
- @par Postconditions
- @code
- this->scheme_id() == scheme::none && this->has_authority() == false
- @endcode
- @par Complexity
- Linear in `this->size()`.
- @par Exception Safety
- Throws nothing.
- */
- url_base&
- remove_origin();
- //--------------------------------------------
- //
- // Normalization
- //
- //--------------------------------------------
- /** Normalize the URL components
- Applies Syntax-based normalization to
- all components of the URL.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
- >6.2.2 Syntax-Based Normalization (rfc3986)</a>
- */
- url_base&
- normalize();
- /** Normalize the URL scheme
- Applies Syntax-based normalization to the
- URL scheme.
- The scheme is normalized to lowercase.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
- >6.2.2 Syntax-Based Normalization (rfc3986)</a>
- */
- url_base&
- normalize_scheme();
- /** Normalize the URL authority
- Applies Syntax-based normalization to the
- URL authority.
- Percent-encoding triplets are normalized
- to uppercase letters. Percent-encoded
- octets that correspond to unreserved
- characters are decoded.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
- >6.2.2 Syntax-Based Normalization (rfc3986)</a>
- */
- url_base&
- normalize_authority();
- /** Normalize the URL path
- Applies Syntax-based normalization to the
- URL path.
- Percent-encoding triplets are normalized
- to uppercase letters. Percent-encoded
- octets that correspond to unreserved
- characters are decoded. Redundant
- path-segments are removed.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
- >6.2.2 Syntax-Based Normalization (rfc3986)</a>
- */
- url_base&
- normalize_path();
- /** Normalize the URL query
- Applies Syntax-based normalization to the
- URL query.
- Percent-encoding triplets are normalized
- to uppercase letters. Percent-encoded
- octets that correspond to unreserved
- characters are decoded.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
- >6.2.2 Syntax-Based Normalization (rfc3986)</a>
- */
- url_base&
- normalize_query();
- /** Normalize the URL fragment
- Applies Syntax-based normalization to the
- URL fragment.
- Percent-encoding triplets are normalized
- to uppercase letters. Percent-encoded
- octets that correspond to unreserved
- characters are decoded.
- @par Exception Safety
- Strong guarantee.
- Calls to allocate may throw.
- @par Specification
- @li <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-6.2.2"
- >6.2.2 Syntax-Based Normalization (rfc3986)</a>
- */
- url_base&
- normalize_fragment();
- //
- // (end of fluent API)
- //
- //--------------------------------------------
- //--------------------------------------------
- //
- // Resolution
- //
- //--------------------------------------------
- /** Resolve a URL reference against this base URL
- This function attempts to resolve a URL
- reference `ref` against this base URL
- in a manner similar to that of a web browser
- resolving an anchor tag.
- This URL must satisfy the <em>URI</em>
- grammar. In other words, it must contain
- a scheme.
- Relative references are only usable when
- in the context of a base absolute URI.
- This process of resolving a relative
- <em>reference</em> within the context of
- a <em>base</em> URI is defined in detail
- in rfc3986 (see below).
- The resolution process works as if the
- relative reference is appended to the base
- URI and the result is normalized.
- Given the input base URL, this function
- resolves the relative reference
- as if performing the following steps:
- @li Ensure the base URI has at least a scheme
- @li Normalizing the reference path
- @li Merge base and reference paths
- @li Normalize the merged path
- This function places the result of the
- resolution into this URL in place.
- If an error occurs, the contents of
- this URL are unspecified and a @ref result
- with an `system::error_code` is returned.
- @note Abnormal hrefs where the number of ".."
- segments exceeds the number of segments in
- the base path are handled by including the
- unmatched ".." segments in the result, as described
- in <a href="https://www.rfc-editor.org/errata/eid4547"
- >Errata 4547</a>.
- @par Example
- @code
- url base1( "/one/two/three" );
- base1.resolve("four");
- assert( base1.buffer() == "/one/two/four" );
- url base2( "http://example.com/" )
- base2.resolve("/one");
- assert( base2.buffer() == "http://example.com/one" );
- url base3( "http://example.com/one" );
- base3.resolve("/two");
- assert( base3.buffer() == "http://example.com/two" );
- url base4( "http://a/b/c/d;p?q" );
- base4.resolve("g#s");
- assert( base4.buffer() == "http://a/b/c/g#s" );
- @endcode
- @par BNF
- @code
- absolute-URI = scheme ":" hier-part [ "?" query ]
- @endcode
- @par Exception Safety
- Basic guarantee.
- Calls to allocate may throw.
- @return An empty @ref result upon success,
- otherwise an error code if `!base.has_scheme()`.
- @param ref The URL reference to resolve.
- @par Specification
- <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-5"
- >5. Reference Resolution (rfc3986)</a>
- @see
- @ref url,
- @ref url_view.
- */
- system::result<void>
- resolve(
- url_view_base const& ref);
- friend
- system::result<void>
- resolve(
- url_view_base const& base,
- url_view_base const& ref,
- url_base& dest);
- private:
- //--------------------------------------------
- //
- // implementation
- //
- //--------------------------------------------
- void check_invariants() const noexcept;
- char* resize_impl(int, std::size_t, op_t&);
- char* resize_impl(int, int, std::size_t, op_t&);
- char* shrink_impl(int, std::size_t, op_t&);
- char* shrink_impl(int, int, std::size_t, op_t&);
- void set_scheme_impl(core::string_view, urls::scheme);
- char* set_user_impl(std::size_t n, op_t& op);
- char* set_password_impl(std::size_t n, op_t& op);
- char* set_userinfo_impl(std::size_t n, op_t& op);
- char* set_host_impl(std::size_t n, op_t& op);
- char* set_port_impl(std::size_t n, op_t& op);
- char* set_path_impl(std::size_t n, op_t& op);
- core::string_view
- first_segment() const noexcept;
- detail::segments_iter_impl
- edit_segments(
- detail::segments_iter_impl const&,
- detail::segments_iter_impl const&,
- detail::any_segments_iter&& it0,
- int absolute = -1);
- auto
- edit_params(
- detail::params_iter_impl const&,
- detail::params_iter_impl const&,
- detail::any_params_iter&&) ->
- detail::params_iter_impl;
- system::result<void>
- resolve_impl(
- url_view_base const& base,
- url_view_base const& ref);
- template<class CharSet>
- void normalize_octets_impl(int,
- CharSet const& allowed, op_t&) noexcept;
- void decoded_to_lower_impl(int id) noexcept;
- void to_lower_impl(int id) noexcept;
- };
- //------------------------------------------------
- /** Resolve a URL reference against a base URL
- This function attempts to resolve a URL
- reference `ref` against the base URL `base`
- in a manner similar to that of a web browser
- resolving an anchor tag.
- The base URL must satisfy the <em>URI</em>
- grammar. In other words, it must contain
- a scheme.
- Relative references are only usable when
- in the context of a base absolute URI.
- This process of resolving a relative
- <em>reference</em> within the context of
- a <em>base</em> URI is defined in detail
- in rfc3986 (see below).
- The resolution process works as if the
- relative reference is appended to the base
- URI and the result is normalized.
- Given the input base URL, this function
- resolves the relative reference
- as if performing the following steps:
- @li Ensure the base URI has at least a scheme
- @li Normalizing the reference path
- @li Merge base and reference paths
- @li Normalize the merged path
- This function places the result of the
- resolution into `dest`, which can be
- any of the url containers that inherit
- from @ref url_base.
- If an error occurs, the contents of
- `dest` is unspecified and `ec` is set.
- @note Abnormal hrefs where the number of ".."
- segments exceeds the number of segments in
- the base path are handled by including the
- unmatched ".." segments in the result, as described
- in <a href="https://www.rfc-editor.org/errata/eid4547"
- >Errata 4547</a>.
- @par Example
- @code
- url dest;
- system::error_code ec;
- resolve("/one/two/three", "four", dest, ec);
- assert( dest.str() == "/one/two/four" );
- resolve("http://example.com/", "/one", dest, ec);
- assert( dest.str() == "http://example.com/one" );
- resolve("http://example.com/one", "/two", dest, ec);
- assert( dest.str() == "http://example.com/two" );
- resolve("http://a/b/c/d;p?q", "g#s", dest, ec);
- assert( dest.str() == "http://a/b/c/g#s" );
- @endcode
- @par BNF
- @code
- absolute-URI = scheme ":" hier-part [ "?" query ]
- @endcode
- @par Exception Safety
- Basic guarantee.
- Calls to allocate may throw.
- @return An empty @ref result upon success,
- otherwise an error code if `!base.has_scheme()`.
- @param base The base URL to resolve against.
- @param ref The URL reference to resolve.
- @param dest The container where the result
- is written, upon success.
- @par Specification
- <a href="https://datatracker.ietf.org/doc/html/rfc3986#section-5"
- >5. Reference Resolution (rfc3986)</a>
- @see
- @ref url,
- @ref url_view.
- */
- inline
- system::result<void>
- resolve(
- url_view_base const& base,
- url_view_base const& ref,
- url_base& dest)
- {
- if (&dest != &base)
- dest.copy(base);
- return dest.resolve(ref);
- }
- } // urls
- } // boost
- // These are here because of circular references
- #include <boost/url/impl/params_ref.hpp>
- #include <boost/url/impl/params_encoded_ref.hpp>
- #include <boost/url/impl/segments_ref.hpp>
- #include <boost/url/impl/segments_encoded_ref.hpp>
- #endif
|