1 | // |
---|---|
2 | // HTTPServerRequestImpl.h |
3 | // |
4 | // Library: Net |
5 | // Package: HTTPServer |
6 | // Module: HTTPServerRequestImpl |
7 | // |
8 | // Definition of the HTTPServerRequestImpl class. |
9 | // |
10 | // Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH. |
11 | // and Contributors. |
12 | // |
13 | // SPDX-License-Identifier: BSL-1.0 |
14 | // |
15 | |
16 | |
17 | #ifndef Net_HTTPServerRequestImpl_INCLUDED |
18 | #define Net_HTTPServerRequestImpl_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Net/Net.h" |
22 | #include "Poco/Net/HTTPServerRequest.h" |
23 | #include "Poco/Net/HTTPServerResponseImpl.h" |
24 | #include "Poco/Net/SocketAddress.h" |
25 | #include "Poco/AutoPtr.h" |
26 | #include <istream> |
27 | |
28 | |
29 | namespace Poco { |
30 | namespace Net { |
31 | |
32 | |
33 | class HTTPServerSession; |
34 | class HTTPServerParams; |
35 | class StreamSocket; |
36 | |
37 | |
38 | class Net_API HTTPServerRequestImpl: public HTTPServerRequest |
39 | /// This subclass of HTTPServerRequest is used for |
40 | /// representing server-side HTTP requests. |
41 | /// |
42 | /// A HTTPServerRequest is passed to the |
43 | /// handleRequest() method of HTTPRequestHandler. |
44 | { |
45 | public: |
46 | HTTPServerRequestImpl(HTTPServerResponseImpl& response, HTTPServerSession& session, HTTPServerParams* pParams); |
47 | /// Creates the HTTPServerRequestImpl, using the |
48 | /// given HTTPServerSession. |
49 | |
50 | ~HTTPServerRequestImpl(); |
51 | /// Destroys the HTTPServerRequestImpl. |
52 | |
53 | std::istream& stream(); |
54 | /// Returns the input stream for reading |
55 | /// the request body. |
56 | /// |
57 | /// The stream is valid until the HTTPServerRequestImpl |
58 | /// object is destroyed. |
59 | |
60 | const SocketAddress& clientAddress() const; |
61 | /// Returns the client's address. |
62 | |
63 | const SocketAddress& serverAddress() const; |
64 | /// Returns the server's address. |
65 | |
66 | const HTTPServerParams& serverParams() const; |
67 | /// Returns a reference to the server parameters. |
68 | |
69 | HTTPServerResponse& response() const; |
70 | /// Returns a reference to the associated response. |
71 | |
72 | bool secure() const; |
73 | /// Returns true if the request is using a secure |
74 | /// connection. Returns false if no secure connection |
75 | /// is used, or if it is not known whether a secure |
76 | /// connection is used. |
77 | |
78 | StreamSocket& socket(); |
79 | /// Returns a reference to the underlying socket. |
80 | |
81 | StreamSocket detachSocket(); |
82 | /// Returns the underlying socket after detaching |
83 | /// it from the server session. |
84 | |
85 | HTTPServerSession& session(); |
86 | /// Returns the underlying HTTPServerSession. |
87 | |
88 | private: |
89 | HTTPServerResponseImpl& _response; |
90 | HTTPServerSession& _session; |
91 | std::istream* _pStream; |
92 | Poco::AutoPtr<HTTPServerParams> _pParams; |
93 | SocketAddress _clientAddress; |
94 | SocketAddress _serverAddress; |
95 | }; |
96 | |
97 | |
98 | // |
99 | // inlines |
100 | // |
101 | inline std::istream& HTTPServerRequestImpl::stream() |
102 | { |
103 | poco_check_ptr (_pStream); |
104 | |
105 | return *_pStream; |
106 | } |
107 | |
108 | |
109 | inline const SocketAddress& HTTPServerRequestImpl::clientAddress() const |
110 | { |
111 | return _clientAddress; |
112 | } |
113 | |
114 | |
115 | inline const SocketAddress& HTTPServerRequestImpl::serverAddress() const |
116 | { |
117 | return _serverAddress; |
118 | } |
119 | |
120 | |
121 | inline const HTTPServerParams& HTTPServerRequestImpl::serverParams() const |
122 | { |
123 | return *_pParams; |
124 | } |
125 | |
126 | |
127 | inline HTTPServerResponse& HTTPServerRequestImpl::response() const |
128 | { |
129 | return _response; |
130 | } |
131 | |
132 | |
133 | inline HTTPServerSession& HTTPServerRequestImpl::session() |
134 | { |
135 | return _session; |
136 | } |
137 | |
138 | |
139 | } } // namespace Poco::Net |
140 | |
141 | |
142 | #endif // Net_HTTPServerRequestImpl_INCLUDED |
143 |