Reply.h
1/*
2 * Copyright (C) 2009 by Marc Boris Duerner, Tommi Maekitalo
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * As a special exception, you may use this file as part of a free
10 * software library without restriction. Specifically, if other files
11 * instantiate templates or use macros or inline functions from this
12 * file, or you compile this file and link it with other files to
13 * produce an executable, this file does not by itself cause the
14 * resulting executable to be covered by the GNU General Public
15 * License. This exception does not however invalidate any other
16 * reasons why the executable file might be covered by the GNU Library
17 * General Public License.
18 *
19 * This library is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
27 */
28
29#ifndef Pt_Http_Reply_h
30#define Pt_Http_Reply_h
31
32#include <Pt/Http/Api.h>
33#include <Pt/Http/Message.h>
34#include <Pt/Signal.h>
35#include <string>
36
37namespace Pt {
38
39namespace Http {
40
63class PT_HTTP_API Reply : public Message
64{
65 friend class Connection;
66
67 public:
80
81 public:
84 explicit Reply(Http::Connection& conn)
85 : Message(conn)
86 , _statusCode(200)
87 , _statusText("OK")
88 { }
89
92 void setStatus(unsigned code, const std::string& txt)
93 {
94 _statusCode = code;
95 _statusText = txt;
96 }
97
100 void setStatus(unsigned code, const char* txt)
101 {
102 _statusCode = code;
103 _statusText = txt;
104 }
105
107 unsigned statusCode() const
108 { return _statusCode; }
109
111 const std::string& statusText() const
112 { return _statusText; }
113
115 void receive();
116
118 void beginReceive();
119
121 MessageProgress endReceive();
122
127 void beginSend(bool finish = true);
128
130 MessageProgress endSend();
131
133 Signal<Reply&>& inputReceived()
134 { return _inputReceived; }
135
137 Signal<Reply&>& outputSent()
138 { return _outputSent; }
139
142 void clear();
143
144 protected:
146 void onInput()
147 { _inputReceived.send(*this); }
148
150 void onOutput()
151 { _outputSent.send(*this); }
152
153 private:
154 unsigned _statusCode;
155 std::string _statusText;
156 Signal<Reply&> _inputReceived;
157 Signal<Reply&> _outputSent;
158};
159
160} // namespace Http
161
162} // namespace Pt
163
164#endif // Pt_Http_Reply_h
Progress of an asynchronous HTTP send or receive.
Definition Message.h:337
Message(Http::Connection &conn)
Constructs with connection to use.
Reply(Http::Connection &conn)
Construct with connection.
Definition Reply.h:84
void setStatus(unsigned code, const char *txt)
Sets the HTTP status.
Definition Reply.h:100
const std::string & statusText() const
Returns the HTTP status text.
Definition Reply.h:111
unsigned statusCode() const
Returns the HTTP status code.
Definition Reply.h:107
void clear()
Clears all content.
void beginSend(bool finish=true)
Begins sending the reply.
StatusCode
HTTP reply status code.
Definition Reply.h:71
@ MultipleChoices
Multiple choices for request.
Definition Reply.h:74
@ OK
OK.
Definition Reply.h:73
@ Unauthorized
Unauthorized access.
Definition Reply.h:76
@ Continue
Continue.
Definition Reply.h:72
@ BadRequest
Bad request received.
Definition Reply.h:75
@ RequestEntityTooLarge
Request entity too large
Definition Reply.h:77
@ InternalServerError
Internal server error occured.
Definition Reply.h:78
void setStatus(unsigned code, const std::string &txt)
Sets the HTTP status.
Definition Reply.h:92
Multicast Signal to call multiple slots.
Definition Signal.h:190
HTTP clients and servers.
Core module.
Definition Allocator.h:33