* 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 <optional>
#include <String.h>
class BDataIO;
namespace BPrivate {
namespace Network {
class BHttpFields;
struct HttpResultPrivate;
struct BHttpBody {
std::optional<BString> text;
};
enum class BHttpStatusClass : int16 {
Invalid = 000,
Informational = 100,
Success = 200,
Redirection = 300,
ClientError = 400,
ServerError = 500
};
enum class BHttpStatusCode : int16 {
Unknown = 0,
Continue = 100,
SwitchingProtocols,
Ok = 200,
Created,
Accepted,
NonAuthoritativeInformation,
NoContent,
ResetContent,
PartialContent,
MultipleChoice = 300,
MovedPermanently,
Found,
SeeOther,
NotModified,
UseProxy,
TemporaryRedirect = 307,
PermanentRedirect,
BadRequest = 400,
Unauthorized,
PaymentRequired,
Forbidden,
NotFound,
MethodNotAllowed,
NotAcceptable,
ProxyAuthenticationRequired,
RequestTimeout,
Conflict,
Gone,
LengthRequired,
PreconditionFailed,
RequestEntityTooLarge,
RequestUriTooLarge,
UnsupportedMediaType,
RequestedRangeNotSatisfiable,
ExpectationFailed,
InternalServerError = 500,
NotImplemented,
BadGateway,
ServiceUnavailable,
GatewayTimeout,
};
struct BHttpStatus {
int16 code = 0;
BString text;
BHttpStatusClass StatusClass() const noexcept;
BHttpStatusCode StatusCode() const noexcept;
};
class BHttpResult
{
public:
BHttpResult(const BHttpResult& other) = delete;
BHttpResult(BHttpResult&& other) noexcept;
~BHttpResult();
BHttpResult& operator=(const BHttpResult& other) = delete;
BHttpResult& operator=(BHttpResult&& other) noexcept;
const BHttpStatus& Status() const;
const BHttpFields& Fields() const;
BHttpBody& Body() const;
bool HasStatus() const;
bool HasFields() const;
bool HasBody() const;
bool IsCompleted() const;
int32 Identity() const;
private:
friend class BHttpSession;
BHttpResult(std::shared_ptr<HttpResultPrivate> data);
std::shared_ptr<HttpResultPrivate> fData;
};
}
}
#endif