1ec865cb8SNiels Sascha Reedijk/* 2ec865cb8SNiels Sascha Reedijk * Copyright 2022 Haiku, Inc. All rights reserved. 3ec865cb8SNiels Sascha Reedijk * Distributed under the terms of the MIT License. 4ec865cb8SNiels Sascha Reedijk * 5ec865cb8SNiels Sascha Reedijk * Authors: 6ec865cb8SNiels Sascha Reedijk * Niels Sascha Reedijk, niels.reedijk@gmail.com 7ec865cb8SNiels Sascha Reedijk * 8ec865cb8SNiels Sascha Reedijk * Corresponds to: 9ec865cb8SNiels Sascha Reedijk * headers/private/netservices2/HttpRequest.h hrev????? 10ec865cb8SNiels Sascha Reedijk * src/kits/network/libnetservices2/HttpRequest.cpp hrev????? 11ec865cb8SNiels Sascha Reedijk */ 12ec865cb8SNiels Sascha Reedijk 13ec865cb8SNiels Sascha Reedijk 14ec865cb8SNiels Sascha Reedijk#if __cplusplus >= 201703L 15ec865cb8SNiels Sascha Reedijk 16ec865cb8SNiels Sascha Reedijk 17ec865cb8SNiels Sascha Reedijk/*! 18ec865cb8SNiels Sascha Reedijk \file HttpRequest.h 19ec865cb8SNiels Sascha Reedijk \ingroup netservices 20ec865cb8SNiels Sascha Reedijk \brief Provides the classes and tools to build HTTP Requests. 21ec865cb8SNiels Sascha Reedijk 22ec865cb8SNiels Sascha Reedijk \since Haiku R1 23ec865cb8SNiels Sascha Reedijk*/ 24ec865cb8SNiels Sascha Reedijk 25ec865cb8SNiels Sascha Reedijk 26ec865cb8SNiels Sascha Reedijknamespace BPrivate { 27ec865cb8SNiels Sascha Reedijk 28ec865cb8SNiels Sascha Reedijknamespace Network { 29ec865cb8SNiels Sascha Reedijk 30ec865cb8SNiels Sascha Reedijk 31ec865cb8SNiels Sascha Reedijk/*! 32ec865cb8SNiels Sascha Reedijk \class BHttpMethod 33ec865cb8SNiels Sascha Reedijk \ingroup netservices 34ec865cb8SNiels Sascha Reedijk \brief Represent a HTTP method. 35ec865cb8SNiels Sascha Reedijk 36ec865cb8SNiels Sascha Reedijk The <a href="https://datatracker.ietf.org/doc/html/rfc7231#section-4.1">HTTP standard</a> 37ec865cb8SNiels Sascha Reedijk specifies that HTTP requests have a method. Common methods are \c GET and \c HEAD methods. 38ec865cb8SNiels Sascha Reedijk Standardized and common methods are in the form of \em verbs and are in capitalized letters 39ec865cb8SNiels Sascha Reedijk from the ASCII token set, though any valid token can be used. 40ec865cb8SNiels Sascha Reedijk 41ec865cb8SNiels Sascha Reedijk It is most likely that you will not use the methods of this class directly, instead you will 42ec865cb8SNiels Sascha Reedijk use the implicit constructors while interacting with the \ref BHttpRequest class. 43ec865cb8SNiels Sascha Reedijk 44ec865cb8SNiels Sascha Reedijk \code 4559c359e5SNiels Sascha Reedijk auto url = BUrl("https://www.haiku-os.org/"); 46ec865cb8SNiels Sascha Reedijk // implicitly construct a standard get request 47ec865cb8SNiels Sascha Reedijk auto standard = BHttpRequest(url, BHttpMethod::Get); 48ec865cb8SNiels Sascha Reedijk // implicitly construct a nonstandard patch request 49ec865cb8SNiels Sascha Reedijk auto custom = BHttpRequest(url, "PATCH"sv); 50ec865cb8SNiels Sascha Reedijk \endcode 51ec865cb8SNiels Sascha Reedijk 52ec865cb8SNiels Sascha Reedijk \note When you are using the standard list of verbs, there will never be an exception when 53ec865cb8SNiels Sascha Reedijk creating objects of this type. When you create a custom method, exceptions may be raised 54ec865cb8SNiels Sascha Reedijk when the system runs out of memory, or when your custom method contains invalid characters. 55ec865cb8SNiels Sascha Reedijk In almost all cases, you can probably safely assume you will not run into these exceptions, 56ec865cb8SNiels Sascha Reedijk except for cases where you use user input to create methods or you are very defensive 57ec865cb8SNiels Sascha Reedijk about memory management. 58ec865cb8SNiels Sascha Reedijk 59ec865cb8SNiels Sascha Reedijk \since Haiku R1 60ec865cb8SNiels Sascha Reedijk*/ 61ec865cb8SNiels Sascha Reedijk 62ec865cb8SNiels Sascha Reedijk 63ec865cb8SNiels Sascha Reedijk/*! 64ec865cb8SNiels Sascha Reedijk \class BHttpMethod::InvalidMethod 65ec865cb8SNiels Sascha Reedijk \ingroup netservices 66ec865cb8SNiels Sascha Reedijk \brief Error that represents when a custom method does not conform to the HTTP standard. 67ec865cb8SNiels Sascha Reedijk 68ec865cb8SNiels Sascha Reedijk \since Haiku R1 69ec865cb8SNiels Sascha Reedijk*/ 70ec865cb8SNiels Sascha Reedijk 71ec865cb8SNiels Sascha Reedijk 72ec865cb8SNiels Sascha Reedijk/*! 73ec865cb8SNiels Sascha Reedijk \var BString BHttpMethod::InvalidMethod::input 74ec865cb8SNiels Sascha Reedijk \brief The input that contains the invalid contents. 75ec865cb8SNiels Sascha Reedijk 76ec865cb8SNiels Sascha Reedijk \since Haiku R1 77ec865cb8SNiels Sascha Reedijk*/ 78ec865cb8SNiels Sascha Reedijk 79ec865cb8SNiels Sascha Reedijk 80ec865cb8SNiels Sascha Reedijk/*! 81ec865cb8SNiels Sascha Reedijk \fn BHttpMethod::InvalidMethod::InvalidMethod(const char *origin, BString input) 82ec865cb8SNiels Sascha Reedijk \brief Constructor that sets the \a origin and the invalid \a input. 83ec865cb8SNiels Sascha Reedijk 84ec865cb8SNiels Sascha Reedijk \since Haiku R1 85ec865cb8SNiels Sascha Reedijk*/ 86ec865cb8SNiels Sascha Reedijk 87ec865cb8SNiels Sascha Reedijk 88ec865cb8SNiels Sascha Reedijk/*! 89ec865cb8SNiels Sascha Reedijk \enum BHttpMethod::Verb 90ec865cb8SNiels Sascha Reedijk \ingroup netservices 91ec865cb8SNiels Sascha Reedijk \brief A list of standard HTTP methods. 92ec865cb8SNiels Sascha Reedijk 93ec865cb8SNiels Sascha Reedijk \since Haiku R1 94ec865cb8SNiels Sascha Reedijk*/ 95ec865cb8SNiels Sascha Reedijk 96ec865cb8SNiels Sascha Reedijk 97ec865cb8SNiels Sascha Reedijk/*! 98ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Get 99ec865cb8SNiels Sascha Reedijk \brief Represents the \c GET method. 100ec865cb8SNiels Sascha Reedijk 101ec865cb8SNiels Sascha Reedijk \since Haiku R1 102ec865cb8SNiels Sascha Reedijk*/ 103ec865cb8SNiels Sascha Reedijk 104ec865cb8SNiels Sascha Reedijk 105ec865cb8SNiels Sascha Reedijk/*! 106ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Head 107ec865cb8SNiels Sascha Reedijk \brief Represents the \c HEAD method. 108ec865cb8SNiels Sascha Reedijk 109ec865cb8SNiels Sascha Reedijk \since Haiku R1 110ec865cb8SNiels Sascha Reedijk*/ 111ec865cb8SNiels Sascha Reedijk 112ec865cb8SNiels Sascha Reedijk 113ec865cb8SNiels Sascha Reedijk/*! 114ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Post 115ec865cb8SNiels Sascha Reedijk \brief Represents the \c POST method. 116ec865cb8SNiels Sascha Reedijk 117ec865cb8SNiels Sascha Reedijk \since Haiku R1 118ec865cb8SNiels Sascha Reedijk*/ 119ec865cb8SNiels Sascha Reedijk 120ec865cb8SNiels Sascha Reedijk 121ec865cb8SNiels Sascha Reedijk/*! 122ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Put 123ec865cb8SNiels Sascha Reedijk \brief Represents the \c PUT method. 124ec865cb8SNiels Sascha Reedijk 125ec865cb8SNiels Sascha Reedijk \since Haiku R1 126ec865cb8SNiels Sascha Reedijk*/ 127ec865cb8SNiels Sascha Reedijk 128ec865cb8SNiels Sascha Reedijk 129ec865cb8SNiels Sascha Reedijk/*! 130ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Delete 131ec865cb8SNiels Sascha Reedijk \brief Represents the \c DELETE method. 132ec865cb8SNiels Sascha Reedijk 133ec865cb8SNiels Sascha Reedijk \since Haiku R1 134ec865cb8SNiels Sascha Reedijk*/ 135ec865cb8SNiels Sascha Reedijk 136ec865cb8SNiels Sascha Reedijk 137ec865cb8SNiels Sascha Reedijk/*! 138ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Connect 139ec865cb8SNiels Sascha Reedijk \brief Represents the \c CONNECT method. 140ec865cb8SNiels Sascha Reedijk 141ec865cb8SNiels Sascha Reedijk \since Haiku R1 142ec865cb8SNiels Sascha Reedijk*/ 143ec865cb8SNiels Sascha Reedijk 144ec865cb8SNiels Sascha Reedijk 145ec865cb8SNiels Sascha Reedijk/*! 146ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Options 147ec865cb8SNiels Sascha Reedijk \brief Represents the \c OPTIONS method. 148ec865cb8SNiels Sascha Reedijk 149ec865cb8SNiels Sascha Reedijk \since Haiku R1 150ec865cb8SNiels Sascha Reedijk*/ 151ec865cb8SNiels Sascha Reedijk 152ec865cb8SNiels Sascha Reedijk 153ec865cb8SNiels Sascha Reedijk/*! 154ec865cb8SNiels Sascha Reedijk \var BHttpMethod::Verb BHttpMethod::Trace 155ec865cb8SNiels Sascha Reedijk \brief Represents the \c TRACE method. 156ec865cb8SNiels Sascha Reedijk 157ec865cb8SNiels Sascha Reedijk \since Haiku R1 158ec865cb8SNiels Sascha Reedijk*/ 159ec865cb8SNiels Sascha Reedijk 160ec865cb8SNiels Sascha Reedijk 161ec865cb8SNiels Sascha Reedijk/*! 162ec865cb8SNiels Sascha Reedijk \fn BHttpMethod::BHttpMethod(BHttpMethod &&other) noexcept 163ec865cb8SNiels Sascha Reedijk \brief Move constructor. 164ec865cb8SNiels Sascha Reedijk 165ec865cb8SNiels Sascha Reedijk Moves the data from the \a other to this object. The \a other object will be set to 166ec865cb8SNiels Sascha Reedijk \ref BHttpMethod::Get. 167ec865cb8SNiels Sascha Reedijk 168ec865cb8SNiels Sascha Reedijk \since Haiku R1 169ec865cb8SNiels Sascha Reedijk*/ 170ec865cb8SNiels Sascha Reedijk 171ec865cb8SNiels Sascha Reedijk 172ec865cb8SNiels Sascha Reedijk/*! 173ec865cb8SNiels Sascha Reedijk \fn BHttpMethod::BHttpMethod(const BHttpMethod &other) 174ec865cb8SNiels Sascha Reedijk \brief Copy constructor. 175ec865cb8SNiels Sascha Reedijk 176ec865cb8SNiels Sascha Reedijk Copy data from an \a other object. 177ec865cb8SNiels Sascha Reedijk 178ec865cb8SNiels Sascha Reedijk \exception std::bad_alloc When the \a other object contains a custom verb, this exception 179ec865cb8SNiels Sascha Reedijk will be raised if it is impossible to allocate memory. 180ec865cb8SNiels Sascha Reedijk 181ec865cb8SNiels Sascha Reedijk \since Haiku R1 182ec865cb8SNiels Sascha Reedijk*/ 183ec865cb8SNiels Sascha Reedijk 184ec865cb8SNiels Sascha Reedijk 185ec865cb8SNiels Sascha Reedijk/*! 186ec865cb8SNiels Sascha Reedijk \fn BHttpMethod::BHttpMethod(const std::string_view &method) 187ec865cb8SNiels Sascha Reedijk \brief Construct a custom method. 188ec865cb8SNiels Sascha Reedijk 189ec865cb8SNiels Sascha Reedijk \param method The verb for the method. 190ec865cb8SNiels Sascha Reedijk 191ec865cb8SNiels Sascha Reedijk \exception std::bad_alloc In case it is not possible to allocate memory for the custom string. 192ec865cb8SNiels Sascha Reedijk \exception BHttpMethod::InvalidMethod In case the \a method is empty or contains invalid 193ec865cb8SNiels Sascha Reedijk characters. 194ec865cb8SNiels Sascha Reedijk 195ec865cb8SNiels Sascha Reedijk \since Haiku R1 196ec865cb8SNiels Sascha Reedijk*/ 197ec865cb8SNiels Sascha Reedijk 198ec865cb8SNiels Sascha Reedijk 199ec865cb8SNiels Sascha Reedijk/*! 200ec865cb8SNiels Sascha Reedijk \fn BHttpMethod::BHttpMethod(Verb verb) noexcept 201ec865cb8SNiels Sascha Reedijk \brief Construct a standard method. 202ec865cb8SNiels Sascha Reedijk 203ec865cb8SNiels Sascha Reedijk \param verb The chosen method. 204ec865cb8SNiels Sascha Reedijk 205ec865cb8SNiels Sascha Reedijk \since Haiku R1 206ec865cb8SNiels Sascha Reedijk*/ 207ec865cb8SNiels Sascha Reedijk 208ec865cb8SNiels Sascha Reedijk 209ec865cb8SNiels Sascha Reedijk/*! 210ec865cb8SNiels Sascha Reedijk \fn BHttpMethod::~BHttpMethod() 211ec865cb8SNiels Sascha Reedijk \brief Destructor. 212ec865cb8SNiels Sascha Reedijk 213ec865cb8SNiels Sascha Reedijk \since Haiku R1 214ec865cb8SNiels Sascha Reedijk*/ 215ec865cb8SNiels Sascha Reedijk 216ec865cb8SNiels Sascha Reedijk 217ec865cb8SNiels Sascha Reedijk/*! 21859c359e5SNiels Sascha Reedijk \fn bool BHttpMethod::operator==(const Verb &other) const noexcept 21959c359e5SNiels Sascha Reedijk \brief Comparison operator. 22059c359e5SNiels Sascha Reedijk 22159c359e5SNiels Sascha Reedijk \param other The verb to compare to. 22259c359e5SNiels Sascha Reedijk 22359c359e5SNiels Sascha Reedijk \retval true This method is equal to \a other. 22459c359e5SNiels Sascha Reedijk \retval false This method is different from \a other. 22559c359e5SNiels Sascha Reedijk 22659c359e5SNiels Sascha Reedijk \since Haiku R1 22759c359e5SNiels Sascha Reedijk*/ 22859c359e5SNiels Sascha Reedijk 22959c359e5SNiels Sascha Reedijk 23059c359e5SNiels Sascha Reedijk/*! 23113bfff7bSNiels Sascha Reedijk \fn bool BHttpMethod::operator!=(const Verb &other) const noexcept 23213bfff7bSNiels Sascha Reedijk \brief Comparison operator. 23313bfff7bSNiels Sascha Reedijk 23413bfff7bSNiels Sascha Reedijk \param other The verb to compare to. 23513bfff7bSNiels Sascha Reedijk 23613bfff7bSNiels Sascha Reedijk \retval true This method is different from \a other. 23713bfff7bSNiels Sascha Reedijk \retval false This method is equal to \a other. 23813bfff7bSNiels Sascha Reedijk 23913bfff7bSNiels Sascha Reedijk \since Haiku R1 24013bfff7bSNiels Sascha Reedijk*/ 24113bfff7bSNiels Sascha Reedijk 24213bfff7bSNiels Sascha Reedijk 24313bfff7bSNiels Sascha Reedijk/*! 244ec865cb8SNiels Sascha Reedijk \fn const std::string_view BHttpMethod::Method() const noexcept 245ec865cb8SNiels Sascha Reedijk \brief Get a string representation of the method. 246ec865cb8SNiels Sascha Reedijk 247ec865cb8SNiels Sascha Reedijk \return A \c std::string_view that is a string representation of the standard or custom method 248ec865cb8SNiels Sascha Reedijk in this object. The lifetime of the string view is bound to the lifetime of this method. 249ec865cb8SNiels Sascha Reedijk 250ec865cb8SNiels Sascha Reedijk \since Haiku R1 251ec865cb8SNiels Sascha Reedijk*/ 252ec865cb8SNiels Sascha Reedijk 253ec865cb8SNiels Sascha Reedijk 254ec865cb8SNiels Sascha Reedijk/*! 255ec865cb8SNiels Sascha Reedijk \fn BHttpMethod& BHttpMethod::operator=(BHttpMethod &&other) noexcept 256ec865cb8SNiels Sascha Reedijk \brief Move assignment. 257ec865cb8SNiels Sascha Reedijk Moves the data from the \a other to this object. The \a other object will be set to 258ec865cb8SNiels Sascha Reedijk \ref BHttpMethod::Get. 259ec865cb8SNiels Sascha Reedijk 260ec865cb8SNiels Sascha Reedijk \since Haiku R1 261ec865cb8SNiels Sascha Reedijk*/ 262ec865cb8SNiels Sascha Reedijk 263ec865cb8SNiels Sascha Reedijk 264ec865cb8SNiels Sascha Reedijk/*! 26513bfff7bSNiels Sascha Reedijk \fn BHttpMethod& BHttpMethod::operator=(const BHttpMethod &other) 266ec865cb8SNiels Sascha Reedijk \brief Copy assignment. 267ec865cb8SNiels Sascha Reedijk 268ec865cb8SNiels Sascha Reedijk Copy data from an \a other object. 269ec865cb8SNiels Sascha Reedijk 270ec865cb8SNiels Sascha Reedijk \exception std::bad_alloc When the \a other object contains a custom verb, this exception 271ec865cb8SNiels Sascha Reedijk will be raised if it is impossible to allocate memory. 272ec865cb8SNiels Sascha Reedijk 273ec865cb8SNiels Sascha Reedijk \since Haiku R1 274ec865cb8SNiels Sascha Reedijk*/ 275ec865cb8SNiels Sascha Reedijk 276ec865cb8SNiels Sascha Reedijk 2776ce6e964SNiels Sascha Reedijk/*! 278f9d9d202SNiels Sascha Reedijk \struct BHttpAuthentication 279f9d9d202SNiels Sascha Reedijk \ingroup netservices 280f9d9d202SNiels Sascha Reedijk \brief Describe username and password for basic authentication for the request. 281f9d9d202SNiels Sascha Reedijk 282f9d9d202SNiels Sascha Reedijk \see These options are used by \ref BHttpRequest::Authentication() and 283f9d9d202SNiels Sascha Reedijk \ref BHttpRequest::SetAuthentication() 284f9d9d202SNiels Sascha Reedijk 285f9d9d202SNiels Sascha Reedijk \since Haiku R1 286f9d9d202SNiels Sascha Reedijk*/ 287f9d9d202SNiels Sascha Reedijk 288f9d9d202SNiels Sascha Reedijk 289f9d9d202SNiels Sascha Reedijk/*! 290f9d9d202SNiels Sascha Reedijk \var BString BHttpAuthentication::username 291f9d9d202SNiels Sascha Reedijk \brief The username for the request. 292f9d9d202SNiels Sascha Reedijk 293f9d9d202SNiels Sascha Reedijk \since Haiku R1 294f9d9d202SNiels Sascha Reedijk*/ 295f9d9d202SNiels Sascha Reedijk 296f9d9d202SNiels Sascha Reedijk 297f9d9d202SNiels Sascha Reedijk/*! 298f9d9d202SNiels Sascha Reedijk \var BString BHttpAuthentication::password 299f9d9d202SNiels Sascha Reedijk \brief The password for the request. 300f9d9d202SNiels Sascha Reedijk 301f9d9d202SNiels Sascha Reedijk \since Haiku R1 302f9d9d202SNiels Sascha Reedijk*/ 303f9d9d202SNiels Sascha Reedijk 304f9d9d202SNiels Sascha Reedijk 305f9d9d202SNiels Sascha Reedijk/*! 306*92357c13SNiels Sascha Reedijk \struct BHttpRequest::Body 307*92357c13SNiels Sascha Reedijk \ingroup netservices 308*92357c13SNiels Sascha Reedijk \brief Describe the body for a network request 309*92357c13SNiels Sascha Reedijk 310*92357c13SNiels Sascha Reedijk \since Haiku R1 311*92357c13SNiels Sascha Reedijk*/ 312*92357c13SNiels Sascha Reedijk 313*92357c13SNiels Sascha Reedijk 314*92357c13SNiels Sascha Reedijk/*! 315*92357c13SNiels Sascha Reedijk \var std::unique_ptr<BDataIO> BHttpRequest::Body::input 316*92357c13SNiels Sascha Reedijk \brief The \ref BDataIO object that holds the contents of the body. 317*92357c13SNiels Sascha Reedijk 318*92357c13SNiels Sascha Reedijk \since Haiku R1 319*92357c13SNiels Sascha Reedijk*/ 320*92357c13SNiels Sascha Reedijk 321*92357c13SNiels Sascha Reedijk 322*92357c13SNiels Sascha Reedijk/*! 323*92357c13SNiels Sascha Reedijk \var BString BHttpRequest::Body::mimeType 324*92357c13SNiels Sascha Reedijk \brief The mimetype of the body. 325*92357c13SNiels Sascha Reedijk 326*92357c13SNiels Sascha Reedijk The \c Content-Type header field of the request is set to this value. 327*92357c13SNiels Sascha Reedijk 328*92357c13SNiels Sascha Reedijk \since Haiku R1 329*92357c13SNiels Sascha Reedijk*/ 330*92357c13SNiels Sascha Reedijk 331*92357c13SNiels Sascha Reedijk 332*92357c13SNiels Sascha Reedijk/*! 333*92357c13SNiels Sascha Reedijk \var std::optional<off_t> BHttpRequest::Body::size 334*92357c13SNiels Sascha Reedijk \brief The size of the content, if known. 335*92357c13SNiels Sascha Reedijk 336*92357c13SNiels Sascha Reedijk \since Haiku R1 337*92357c13SNiels Sascha Reedijk*/ 338*92357c13SNiels Sascha Reedijk 339*92357c13SNiels Sascha Reedijk 340*92357c13SNiels Sascha Reedijk/*! 341*92357c13SNiels Sascha Reedijk \var std::optional<off_t> BHttpRequest::Body::startPosition 342*92357c13SNiels Sascha Reedijk \brief If the input is a \ref BPositionIO, this is the current position when the body was set. 343*92357c13SNiels Sascha Reedijk 344*92357c13SNiels Sascha Reedijk This value is used to rewind the input when it needs to be resubmitted, for example in the case 345*92357c13SNiels Sascha Reedijk of a redirection. 346*92357c13SNiels Sascha Reedijk 347*92357c13SNiels Sascha Reedijk \since Haiku R1 348*92357c13SNiels Sascha Reedijk*/ 349*92357c13SNiels Sascha Reedijk 350*92357c13SNiels Sascha Reedijk 351*92357c13SNiels Sascha Reedijk/*! 3526ce6e964SNiels Sascha Reedijk \class BHttpRequest 3536ce6e964SNiels Sascha Reedijk \ingroup netservices 3546ce6e964SNiels Sascha Reedijk \brief Represent a HTTP request. 3556ce6e964SNiels Sascha Reedijk 3566ce6e964SNiels Sascha Reedijk This class can be used to construct HTTP requests that can be executed by the Network Services 3576ce6e964SNiels Sascha Reedijk Kit. A request has two states, either it is is a valid request, or it is an empty request. The 3586ce6e964SNiels Sascha Reedijk criterium is whether or not the request has a URL. 3596ce6e964SNiels Sascha Reedijk This class has all kinds of convenience methods set and retrieve particular options. Most 3606ce6e964SNiels Sascha Reedijk options are wrapped in specialized container classes that do some form of validation. 3616ce6e964SNiels Sascha Reedijk 3626ce6e964SNiels Sascha Reedijk The default options are: 3636ce6e964SNiels Sascha Reedijk <table> 3646ce6e964SNiels Sascha Reedijk <tr><th>Getter</th><th>Setter</th><th>Description</th><th>Default</th></tr> 3656ce6e964SNiels Sascha Reedijk <tr> 3666ce6e964SNiels Sascha Reedijk <td> \ref Url() </td> 3676ce6e964SNiels Sascha Reedijk <td> \ref SetUrl() </td> 3686ce6e964SNiels Sascha Reedijk <td> The URL. This must start with http or https. </td> 3696ce6e964SNiels Sascha Reedijk <td> Defaults to an empty \ref BUrl </td> 3706ce6e964SNiels Sascha Reedijk </tr> 3716ce6e964SNiels Sascha Reedijk <tr> 372f7515342SNiels Sascha Reedijk <td> \ref Fields() </td> 373f7515342SNiels Sascha Reedijk <td> \ref SetFields() </td> 374f7515342SNiels Sascha Reedijk <td> Additional fields set in the request header. </td> 375f7515342SNiels Sascha Reedijk <td> Defaults with no additional fields </td> 376f7515342SNiels Sascha Reedijk </tr> 377f7515342SNiels Sascha Reedijk <tr> 3786ce6e964SNiels Sascha Reedijk <td> \ref Method() </td> 3796ce6e964SNiels Sascha Reedijk <td> \ref SetMethod() </td> 3806ce6e964SNiels Sascha Reedijk <td> The HTTP method for the request </td> 3816ce6e964SNiels Sascha Reedijk <td> Defaults to \ref BHttpMethod::Get </td> 3826ce6e964SNiels Sascha Reedijk </tr> 38313bfff7bSNiels Sascha Reedijk <tr> 3842f3b9b18SNiels Sascha Reedijk <td> \ref MaxRedirections() </td> 3852f3b9b18SNiels Sascha Reedijk <td> \ref SetMaxRedirections() </td> 3862f3b9b18SNiels Sascha Reedijk <td> How many redirections should be followed. Set to 0 to disable. </td> 3872f3b9b18SNiels Sascha Reedijk <td> Defaults to 8 redirections per request </td> 3882f3b9b18SNiels Sascha Reedijk </tr> 3892f3b9b18SNiels Sascha Reedijk <tr> 390*92357c13SNiels Sascha Reedijk <td> \ref RequestBody() </td> 391*92357c13SNiels Sascha Reedijk <td> \ref SetRequestBody() </td> 392*92357c13SNiels Sascha Reedijk <td> Body contents that is sent with the request. </td> 393*92357c13SNiels Sascha Reedijk <td> Defaults to an empty body </td> 394*92357c13SNiels Sascha Reedijk </tr> 395*92357c13SNiels Sascha Reedijk <tr> 3962f3b9b18SNiels Sascha Reedijk <td> \ref StopOnError() </td> 3972f3b9b18SNiels Sascha Reedijk <td> \ref SetStopOnError() </td> 3982f3b9b18SNiels Sascha Reedijk <td> Stop parsing the server response when there is a client or server error. </td> 3992f3b9b18SNiels Sascha Reedijk <td> Defaults to \a false </td> 4002f3b9b18SNiels Sascha Reedijk </tr> 4012f3b9b18SNiels Sascha Reedijk <tr> 4022f3b9b18SNiels Sascha Reedijk <td> \ref Timeout() </td> 4032f3b9b18SNiels Sascha Reedijk <td> \ref SetTimeout() </td> 4042f3b9b18SNiels Sascha Reedijk <td> The timeout determines how long is waited for the server to respond </td> 4052f3b9b18SNiels Sascha Reedijk <td> \c B_INFINITE_TIMEOUT </td> 40613bfff7bSNiels Sascha Reedijk </tr> 4076ce6e964SNiels Sascha Reedijk </table> 4086ce6e964SNiels Sascha Reedijk 4096ce6e964SNiels Sascha Reedijk \since Haiku R1 4106ce6e964SNiels Sascha Reedijk*/ 4116ce6e964SNiels Sascha Reedijk 4126ce6e964SNiels Sascha Reedijk 4136ce6e964SNiels Sascha Reedijk/*! 4146ce6e964SNiels Sascha Reedijk \name Constructors and Destructor 4156ce6e964SNiels Sascha Reedijk*/ 4166ce6e964SNiels Sascha Reedijk 4176ce6e964SNiels Sascha Reedijk 4186ce6e964SNiels Sascha Reedijk//! @{ 4196ce6e964SNiels Sascha Reedijk 4206ce6e964SNiels Sascha Reedijk 4216ce6e964SNiels Sascha Reedijk/*! 4226ce6e964SNiels Sascha Reedijk \fn BHttpRequest::BHttpRequest() 4236ce6e964SNiels Sascha Reedijk \brief Construct an empty HTTP request. 4246ce6e964SNiels Sascha Reedijk 4256ce6e964SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 4266ce6e964SNiels Sascha Reedijk 4276ce6e964SNiels Sascha Reedijk \since Haiku R1 4286ce6e964SNiels Sascha Reedijk*/ 4296ce6e964SNiels Sascha Reedijk 4306ce6e964SNiels Sascha Reedijk 4316ce6e964SNiels Sascha Reedijk/*! 4326ce6e964SNiels Sascha Reedijk \fn BHttpRequest::BHttpRequest(const BUrl &url) 4336ce6e964SNiels Sascha Reedijk \brief Construct a HTTP request for an \a url. 4346ce6e964SNiels Sascha Reedijk 4356ce6e964SNiels Sascha Reedijk \param url A valid URL with the \c http or \c https protocol. 4366ce6e964SNiels Sascha Reedijk 4376ce6e964SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 4386ce6e964SNiels Sascha Reedijk \exception BUnsupportedProtocol This exception is raised when the protocol of the URL cannot be 4396ce6e964SNiels Sascha Reedijk handled. 4406ce6e964SNiels Sascha Reedijk \exception BInvalidUrl This exception is raised when the \a url is invalid. 4416ce6e964SNiels Sascha Reedijk 4426ce6e964SNiels Sascha Reedijk \since Haiku R1 4436ce6e964SNiels Sascha Reedijk*/ 4446ce6e964SNiels Sascha Reedijk 4456ce6e964SNiels Sascha Reedijk 4466ce6e964SNiels Sascha Reedijk/*! 4476ce6e964SNiels Sascha Reedijk \fn BHttpRequest::BHttpRequest(const BHttpRequest &other)=delete 4486ce6e964SNiels Sascha Reedijk \brief Copying is not allowed. 4496ce6e964SNiels Sascha Reedijk 4506ce6e964SNiels Sascha Reedijk \since Haiku R1 4516ce6e964SNiels Sascha Reedijk*/ 4526ce6e964SNiels Sascha Reedijk 4536ce6e964SNiels Sascha Reedijk 4546ce6e964SNiels Sascha Reedijk/*! 4556ce6e964SNiels Sascha Reedijk \fn BHttpRequest::BHttpRequest(BHttpRequest &&other) noexcept 4566ce6e964SNiels Sascha Reedijk \brief Move constructor. 4576ce6e964SNiels Sascha Reedijk 4586ce6e964SNiels Sascha Reedijk After a move, the \a other object is left in an empty state. 4596ce6e964SNiels Sascha Reedijk 4606ce6e964SNiels Sascha Reedijk \param other The request to move data from. 4616ce6e964SNiels Sascha Reedijk 4626ce6e964SNiels Sascha Reedijk \since Haiku R1 4636ce6e964SNiels Sascha Reedijk*/ 4646ce6e964SNiels Sascha Reedijk 4656ce6e964SNiels Sascha Reedijk 4666ce6e964SNiels Sascha Reedijk/*! 4676ce6e964SNiels Sascha Reedijk \fn BPrivate::Network::BHttpRequest::~BHttpRequest() 4686ce6e964SNiels Sascha Reedijk \brief Destructor 4696ce6e964SNiels Sascha Reedijk 4706ce6e964SNiels Sascha Reedijk \since Haiku R1 4716ce6e964SNiels Sascha Reedijk*/ 4726ce6e964SNiels Sascha Reedijk 4736ce6e964SNiels Sascha Reedijk 4746ce6e964SNiels Sascha Reedijk//! @} 4756ce6e964SNiels Sascha Reedijk 4766ce6e964SNiels Sascha Reedijk 4776ce6e964SNiels Sascha Reedijk/*! 4786ce6e964SNiels Sascha Reedijk \name Assignment operators 4796ce6e964SNiels Sascha Reedijk*/ 4806ce6e964SNiels Sascha Reedijk 4816ce6e964SNiels Sascha Reedijk 4826ce6e964SNiels Sascha Reedijk//! @{ 4836ce6e964SNiels Sascha Reedijk 4846ce6e964SNiels Sascha Reedijk 4856ce6e964SNiels Sascha Reedijk/*! 4866ce6e964SNiels Sascha Reedijk \fn BHttpRequest& BHttpRequest::operator=(const BHttpRequest &other)=delete 4876ce6e964SNiels Sascha Reedijk \brief Copy assignment is not allowed. 4886ce6e964SNiels Sascha Reedijk 4896ce6e964SNiels Sascha Reedijk \since Haiku R1 4906ce6e964SNiels Sascha Reedijk*/ 4916ce6e964SNiels Sascha Reedijk 4926ce6e964SNiels Sascha Reedijk 4936ce6e964SNiels Sascha Reedijk/*! 4946ce6e964SNiels Sascha Reedijk \fn BHttpRequest& BHttpRequest::operator=(BHttpRequest &&other) noexcept 4956ce6e964SNiels Sascha Reedijk \brief Move assignment 4966ce6e964SNiels Sascha Reedijk 4976ce6e964SNiels Sascha Reedijk After a move, the \a other object is left in an empty state. 4986ce6e964SNiels Sascha Reedijk 4996ce6e964SNiels Sascha Reedijk \param other The request to move data from. 5006ce6e964SNiels Sascha Reedijk 5016ce6e964SNiels Sascha Reedijk \since Haiku R1 5026ce6e964SNiels Sascha Reedijk*/ 5036ce6e964SNiels Sascha Reedijk 5046ce6e964SNiels Sascha Reedijk 5056ce6e964SNiels Sascha Reedijk//! @} 5066ce6e964SNiels Sascha Reedijk 5076ce6e964SNiels Sascha Reedijk 5086ce6e964SNiels Sascha Reedijk/*! 5096ce6e964SNiels Sascha Reedijk \name Valid or empty 5106ce6e964SNiels Sascha Reedijk*/ 5116ce6e964SNiels Sascha Reedijk 5126ce6e964SNiels Sascha Reedijk 5136ce6e964SNiels Sascha Reedijk//! @{ 5146ce6e964SNiels Sascha Reedijk 5156ce6e964SNiels Sascha Reedijk 5166ce6e964SNiels Sascha Reedijk/*! 5176ce6e964SNiels Sascha Reedijk \fn bool BHttpRequest::IsEmpty() const noexcept 5186ce6e964SNiels Sascha Reedijk \brief Check if the request is valid or empty 5196ce6e964SNiels Sascha Reedijk 5206ce6e964SNiels Sascha Reedijk \retval true The request is empty. 5216ce6e964SNiels Sascha Reedijk \retval false The request is valid. 5226ce6e964SNiels Sascha Reedijk 5236ce6e964SNiels Sascha Reedijk \since Haiku R1 5246ce6e964SNiels Sascha Reedijk*/ 5256ce6e964SNiels Sascha Reedijk 5266ce6e964SNiels Sascha Reedijk 5276ce6e964SNiels Sascha Reedijk//! @} 5286ce6e964SNiels Sascha Reedijk 5296ce6e964SNiels Sascha Reedijk 5306ce6e964SNiels Sascha Reedijk/*! 5316ce6e964SNiels Sascha Reedijk \name Current Options 5326ce6e964SNiels Sascha Reedijk*/ 5336ce6e964SNiels Sascha Reedijk 5346ce6e964SNiels Sascha Reedijk 5356ce6e964SNiels Sascha Reedijk//! @{ 5366ce6e964SNiels Sascha Reedijk 5376ce6e964SNiels Sascha Reedijk 5386ce6e964SNiels Sascha Reedijk/*! 539f9d9d202SNiels Sascha Reedijk \fn const BHttpAuthentication* BHttpRequest::Authentication() const noexcept 540f9d9d202SNiels Sascha Reedijk \brief Get the credentials for the authentication for the request. 541f9d9d202SNiels Sascha Reedijk 542f9d9d202SNiels Sascha Reedijk \return When no credentials are set for this request, the method returns a \c nullptr. 543f9d9d202SNiels Sascha Reedijk Otherwise, it will return a pointer to the current BHttpAuthentication data set for this 544f9d9d202SNiels Sascha Reedijk request. 545f9d9d202SNiels Sascha Reedijk 546f9d9d202SNiels Sascha Reedijk \since Haiku R1 547f9d9d202SNiels Sascha Reedijk*/ 548f9d9d202SNiels Sascha Reedijk 549f9d9d202SNiels Sascha Reedijk 550f9d9d202SNiels Sascha Reedijk/*! 551f7515342SNiels Sascha Reedijk \fn const BHttpFields& BHttpRequest::Fields() const noexcept 552f7515342SNiels Sascha Reedijk \brief Get the additional header fields set for the request. 553f7515342SNiels Sascha Reedijk 554f7515342SNiels Sascha Reedijk The returned header fields may be empty if no additional header fields were set. 555f7515342SNiels Sascha Reedijk 556f7515342SNiels Sascha Reedijk \since Haiku R1 557f7515342SNiels Sascha Reedijk*/ 558f7515342SNiels Sascha Reedijk 559f7515342SNiels Sascha Reedijk 560f7515342SNiels Sascha Reedijk/*! 5616ce6e964SNiels Sascha Reedijk \fn const BHttpMethod& BHttpRequest::Method() const noexcept 5626ce6e964SNiels Sascha Reedijk \brief Get the current method for the request. 5636ce6e964SNiels Sascha Reedijk 5646ce6e964SNiels Sascha Reedijk This will either return the custom value set for this request, or the default as is listed in 5656ce6e964SNiels Sascha Reedijk the overview documentation of this class. 5666ce6e964SNiels Sascha Reedijk 5676ce6e964SNiels Sascha Reedijk \since Haiku R1 5686ce6e964SNiels Sascha Reedijk*/ 5696ce6e964SNiels Sascha Reedijk 5706ce6e964SNiels Sascha Reedijk 5716ce6e964SNiels Sascha Reedijk/*! 5722f3b9b18SNiels Sascha Reedijk \fn uint8 BHttpRequest::MaxRedirections() const noexcept 57313bfff7bSNiels Sascha Reedijk \brief Get the current redirection options for this request. 57413bfff7bSNiels Sascha Reedijk 5752f3b9b18SNiels Sascha Reedijk \see \ref BHttpRequest::SetMaxRedirections() for details on the options. 5762f3b9b18SNiels Sascha Reedijk 5772f3b9b18SNiels Sascha Reedijk \since Haiku R1 5782f3b9b18SNiels Sascha Reedijk*/ 5792f3b9b18SNiels Sascha Reedijk 5802f3b9b18SNiels Sascha Reedijk 5812f3b9b18SNiels Sascha Reedijk/*! 582*92357c13SNiels Sascha Reedijk \fn const BHttpRequest::Body* BHttpRequest::RequestBody() const noexcept 583*92357c13SNiels Sascha Reedijk \brief Get the details of the custom body set for the request. 584*92357c13SNiels Sascha Reedijk 585*92357c13SNiels Sascha Reedijk \return When no body is set for this request, the method returns a \c nullptr. 586*92357c13SNiels Sascha Reedijk Otherwise, it will return a pointer to a struct that describes the current body. 587*92357c13SNiels Sascha Reedijk 588*92357c13SNiels Sascha Reedijk \since Haiku R1 589*92357c13SNiels Sascha Reedijk*/ 590*92357c13SNiels Sascha Reedijk 591*92357c13SNiels Sascha Reedijk 592*92357c13SNiels Sascha Reedijk/*! 5932f3b9b18SNiels Sascha Reedijk \fn bool BHttpRequest::StopOnError() const noexcept 5942f3b9b18SNiels Sascha Reedijk \brief Is the request set to parse the full response on error. 5952f3b9b18SNiels Sascha Reedijk 5962f3b9b18SNiels Sascha Reedijk \retval true When encountering a HTTP status of the client error class (4xx) or server error 5972f3b9b18SNiels Sascha Reedijk class (5xx), then the response will not be parsed. 5982f3b9b18SNiels Sascha Reedijk \retval false The full response will be parsed, even with an error status code. 5992f3b9b18SNiels Sascha Reedijk 6002f3b9b18SNiels Sascha Reedijk \since Haiku R1 6012f3b9b18SNiels Sascha Reedijk*/ 6022f3b9b18SNiels Sascha Reedijk 6032f3b9b18SNiels Sascha Reedijk 6042f3b9b18SNiels Sascha Reedijk/*! 6052f3b9b18SNiels Sascha Reedijk \fn bigtime_t BHttpRequest::Timeout() const noexcept 6062f3b9b18SNiels Sascha Reedijk \brief Get the current timeout for the server to respond. 60713bfff7bSNiels Sascha Reedijk 60813bfff7bSNiels Sascha Reedijk \since Haiku R1 60913bfff7bSNiels Sascha Reedijk*/ 61013bfff7bSNiels Sascha Reedijk 61113bfff7bSNiels Sascha Reedijk 61213bfff7bSNiels Sascha Reedijk/*! 6136ce6e964SNiels Sascha Reedijk \fn const BUrl& BHttpRequest::Url() const noexcept 6146ce6e964SNiels Sascha Reedijk \brief Get the current Url for the request. 6156ce6e964SNiels Sascha Reedijk 6166ce6e964SNiels Sascha Reedijk This will either return the custom value set for this request, or the default as is listed in 6176ce6e964SNiels Sascha Reedijk the overview documentation of this class. 6186ce6e964SNiels Sascha Reedijk 6196ce6e964SNiels Sascha Reedijk \since Haiku R1 6206ce6e964SNiels Sascha Reedijk*/ 6216ce6e964SNiels Sascha Reedijk 6226ce6e964SNiels Sascha Reedijk 6236ce6e964SNiels Sascha Reedijk//! @} 6246ce6e964SNiels Sascha Reedijk 6256ce6e964SNiels Sascha Reedijk 6266ce6e964SNiels Sascha Reedijk/*! 6276ce6e964SNiels Sascha Reedijk \name Setting Options 6286ce6e964SNiels Sascha Reedijk*/ 6296ce6e964SNiels Sascha Reedijk 6306ce6e964SNiels Sascha Reedijk 6316ce6e964SNiels Sascha Reedijk//! @{ 6326ce6e964SNiels Sascha Reedijk 6336ce6e964SNiels Sascha Reedijk 6346ce6e964SNiels Sascha Reedijk/*! 635f9d9d202SNiels Sascha Reedijk \fn void BHttpRequest::SetAuthentication(const BHttpAuthentication &authentication) 636f9d9d202SNiels Sascha Reedijk \brief Set the credentials to enable basic authentication for the request. 637f9d9d202SNiels Sascha Reedijk 638f9d9d202SNiels Sascha Reedijk The Basic authorization line is added to the request upon setting the request details. There is 639f9d9d202SNiels Sascha Reedijk no support for other authentication schemes, like digest authentication. 640f9d9d202SNiels Sascha Reedijk 641f9d9d202SNiels Sascha Reedijk \param authentication The credentials to apply to the request. 642f9d9d202SNiels Sascha Reedijk 643f9d9d202SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 644f9d9d202SNiels Sascha Reedijk 645f9d9d202SNiels Sascha Reedijk \since Haiku R1 646f9d9d202SNiels Sascha Reedijk*/ 647f9d9d202SNiels Sascha Reedijk 648f9d9d202SNiels Sascha Reedijk 649f9d9d202SNiels Sascha Reedijk/*! 650f7515342SNiels Sascha Reedijk \fn void BHttpRequest::SetFields(const BHttpFields &fields) 651f7515342SNiels Sascha Reedijk \brief Set additional header \a fields for this request. 652f7515342SNiels Sascha Reedijk 653f7515342SNiels Sascha Reedijk There are a few reserved fields, which cannot be set as optional fields. These currently are: 654f7515342SNiels Sascha Reedijk * \c Host 655f7515342SNiels Sascha Reedijk * \c Accept-Encoding 656f7515342SNiels Sascha Reedijk * \c Connection 657*92357c13SNiels Sascha Reedijk * \c Content-Type 658*92357c13SNiels Sascha Reedijk * \c Content-Length 659f7515342SNiels Sascha Reedijk 660f7515342SNiels Sascha Reedijk \param fields Additional fields for the header of the request. 661f7515342SNiels Sascha Reedijk 662f7515342SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 663f7515342SNiels Sascha Reedijk \exception BHttpFields::InvalidData This exception is raised when the \a fields contain 664f7515342SNiels Sascha Reedijk reserved fields. 665f7515342SNiels Sascha Reedijk 666f7515342SNiels Sascha Reedijk \since Haiku R1 667f7515342SNiels Sascha Reedijk*/ 668f7515342SNiels Sascha Reedijk 669f7515342SNiels Sascha Reedijk 670f7515342SNiels Sascha Reedijk/*! 6716ce6e964SNiels Sascha Reedijk \fn void BHttpRequest::SetMethod(const BHttpMethod &method) 6726ce6e964SNiels Sascha Reedijk \brief Set the \a method for this request. 6736ce6e964SNiels Sascha Reedijk 6746ce6e964SNiels Sascha Reedijk Note that there currently is no additional validation done on any semantical incompatibilities. 6756ce6e964SNiels Sascha Reedijk This means that it is currently allowed to do a \c GET or \c HEAD request with data, while that 6766ce6e964SNiels Sascha Reedijk is forbidden by the standard. 6776ce6e964SNiels Sascha Reedijk 6786ce6e964SNiels Sascha Reedijk \param method The method to use for the request. 6796ce6e964SNiels Sascha Reedijk 6806ce6e964SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 6816ce6e964SNiels Sascha Reedijk 6826ce6e964SNiels Sascha Reedijk \since Haiku R1 6836ce6e964SNiels Sascha Reedijk*/ 6846ce6e964SNiels Sascha Reedijk 6856ce6e964SNiels Sascha Reedijk 6866ce6e964SNiels Sascha Reedijk/*! 6872f3b9b18SNiels Sascha Reedijk \fn void BHttpRequest::SetMaxRedirections(uint8 maxRedirections) 68813bfff7bSNiels Sascha Reedijk \brief Set the redirection options for this request. 68913bfff7bSNiels Sascha Reedijk 69013bfff7bSNiels Sascha Reedijk The HTTP protocol allows the server to redirect requests if the resources have moved to a new 69113bfff7bSNiels Sascha Reedijk location. For your convenience, you can instruct the network services kit to follow these 6922f3b9b18SNiels Sascha Reedijk redirections. You can set how many redirects should be followed. The maximum value is that of 6932f3b9b18SNiels Sascha Reedijk an unsigned 8 bit int, so maximum is 256 redirects. This prevents the request from staying 6942f3b9b18SNiels Sascha Reedijk stuck in a redirection loop. 69513bfff7bSNiels Sascha Reedijk 6962f3b9b18SNiels Sascha Reedijk If redirects are set to 0, or the maximum number of redirects have been processed, then the 69713bfff7bSNiels Sascha Reedijk response will be set to the actual (last) received redirection response. 69813bfff7bSNiels Sascha Reedijk 6992f3b9b18SNiels Sascha Reedijk \param maxRedirections The number of redirections to follow. Set to 0 to disable. 7002f3b9b18SNiels Sascha Reedijk 7012f3b9b18SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 7022f3b9b18SNiels Sascha Reedijk 7032f3b9b18SNiels Sascha Reedijk \since Haiku R1 7042f3b9b18SNiels Sascha Reedijk*/ 7052f3b9b18SNiels Sascha Reedijk 7062f3b9b18SNiels Sascha Reedijk 7072f3b9b18SNiels Sascha Reedijk/*! 708*92357c13SNiels Sascha Reedijk \fn void BHttpRequest::SetRequestBody(std::unique_ptr<BDataIO> input, BString mimeType, 709*92357c13SNiels Sascha Reedijk std::optional<off_t> size) 710*92357c13SNiels Sascha Reedijk \brief Set a body for this request. 711*92357c13SNiels Sascha Reedijk 712*92357c13SNiels Sascha Reedijk When the requests needs a body, this method can be used to set the contents of that body. 713*92357c13SNiels Sascha Reedijk 714*92357c13SNiels Sascha Reedijk \param input The input is an owned pointer to an input. The lifetime of the input is guaranteed 715*92357c13SNiels Sascha Reedijk up to the point that the request is sent for execution. 716*92357c13SNiels Sascha Reedijk \param mimeType A valid mimetype, with a class and a subtype. For example \c text/plain is a 717*92357c13SNiels Sascha Reedijk valid mime type. 718*92357c13SNiels Sascha Reedijk \param size When the content size is set, the request will have a \c Content-Length header 719*92357c13SNiels Sascha Reedijk field. If the \a input has less data in the buffer, this will cause the request to 720*92357c13SNiels Sascha Reedijk error out. However, if the input has more data, it is only read up to size. If the actual 721*92357c13SNiels Sascha Reedijk size of the data is unknown, this can be made optional. The request body will 722*92357c13SNiels Sascha Reedijk then be sent as a so-called chunked transfer, sending data until the input is at the end. 723*92357c13SNiels Sascha Reedijk 724*92357c13SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 725*92357c13SNiels Sascha Reedijk \exception std::invalid_argument This exception is raised when the \a mimeType is invalid or 726*92357c13SNiels Sascha Reedijk when \a input is a \c nullptr. 727*92357c13SNiels Sascha Reedijk 728*92357c13SNiels Sascha Reedijk \since Haiku R1 729*92357c13SNiels Sascha Reedijk*/ 730*92357c13SNiels Sascha Reedijk 731*92357c13SNiels Sascha Reedijk 732*92357c13SNiels Sascha Reedijk/*! 7332f3b9b18SNiels Sascha Reedijk \fn void BHttpRequest::SetStopOnError(bool stopOnError) 7342f3b9b18SNiels Sascha Reedijk \brief Set whether the entire response will be parsed on a client or server error. 7352f3b9b18SNiels Sascha Reedijk 7362f3b9b18SNiels Sascha Reedijk When the server encounters an error processing a request, it may respond with an error code. 7372f3b9b18SNiels Sascha Reedijk Error responses can be either an error with the request, like the 404 Not Found error, or 7382f3b9b18SNiels Sascha Reedijk errors on the server side, like a 500 Internal Server Error. Error responses may still have 7392f3b9b18SNiels Sascha Reedijk header fields and bodies. 7402f3b9b18SNiels Sascha Reedijk 7412f3b9b18SNiels Sascha Reedijk If your application is not interested in the rest of the response in case a client error or 7422f3b9b18SNiels Sascha Reedijk a server error occurs, you can set this option to stop parsing. This will allow you to use the 7432f3b9b18SNiels Sascha Reedijk \ref BHttpResult object as normal, but the response fields will be empty, and there will be no 7442f3b9b18SNiels Sascha Reedijk body data. 7452f3b9b18SNiels Sascha Reedijk 7462f3b9b18SNiels Sascha Reedijk \param stopOnError Set to \c true to stop parsing the HTTP response when a client error or 7472f3b9b18SNiels Sascha Reedijk server error occurs. 7482f3b9b18SNiels Sascha Reedijk 7492f3b9b18SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 7502f3b9b18SNiels Sascha Reedijk 7512f3b9b18SNiels Sascha Reedijk \since Haiku R1 7522f3b9b18SNiels Sascha Reedijk*/ 7532f3b9b18SNiels Sascha Reedijk 7542f3b9b18SNiels Sascha Reedijk 7552f3b9b18SNiels Sascha Reedijk/*! 7562f3b9b18SNiels Sascha Reedijk \fn void BHttpRequest::SetTimeout(bigtime_t timeout) 7572f3b9b18SNiels Sascha Reedijk \brief Set the maximum time waiting for the server to respond. 7582f3b9b18SNiels Sascha Reedijk 7592f3b9b18SNiels Sascha Reedijk If the request times out, then the response will hold the \ref BNetworkRequestError of the 7602f3b9b18SNiels Sascha Reedijk \c NetworkError type. By default, the request does not time out. 7612f3b9b18SNiels Sascha Reedijk 7622f3b9b18SNiels Sascha Reedijk \param timeout The timeout in milliseconds. 76313bfff7bSNiels Sascha Reedijk 76413bfff7bSNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 76513bfff7bSNiels Sascha Reedijk 76613bfff7bSNiels Sascha Reedijk \since Haiku R1 76713bfff7bSNiels Sascha Reedijk*/ 76813bfff7bSNiels Sascha Reedijk 76913bfff7bSNiels Sascha Reedijk 77013bfff7bSNiels Sascha Reedijk/*! 7716ce6e964SNiels Sascha Reedijk \fn void BHttpRequest::SetUrl(const BUrl &url) 7726ce6e964SNiels Sascha Reedijk \brief Set the \a url for this request. 7736ce6e964SNiels Sascha Reedijk 7746ce6e964SNiels Sascha Reedijk \param url A valid URL with the \c http or \c https protocol. 7756ce6e964SNiels Sascha Reedijk 7766ce6e964SNiels Sascha Reedijk \exception std::bad_alloc This exception may be raised if it is impossible to allocate memory. 7776ce6e964SNiels Sascha Reedijk \exception BUnsupportedProtocol This exception is raised when the protocol of the URL cannot be 7786ce6e964SNiels Sascha Reedijk handled. 7796ce6e964SNiels Sascha Reedijk \exception BInvalidUrl This exception is raised when the \a url is invalid. 7806ce6e964SNiels Sascha Reedijk 7816ce6e964SNiels Sascha Reedijk \since Haiku R1 7826ce6e964SNiels Sascha Reedijk*/ 7836ce6e964SNiels Sascha Reedijk 7846ce6e964SNiels Sascha Reedijk 7856ce6e964SNiels Sascha Reedijk//! @} 7866ce6e964SNiels Sascha Reedijk 7876ce6e964SNiels Sascha Reedijk 788d9a4c607SNiels Sascha Reedijk/*! 789*92357c13SNiels Sascha Reedijk \name Clearing options 790*92357c13SNiels Sascha Reedijk*/ 791*92357c13SNiels Sascha Reedijk 792*92357c13SNiels Sascha Reedijk 793*92357c13SNiels Sascha Reedijk//! @{ 794*92357c13SNiels Sascha Reedijk 795*92357c13SNiels Sascha Reedijk 796*92357c13SNiels Sascha Reedijk/*! 797*92357c13SNiels Sascha Reedijk \fn void BHttpRequest::ClearAuthentication() noexcept 798*92357c13SNiels Sascha Reedijk \brief Clear any authentication details previously set with \ref SetAuthentication(). 799*92357c13SNiels Sascha Reedijk 800*92357c13SNiels Sascha Reedijk If there is no authentication data set, this method does nothing. 801*92357c13SNiels Sascha Reedijk 802*92357c13SNiels Sascha Reedijk \since Haiku R1 803*92357c13SNiels Sascha Reedijk*/ 804*92357c13SNiels Sascha Reedijk 805*92357c13SNiels Sascha Reedijk 806*92357c13SNiels Sascha Reedijk/*! 807*92357c13SNiels Sascha Reedijk \fn std::unique_ptr<BDataIO> BHttpRequest::ClearRequestBody() noexcept 808*92357c13SNiels Sascha Reedijk \brief Clear any request body previously set with \ref SetRequestBody(). 809*92357c13SNiels Sascha Reedijk 810*92357c13SNiels Sascha Reedijk \return Returns the previously set input \ref BDataIO object. If there is no request body set, 811*92357c13SNiels Sascha Reedijk this method returns \c nullptr. 812*92357c13SNiels Sascha Reedijk 813*92357c13SNiels Sascha Reedijk \since Haiku R1 814*92357c13SNiels Sascha Reedijk*/ 815*92357c13SNiels Sascha Reedijk 816*92357c13SNiels Sascha Reedijk 817*92357c13SNiels Sascha Reedijk//! @} 818*92357c13SNiels Sascha Reedijk 819*92357c13SNiels Sascha Reedijk 820*92357c13SNiels Sascha Reedijk/*! 821d9a4c607SNiels Sascha Reedijk \name Serialization 822d9a4c607SNiels Sascha Reedijk*/ 823d9a4c607SNiels Sascha Reedijk 824d9a4c607SNiels Sascha Reedijk 825d9a4c607SNiels Sascha Reedijk//! @{ 826d9a4c607SNiels Sascha Reedijk 827d9a4c607SNiels Sascha Reedijk 828d9a4c607SNiels Sascha Reedijk/*! 829d9a4c607SNiels Sascha Reedijk \fn BString BHttpRequest::HeaderToString() const 830d9a4c607SNiels Sascha Reedijk \brief Serialize the HTTP Header of this request to a string. 831d9a4c607SNiels Sascha Reedijk 832d9a4c607SNiels Sascha Reedijk The HTTP header consists of the request line, and the fields, serialized as text according to 833d9a4c607SNiels Sascha Reedijk the HTTP specification. 834d9a4c607SNiels Sascha Reedijk 835d9a4c607SNiels Sascha Reedijk This method can be used to debug requests. 836d9a4c607SNiels Sascha Reedijk 837d9a4c607SNiels Sascha Reedijk \return A new string that represents the HTTP request. 838d9a4c607SNiels Sascha Reedijk 839d9a4c607SNiels Sascha Reedijk \exception std::bad_alloc In case it is not possible to allocate memory for the output string. 840d9a4c607SNiels Sascha Reedijk 841d9a4c607SNiels Sascha Reedijk \since Haiku R1 842d9a4c607SNiels Sascha Reedijk*/ 843d9a4c607SNiels Sascha Reedijk 844d9a4c607SNiels Sascha Reedijk 845d9a4c607SNiels Sascha Reedijk//! @} 846d9a4c607SNiels Sascha Reedijk 847d9a4c607SNiels Sascha Reedijk 848ec865cb8SNiels Sascha Reedijk} // namespace Network 849ec865cb8SNiels Sascha Reedijk 850ec865cb8SNiels Sascha Reedijk} // namespace BPrivate 851ec865cb8SNiels Sascha Reedijk 852ec865cb8SNiels Sascha Reedijk#endif 853