Request.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_Request_h
30#define Pt_Http_Request_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
64class PT_HTTP_API Request : public Message
65{
66 friend class Connection;
67
68 public:
71 explicit Request(Http::Connection& conn)
72 : Message(conn)
73 , _url()
74 , _method("GET")
75 { }
76
79 Request( Http::Connection& conn, const std::string& url)
80 : Message(conn)
81 , _url(url)
82 , _method("GET")
83 { }
84
87 Request( Http::Connection& conn, const char* url)
88 : Message(conn)
89 , _url(url)
90 , _method("GET")
91 { }
92
94 const std::string& url() const
95 { return _url; }
96
99 void setUrl(const std::string& u)
100 { _url = u; }
101
104 void setUrl(const char* u)
105 { _url = u; }
106
108 const std::string& method() const
109 { return _method; }
110
113 void setMethod(const std::string& m)
114 { _method = m; }
115
118 void setMethod(const char* m)
119 { _method = m; }
120
122 const std::string& qparams() const
123 { return _qparams; }
124
127 void setQParams(const std::string& p)
128 { _qparams = p; }
129
132 void setQParams(const char* p)
133 { _qparams = p; }
134
136 void beginReceive();
137
139 MessageProgress endReceive();
140
142 void send(bool finish = true);
143
145 void beginSend(bool finish = true);
146
148 MessageProgress endSend();
149
151 Signal<Request&>& inputReceived()
152 { return _inputReceived; }
153
155 Signal<Request&>& outputSent()
156 { return _outputSent; }
157
160 void clear();
161
162 protected:
164 void onInput()
165 { _inputReceived.send(*this); }
166
168 void onOutput()
169 { _outputSent.send(*this); }
170
171 private:
172 std::string _url;
173 std::string _method;
174 std::string _qparams;
175 Signal<Request&> _inputReceived;
176 Signal<Request&> _outputSent;
177};
178
179} // namespace Http
180
181} // namespace Pt
182
183#endif // Pt_Http_Request_h
Progress of an asynchronous HTTP send or receive.
Definition Message.h:337
Message(Http::Connection &conn)
Constructs with connection to use.
void setUrl(const char *u)
Sets the request URL.
Definition Request.h:104
void setMethod(const char *m)
Sets the request method.
Definition Request.h:118
Request(Http::Connection &conn, const std::string &url)
Construct with connection and URL.
Definition Request.h:79
void setQParams(const std::string &p)
Sets the URL query string.
Definition Request.h:127
Request(Http::Connection &conn)
Construct with connection.
Definition Request.h:71
const std::string & qparams() const
Returns the HTTP request URL query.
Definition Request.h:122
const std::string & method() const
Returns the HTTP request method.
Definition Request.h:108
void setUrl(const std::string &u)
Sets the request URL.
Definition Request.h:99
void setQParams(const char *p)
Sets the URL query string.
Definition Request.h:132
void setMethod(const std::string &m)
Sets the request method.
Definition Request.h:113
Request(Http::Connection &conn, const char *url)
Construct with connection and URL.
Definition Request.h:87
void clear()
Clears all content.
const std::string & url() const
Returns the HTTP request URL.
Definition Request.h:94
Multicast Signal to call multiple slots.
Definition Signal.h:190
HTTP clients and servers.
Core module.
Definition Allocator.h:33