libfilezilla 0.59.0
A cross-platform C++ library for asynchronous and networked applications
Loading...
Searching...
No Matches
client_response.hpp
Go to the documentation of this file.
1#ifndef LIBFILEZILLA_HTTP_CLIENT_RESPONSE_HEADER
2#define LIBFILEZILLA_HTTP_CLIENT_RESPONSE_HEADER
3
7
8#include "headers.hpp"
9#include "../aio/writer.hpp"
10#include "../buffer.hpp"
11
12namespace fz::http::client {
13
15typedef std::shared_ptr<request_response_interface> shared_request_response;
16
21class FZ_PUBLIC_SYMBOL response : public with_headers
22{
23public:
24 unsigned int code_{};
25 std::string reason_;
26
27 enum flags : unsigned {
28 flag_got_code = 0x01,
29 flag_got_header = 0x02,
30 flag_got_body = 0x04,
31 flag_no_body = 0x08, // e.g. on HEAD requests, or 204/304 responses
32 };
33 unsigned int flags_{};
34
35 bool got_code() const { return flags_ & flag_got_code; }
36 bool got_header() const { return flags_ & flag_got_header; }
37 bool got_body() const { return (flags_ & (flag_got_body | flag_no_body)) == flag_got_body; }
38 bool no_body() const { return flags_ & flag_no_body; }
39
51 std::function<continuation(std::shared_ptr<request_response_interface> const&)> on_header_;
52
54 std::unique_ptr<fz::writer_base> writer_;
55
58
60 size_t max_body_size_{16 * 1024 * 1024};
61
62 bool success() const {
63 return code_ >= 200 && code_ < 300;
64 }
65
66 bool is_redirect() const {
67 return code_ >= 300 && code_ < 400 && code_ != 304 && code_ != 305 && code_ != 306;
68 }
69
71 bool code_prohobits_body() const {
72 return (code_ >= 100 && code_ < 200) || code_ == 304 || code_ == 204;
73 }
74
75 virtual bool reset();
76};
77}
78
79#endif
Declares fz::buffer.
Definition buffer.hpp:360
Used for type erasure, so the internals don't need to know the full request/response.
Definition client.hpp:24
A single HTTP response received by the client.
Definition client_response.hpp:22
size_t max_body_size_
Only if body_ is used. Has no effect if writers are used.
Definition client_response.hpp:60
fz::buffer body_
Holds error body and success body if there is no writer.
Definition client_response.hpp:57
std::unique_ptr< fz::writer_base > writer_
Writer isn't used if !success(), failure responses always go into body_.
Definition client_response.hpp:54
std::function< continuation(std::shared_ptr< request_response_interface > const &)> on_header_
Called once the complete header has been received.
Definition client_response.hpp:51
bool code_prohobits_body() const
Some HTTP responses cannot possibly have a body.
Definition client_response.hpp:71
Definition headers.hpp:30
Declares fz::with_headers as base for HTTP requests/responses.
Classes for writing data asynchronously into files.