frnetlib/include/frnetlib/HttpResponse.h
Fred Nicolson c8e03f2df8 Added more tests. Tweaks.
Receiving an http request/response will now return errors like HttpHeaderTooBig, instead of the type being set to that.

Added fr::Socket::status_to_string for converting status values into English strings.
2017-09-25 16:19:47 +01:00

58 lines
1.5 KiB
C++

//
// Created by fred on 10/12/16.
//
#ifndef FRNETLIB_HTTPRESPONSE_H
#define FRNETLIB_HTTPRESPONSE_H
#include <string>
#include <vector>
#include <unordered_map>
#include "Http.h"
namespace fr
{
class HttpResponse : public Http
{
public:
//Constructors
HttpResponse()=default;
HttpResponse(HttpResponse&&)=default;
HttpResponse(const HttpResponse&)= default;
HttpResponse &operator=(const HttpResponse &)=default;
HttpResponse &operator=(HttpResponse &&)=default;
virtual ~HttpResponse() = default;
/*!
* Parse a raw request or response from a string
* into the object.
*
* @param data The request/response to parse
* @param datasz The length of data in bytes
* @return NotEnoughData if parse needs to be called again. Success on success, other on error.
*/
fr::Socket::Status parse(const char *data, size_t datasz) override;
/*!
* Constructs a HttpResponse, ready to send.
*
* @return The constructed HTTP response.
*/
std::string construct(const std::string &host) const override;
private:
/*!
* Parses the request header.
*
* @param header_end_pos The position in 'body' of the end of the header
*/
bool parse_header(size_t header_end_pos);
//State
bool header_ended{false};
size_t content_length{0};
};
}
#endif //FRNETLIB_HTTPRESPONSE_H