Webserv
Loading...
Searching...
No Matches
http::FileBody Class Reference

#include <ResponseBody.hpp>

Inheritance diagram for http::FileBody:
http::IResponseBody

Public Member Functions

 FileBody (std::string const &fpath)
 ~FileBody ()
ssize_t read (char *buffer, size_t size)
 Reads a chunk of the body into the provided buffer. This is a non-blocking operation.
size_t size () const
 Returns the total size of the body in bytes, if known.
bool isDone () const
 Checks if the body source has been fully read.
Public Member Functions inherited from http::IResponseBody
 IResponseBody ()
virtual ~IResponseBody ()
virtual int getEventSourceFd () const
 Retrieves the file descriptor for event-driven body sources.
virtual bool hasHeaderParsing () const
 Indicates if the data read from this source contains HTTP headers that need to be parsed by the server (e.g., CGI output).

Private Attributes

int fd_
size_t size_
size_t sent_

Constructor & Destructor Documentation

◆ FileBody()

http::FileBody::FileBody ( std::string const & fpath)
explicit

◆ ~FileBody()

http::FileBody::~FileBody ( )

Member Function Documentation

◆ isDone()

bool http::FileBody::isDone ( ) const
virtual

Checks if the body source has been fully read.

Returns
true if the source is depleted (EOF has been reached), false otherwise.

Implements http::IResponseBody.

◆ read()

ssize_t http::FileBody::read ( char * buffer,
size_t size )
virtual

Reads a chunk of the body into the provided buffer. This is a non-blocking operation.

Parameters
bufferAn output buffer to write data into.
sizeThe maximum size of the buffer.
Returns
The number of bytes read ( > 0).
0 on End-of-File (EOF).
-1 on error. errno may be set (e.g., to EAGAIN/EWOULDBLOCK if the source is not ready).

Implements http::IResponseBody.

◆ size()

size_t http::FileBody::size ( ) const
virtual

Returns the total size of the body in bytes, if known.

Returns
The total content length. Returns 0 or (size_t)-1 if the size is unknown (e.g., for a streaming CGI response).

Implements http::IResponseBody.

Member Data Documentation

◆ fd_

int http::FileBody::fd_
private

◆ sent_

size_t http::FileBody::sent_
private

◆ size_

size_t http::FileBody::size_
private

The documentation for this class was generated from the following files: