1 | // |
2 | // HTTPStreamFactory.h |
3 | // |
4 | // Library: Net |
5 | // Package: HTTP |
6 | // Module: HTTPStreamFactory |
7 | // |
8 | // Definition of the HTTPStreamFactory 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_HTTPStreamFactory_INCLUDED |
18 | #define Net_HTTPStreamFactory_INCLUDED |
19 | |
20 | |
21 | #include "Poco/Net/Net.h" |
22 | #include "Poco/Net/HTTPSession.h" |
23 | #include "Poco/URIStreamFactory.h" |
24 | |
25 | |
26 | namespace Poco { |
27 | namespace Net { |
28 | |
29 | |
30 | class Net_API HTTPStreamFactory: public Poco::URIStreamFactory |
31 | /// An implementation of the URIStreamFactory interface |
32 | /// that handles Hyper-Text Transfer Protocol (http) URIs. |
33 | { |
34 | public: |
35 | HTTPStreamFactory(); |
36 | /// Creates the HTTPStreamFactory. |
37 | |
38 | HTTPStreamFactory(const std::string& proxyHost, Poco::UInt16 proxyPort = HTTPSession::HTTP_PORT); |
39 | /// Creates the HTTPStreamFactory. |
40 | /// |
41 | /// HTTP connections will use the given proxy. |
42 | |
43 | HTTPStreamFactory(const std::string& proxyHost, Poco::UInt16 proxyPort, const std::string& proxyUsername, const std::string& proxyPassword); |
44 | /// Creates the HTTPStreamFactory. |
45 | /// |
46 | /// HTTP connections will use the given proxy and |
47 | /// will be authorized against the proxy using Basic authentication |
48 | /// with the given proxyUsername and proxyPassword. |
49 | |
50 | virtual ~HTTPStreamFactory(); |
51 | /// Destroys the HTTPStreamFactory. |
52 | |
53 | virtual std::istream* open(const Poco::URI& uri); |
54 | /// Creates and opens a HTTP stream for the given URI. |
55 | /// The URI must be a http://... URI. |
56 | /// |
57 | /// Throws a NetException if anything goes wrong. |
58 | /// |
59 | /// Redirect responses are handled and the redirect |
60 | /// location is automatically resolved, as long |
61 | /// as the redirect location is still accessible |
62 | /// via the HTTP protocol. If a redirection to |
63 | /// a non http://... URI is received, a |
64 | /// UnsupportedRedirectException exception is thrown. |
65 | /// The offending URI can then be obtained via the message() |
66 | /// method of UnsupportedRedirectException. |
67 | |
68 | static void registerFactory(); |
69 | /// Registers the HTTPStreamFactory with the |
70 | /// default URIStreamOpener instance. |
71 | |
72 | static void unregisterFactory(); |
73 | /// Unregisters the HTTPStreamFactory with the |
74 | /// default URIStreamOpener instance. |
75 | |
76 | private: |
77 | enum |
78 | { |
79 | MAX_REDIRECTS = 10 |
80 | }; |
81 | |
82 | std::string _proxyHost; |
83 | Poco::UInt16 _proxyPort; |
84 | std::string _proxyUsername; |
85 | std::string _proxyPassword; |
86 | }; |
87 | |
88 | |
89 | } } // namespace Poco::Net |
90 | |
91 | |
92 | #endif // Net_HTTPStreamFactory_INCLUDED |
93 | |