big merge

This commit is contained in:
Philippe G
2021-12-18 21:04:23 -08:00
parent 955692f8ad
commit 898998efb0
583 changed files with 84472 additions and 1965 deletions

View File

@@ -0,0 +1,72 @@
#ifndef BELL_HTTP_STREAM_H
#define BELL_HTTP_STREAM_H
#include <string>
#include <BellLogger.h>
#include <ByteStream.h>
#include <BellSocket.h>
#include <TCPSocket.h>
#include <platform/TLSSocket.h>
/*
* HTTPStream
*
* A class for reading and writing HTTP streams implementing the ByteStream interface.
*
*/
namespace bell
{
enum class StreamStatus
{
OPENING,
READING_HEADERS,
READING_DATA,
CLOSED
};
class HTTPStream : public ByteStream
{
public:
HTTPStream();
~HTTPStream();
std::unique_ptr<bell::Socket> socket;
bool hasFixedSize = false;
size_t contentLength = -1;
size_t currentPos = -1;
StreamStatus status = StreamStatus::OPENING;
/*
* opens connection to given url and reads header
*
* @param url the http url to connect to
*/
void connectToUrl(std::string url, bool disableSSL = false);
/*
* Reads data from the stream.
*
* @param buf The buffer to read data into.
* @param nbytes The size of the buffer.
* @return The number of bytes read.
* @throws std::runtime_error if the stream is closed.
*/
size_t read(uint8_t *buf, size_t nbytes);
/*
* Skips nbytes bytes in the stream.
*/
size_t skip(size_t nbytes);
size_t position() { return currentPos; }
size_t size() { return contentLength; }
// Closes the connection
void close();
};
}
#endif