13bfff7be3
The user of the API can set whether redirects should be followed, and if so, how many. This is part of the BHttpRequest API. The BHttpSession then follows those instructions, and executes the maximum number of redirects the user would like to follow. As part of this commit, the BHttpStatusClass and BHttpStatusCodes helper enums have been added, to give a friendlier access to HTTP status codes and status classes. Change-Id: Ic8c9e3fda158e2cce549c8f1d360951f7ac83311
145 lines
2.5 KiB
C++
145 lines
2.5 KiB
C++
/*
|
|
* Copyright 2022 Haiku Inc. All rights reserved.
|
|
* Distributed under the terms of the MIT License.
|
|
*/
|
|
|
|
#ifndef _B_HTTP_RESULT_H_
|
|
#define _B_HTTP_RESULT_H_
|
|
|
|
#include <memory>
|
|
|
|
#include <String.h>
|
|
|
|
class BDataIO;
|
|
|
|
|
|
namespace BPrivate {
|
|
|
|
namespace Network {
|
|
|
|
class BHttpFields;
|
|
struct HttpResultPrivate;
|
|
|
|
|
|
struct BHttpBody
|
|
{
|
|
std::unique_ptr<BDataIO> target = nullptr;
|
|
BString text;
|
|
};
|
|
|
|
|
|
enum class BHttpStatusClass : int16 {
|
|
Invalid = 000,
|
|
Informational = 100,
|
|
Success = 200,
|
|
Redirection = 300,
|
|
ClientError = 400,
|
|
ServerError = 500
|
|
};
|
|
|
|
|
|
enum class BHttpStatusCode : int16 {
|
|
Unknown = 0,
|
|
|
|
// Informational status codes
|
|
Continue = 100,
|
|
SwitchingProtocols,
|
|
|
|
// Success status codes
|
|
Ok = 200,
|
|
Created,
|
|
Accepted,
|
|
NonAuthoritativeInformation,
|
|
NoContent,
|
|
ResetContent,
|
|
PartialContent,
|
|
|
|
// Redirection status codes
|
|
MultipleChoice = 300,
|
|
MovedPermanently,
|
|
Found,
|
|
SeeOther,
|
|
NotModified,
|
|
UseProxy,
|
|
TemporaryRedirect = 307,
|
|
PermanentRedirect,
|
|
|
|
// Client error status codes
|
|
BadRequest = 400,
|
|
Unauthorized,
|
|
PaymentRequired,
|
|
Forbidden,
|
|
NotFound,
|
|
MethodNotAllowed,
|
|
NotAcceptable,
|
|
ProxyAuthenticationRequired,
|
|
RequestTimeout,
|
|
Conflict,
|
|
Gone,
|
|
LengthRequired,
|
|
PreconditionFailed,
|
|
RequestEntityTooLarge,
|
|
RequestUriTooLarge,
|
|
UnsupportedMediaType,
|
|
RequestedRangeNotSatisfiable,
|
|
ExpectationFailed,
|
|
|
|
// Server error status codes
|
|
InternalServerError = 500,
|
|
NotImplemented,
|
|
BadGateway,
|
|
ServiceUnavailable,
|
|
GatewayTimeout,
|
|
};
|
|
|
|
|
|
struct BHttpStatus
|
|
{
|
|
int16 code = 0;
|
|
BString text;
|
|
|
|
// Helpers
|
|
BHttpStatusClass StatusClass() const noexcept;
|
|
BHttpStatusCode StatusCode() const noexcept;
|
|
};
|
|
|
|
|
|
class BHttpResult
|
|
{
|
|
public:
|
|
// Constructors and destructor
|
|
BHttpResult(const BHttpResult& other) = delete;
|
|
BHttpResult(BHttpResult&& other) noexcept;
|
|
~BHttpResult();
|
|
|
|
// Assignment operators
|
|
BHttpResult& operator=(const BHttpResult& other) = delete;
|
|
BHttpResult& operator=(BHttpResult&& other) noexcept;
|
|
|
|
// Blocking Access Functions
|
|
const BHttpStatus& Status() const;
|
|
const BHttpFields& Fields() const;
|
|
BHttpBody& Body() const;
|
|
|
|
// Check if data is available yet
|
|
bool HasStatus() const;
|
|
bool HasFields() const;
|
|
bool HasBody() const;
|
|
bool IsCompleted() const;
|
|
|
|
// Identity
|
|
int32 Identity() const;
|
|
|
|
private:
|
|
friend class BHttpSession;
|
|
BHttpResult(std::shared_ptr<HttpResultPrivate> data);
|
|
std::shared_ptr<HttpResultPrivate> fData;
|
|
};
|
|
|
|
|
|
} // namespace Network
|
|
|
|
} // namespace BPrivate
|
|
|
|
#endif // _B_HTTP_RESPONSE_H_
|