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 
37 namespace Pt {
38 
39 namespace Http {
40 
43 class PT_HTTP_API Request : public Message
44 {
45  friend class Connection;
46 
47  public:
50  explicit Request(Http::Connection& conn)
51  : Message(conn)
52  , _url()
53  , _method("GET")
54  { }
55 
58  Request( Http::Connection& conn, const std::string& url)
59  : Message(conn)
60  , _url(url)
61  , _method("GET")
62  { }
63 
66  Request( Http::Connection& conn, const char* url)
67  : Message(conn)
68  , _url(url)
69  , _method("GET")
70  { }
71 
73  const std::string& url() const
74  { return _url; }
75 
78  void setUrl(const std::string& u)
79  { _url = u; }
80 
83  void setUrl(const char* u)
84  { _url = u; }
85 
87  const std::string& method() const
88  { return _method; }
89 
92  void setMethod(const std::string& m)
93  { _method = m; }
94 
97  void setMethod(const char* m)
98  { _method = m; }
99 
101  const std::string& qparams() const
102  { return _qparams; }
103 
106  void setQParams(const std::string& p)
107  { _qparams = p; }
108 
111  void setQParams(const char* p)
112  { _qparams = p; }
113 
115  void beginReceive();
116 
118  MessageProgress endReceive();
119 
121  void send(bool finish = true);
122 
124  void beginSend(bool finish = true);
125 
127  MessageProgress endSend();
128 
130  Signal<Request&>& inputReceived()
131  { return _inputReceived; }
132 
134  Signal<Request&>& outputSent()
135  { return _outputSent; }
136 
139  void clear();
140 
141  protected:
143  void onInput()
144  { _inputReceived.send(*this); }
145 
147  void onOutput()
148  { _outputSent.send(*this); }
149 
150  private:
151  std::string _url;
152  std::string _method;
153  std::string _qparams;
154  Signal<Request&> _inputReceived;
155  Signal<Request&> _outputSent;
156 };
157 
158 } // namespace Http
159 
160 } // namespace Pt
161 
162 #endif // Pt_Http_Request_h
HTTP message progress.
Definition: Message.h:277
HTTP request message.
Definition: Request.h:43
const std::string & qparams() const
Returns the HTTP request URL query.
Definition: Request.h:101
HTTP message with header and body.
Definition: Message.h:381
void setQParams(const char *p)
Sets the URL query string.
Definition: Request.h:111
void setMethod(const char *m)
Sets the request method.
Definition: Request.h:97
Represents a connection between a Signal/Delegate and a slot.
Definition: Connection.h:90
Multicast Signal to call multiple slots.
Definition: Signal.h:109
Request(Http::Connection &conn, const std::string &url)
Construct with connection and URL.
Definition: Request.h:58
void setMethod(const std::string &m)
Sets the request method.
Definition: Request.h:92
void setUrl(const char *u)
Sets the request URL.
Definition: Request.h:83
Request(Http::Connection &conn, const char *url)
Construct with connection and URL.
Definition: Request.h:66
const std::string & url() const
Returns the HTTP request URL.
Definition: Request.h:73
const std::string & method() const
Returns the HTTP request method.
Definition: Request.h:87
Request(Http::Connection &conn)
Construct with connection.
Definition: Request.h:50
void setQParams(const std::string &p)
Sets the URL query string.
Definition: Request.h:106
void setUrl(const std::string &u)
Sets the request URL.
Definition: Request.h:78