NetServices: add the HttpSerializer helper to help serialize requests
Change-Id: Ide1e2d387884ce4cf2d406057960cd0732d61f38
This commit is contained in:
@@ -25,6 +25,8 @@ namespace Network {
|
||||
|
||||
|
||||
class BHttpFields;
|
||||
class HttpBuffer;
|
||||
class HttpSerializer;
|
||||
|
||||
|
||||
class BHttpMethod {
|
||||
@@ -134,9 +136,11 @@ public:
|
||||
|
||||
private:
|
||||
friend class BHttpSession;
|
||||
friend class HttpSerializer;
|
||||
struct Data;
|
||||
|
||||
bool RewindBody() noexcept;
|
||||
void SerializeHeaderTo(HttpBuffer& buffer) const;
|
||||
|
||||
std::unique_ptr<Data> fData;
|
||||
};
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright 2022 Haiku Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
#ifndef _HTTP_STREAM_H_
|
||||
#define _HTTP_STREAM_H_
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
class BDataIO;
|
||||
class BMallocIO;
|
||||
class BString;
|
||||
|
||||
|
||||
namespace BPrivate {
|
||||
|
||||
namespace Network {
|
||||
|
||||
class BHttpFields;
|
||||
class BHttpRequest;
|
||||
class BHttpStatus;
|
||||
class HttpBuffer;
|
||||
|
||||
|
||||
class BAbstractDataStream {
|
||||
public:
|
||||
struct TransferInfo {
|
||||
off_t currentBytesWritten;
|
||||
off_t totalBytesWritten;
|
||||
off_t totalSize;
|
||||
bool complete;
|
||||
};
|
||||
|
||||
virtual TransferInfo Transfer(BDataIO*) = 0;
|
||||
|
||||
protected:
|
||||
ssize_t BufferData(BDataIO* source, size_t maxSize);
|
||||
|
||||
std::vector<std::byte> fBuffer;
|
||||
};
|
||||
|
||||
|
||||
class BHttpRequestStream : public BAbstractDataStream {
|
||||
public:
|
||||
BHttpRequestStream(const BHttpRequest& request);
|
||||
~BHttpRequestStream();
|
||||
|
||||
virtual TransferInfo Transfer(BDataIO* target) override;
|
||||
|
||||
private:
|
||||
off_t fRemainingHeaderSize = 0;
|
||||
BDataIO* fBody = nullptr;
|
||||
off_t fTotalBodySize = 0;
|
||||
off_t fBufferedBodySize = 0;
|
||||
off_t fTransferredBodySize = 0;
|
||||
};
|
||||
|
||||
|
||||
using HttpTransferFunction = std::function<size_t (const std::byte*, size_t)>;
|
||||
|
||||
|
||||
|
||||
|
||||
} // namespace Network
|
||||
|
||||
} // namespace BPrivate
|
||||
|
||||
#endif // _HTTP_STREAM_H_
|
||||
Reference in New Issue
Block a user