Webserv
Loading...
Searching...
No Matches
ResponseBody.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <aio.h>
4#include <string>
5
6namespace http {
7
17public:
19 virtual ~IResponseBody() {}
20
32 virtual ssize_t read(char *buffer, size_t size) = 0;
33
40 virtual size_t size() const = 0;
41
48 virtual bool isDone() const = 0;
49
61 virtual int getEventSourceFd() const;
62
69 virtual bool hasHeaderParsing() const;
70
71private:
74};
75
76class FileBody : public IResponseBody {
77public:
78 explicit FileBody(std::string const &fpath);
79 ~FileBody();
80
81 ssize_t read(char *buffer, size_t size);
82 size_t size() const;
83 bool isDone() const;
84
85private:
86 int fd_;
87 size_t size_;
88 size_t sent_;
89};
90
92public:
93 explicit BodyInMemory(std::string const &);
94
95 ssize_t read(char *buffer, size_t size);
96 size_t size() const;
97 bool isDone() const;
98
99private:
100 std::string body_;
102};
103
105public:
106 BodyFromCgi(int pipeFd, bool hasHeaderParsing);
107 ~BodyFromCgi();
108 ssize_t read(char *buffer, size_t size);
109 size_t size() const;
110 bool isDone() const;
111 int getEventSourceFd() const;
112 bool hasHeaderParsing() const;
113
114private:
116 int fd_;
119};
120
121} // namespace http
~BodyFromCgi()
Definition ResponseBody.cpp:77
bool isDone() const
Checks if the body source has been fully read.
Definition ResponseBody.cpp:98
bool isDone_
Definition ResponseBody.hpp:117
bool hasHeaderParsing() const
Indicates if the data read from this source contains HTTP headers that need to be parsed by the serve...
Definition ResponseBody.cpp:100
ssize_t read(char *buffer, size_t size)
Reads a chunk of the body into the provided buffer. This is a non-blocking operation.
Definition ResponseBody.cpp:81
bool hasHeaderParsing_
Definition ResponseBody.hpp:118
size_t size() const
Returns the total size of the body in bytes, if known.
Definition ResponseBody.cpp:97
int fd_
Definition ResponseBody.hpp:116
BodyFromCgi(int pipeFd, bool hasHeaderParsing)
Definition ResponseBody.cpp:67
int getEventSourceFd() const
Retrieves the file descriptor for event-driven body sources.
Definition ResponseBody.cpp:99
size_t bytesRead_
Definition ResponseBody.hpp:101
std::string body_
Definition ResponseBody.hpp:100
bool isDone() const
Checks if the body source has been fully read.
Definition ResponseBody.cpp:55
size_t size() const
Returns the total size of the body in bytes, if known.
Definition ResponseBody.cpp:54
BodyInMemory(std::string const &)
Definition ResponseBody.cpp:52
ssize_t read(char *buffer, size_t size)
Reads a chunk of the body into the provided buffer. This is a non-blocking operation.
Definition ResponseBody.cpp:57
size_t sent_
Definition ResponseBody.hpp:88
ssize_t read(char *buffer, size_t size)
Reads a chunk of the body into the provided buffer. This is a non-blocking operation.
Definition ResponseBody.cpp:37
size_t size() const
Returns the total size of the body in bytes, if known.
Definition ResponseBody.cpp:45
FileBody(std::string const &fpath)
Definition ResponseBody.cpp:20
int fd_
Definition ResponseBody.hpp:86
~FileBody()
Definition ResponseBody.cpp:32
size_t size_
Definition ResponseBody.hpp:87
bool isDone() const
Checks if the body source has been fully read.
Definition ResponseBody.cpp:46
IResponseBody(IResponseBody const &)
virtual int getEventSourceFd() const
Retrieves the file descriptor for event-driven body sources.
Definition ResponseBody.cpp:16
virtual size_t size() const =0
Returns the total size of the body in bytes, if known.
virtual ssize_t read(char *buffer, size_t size)=0
Reads a chunk of the body into the provided buffer. This is a non-blocking operation.
virtual bool hasHeaderParsing() const
Indicates if the data read from this source contains HTTP headers that need to be parsed by the serve...
Definition ResponseBody.cpp:15
virtual bool isDone() const =0
Checks if the body source has been fully read.
IResponseBody const & operator=(IResponseBody const &)
virtual ~IResponseBody()
Definition ResponseBody.hpp:19
IResponseBody()
Definition ResponseBody.hpp:18
Definition IArgument.hpp:5