NetServices: Add support for an input body in a request and handle this with redirects.
Change-Id: Id2399d49aa673469c8c04ebd13884cdbcb24112d
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#define _B_HTTP_REQUEST_H_
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <variant>
|
||||
|
||||
@@ -82,6 +83,14 @@ struct BHttpAuthentication {
|
||||
|
||||
class BHttpRequest {
|
||||
public:
|
||||
// Aggregate parameter types
|
||||
struct Body {
|
||||
std::unique_ptr<BDataIO> input;
|
||||
BString mimeType;
|
||||
std::optional<off_t> size;
|
||||
std::optional<off_t> startPosition;
|
||||
};
|
||||
|
||||
// Constructors and Destructor
|
||||
BHttpRequest();
|
||||
BHttpRequest(const BUrl& url);
|
||||
@@ -99,6 +108,7 @@ public:
|
||||
const BHttpFields& Fields() const noexcept;
|
||||
uint8 MaxRedirections() const noexcept;
|
||||
const BHttpMethod& Method() const noexcept;
|
||||
const Body* RequestBody() const noexcept;
|
||||
bool StopOnError() const noexcept;
|
||||
bigtime_t Timeout() const noexcept;
|
||||
const BUrl& Url() const noexcept;
|
||||
@@ -108,10 +118,16 @@ public:
|
||||
void SetFields(const BHttpFields& fields);
|
||||
void SetMaxRedirections(uint8 maxRedirections);
|
||||
void SetMethod(const BHttpMethod& method);
|
||||
void SetRequestBody(std::unique_ptr<BDataIO> input,
|
||||
BString mimeType, std::optional<off_t> size);
|
||||
void SetStopOnError(bool stopOnError);
|
||||
void SetTimeout(bigtime_t timeout);
|
||||
void SetUrl(const BUrl& url);
|
||||
|
||||
// Clearing Options
|
||||
void ClearAuthentication() noexcept;
|
||||
std::unique_ptr<BDataIO> ClearRequestBody() noexcept;
|
||||
|
||||
// Serialization
|
||||
ssize_t SerializeHeaderTo(BDataIO* target) const;
|
||||
BString HeaderToString() const;
|
||||
@@ -119,6 +135,9 @@ public:
|
||||
private:
|
||||
friend class BHttpSession;
|
||||
struct Data;
|
||||
|
||||
bool RewindBody() noexcept;
|
||||
|
||||
std::unique_ptr<Data> fData;
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#define _HTTP_STREAM_H_
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class BDataIO;
|
||||
class BMallocIO;
|
||||
@@ -29,7 +30,12 @@ public:
|
||||
bool complete;
|
||||
};
|
||||
|
||||
virtual TransferInfo Transfer(BDataIO*) = 0;
|
||||
virtual TransferInfo Transfer(BDataIO*) = 0;
|
||||
|
||||
protected:
|
||||
ssize_t BufferData(BDataIO* source, size_t maxSize);
|
||||
|
||||
std::vector<std::byte> fBuffer;
|
||||
};
|
||||
|
||||
|
||||
@@ -41,11 +47,11 @@ public:
|
||||
virtual TransferInfo Transfer(BDataIO* target) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<BMallocIO> fHeader;
|
||||
BDataIO* fBody;
|
||||
off_t fTotalSize = 0;
|
||||
off_t fBodyOffset = 0;
|
||||
off_t fCurrentPos = 0;
|
||||
off_t fRemainingHeaderSize = 0;
|
||||
BDataIO* fBody = nullptr;
|
||||
off_t fTotalBodySize = 0;
|
||||
off_t fBufferedBodySize = 0;
|
||||
off_t fTransferredBodySize = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user