Skip to content

Commit dbb4338

Browse files
committed
fix(Net): correct indentation and formatting in HTTPS proxy support
Replace space indentation with tabs to match project conventions. Fix copy-paste error in setProxyProtocol() error message. Update copyright year in ProxyConfig.h.
1 parent 53b0c7b commit dbb4338

File tree

4 files changed

+118
-111
lines changed

4 files changed

+118
-111
lines changed

Net/include/Poco/Net/HTTPClientSession.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Net_API HTTPClientSession: public HTTPSession
145145
/// Sets the port number of the proxy server.
146146

147147
void setProxyProtocol(const std::string& protocol);
148-
/// Sets the proxy protocol (http or https).
148+
/// Sets the proxy protocol (http or https).
149149

150150
void setProxyTunnel(bool tunnel);
151151
/// If 'true' proxy will be used as tunnel.
@@ -157,7 +157,7 @@ class Net_API HTTPClientSession: public HTTPSession
157157
/// Returns the proxy port number.
158158

159159
const std::string& getProxyProtocol() const;
160-
/// Returns the proxy protocol.
160+
/// Returns the proxy protocol.
161161

162162
bool isProxyTunnel() const;
163163
/// Returns 'true' if proxy is configured as tunnel.
@@ -345,8 +345,9 @@ class Net_API HTTPClientSession: public HTTPSession
345345
/// Calls proxyConnect() and attaches the resulting StreamSocket
346346
/// to the HTTPClientSession.
347347

348-
HTTPSessionFactory _proxySessionFactory;
349-
/// Factory to create HTTPClientSession to proxy.
348+
HTTPSessionFactory _proxySessionFactory;
349+
/// Factory to create HTTPClientSession to proxy.
350+
350351
private:
351352
using OStreamPtr = Poco::SharedPtr<std::ostream>;
352353
using IStreamPtr = Poco::SharedPtr<std::istream>;
@@ -408,13 +409,13 @@ inline Poco::UInt16 HTTPClientSession::getProxyPort() const
408409

409410
inline const std::string& HTTPClientSession::getProxyProtocol() const
410411
{
411-
return _proxyConfig.protocol;
412+
return _proxyConfig.protocol;
412413
}
413414

414415

415416
inline bool HTTPClientSession::isProxyTunnel() const
416417
{
417-
return _proxyConfig.tunnel;
418+
return _proxyConfig.tunnel;
418419
}
419420

420421

Net/include/Poco/Net/ProxyConfig.h

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
// Definition of the ProxyConfig class.
99
//
10-
// Copyright (c) 2005-2006, Applied Informatics Software Engineering GmbH.
10+
// Copyright (c) 2005-2026, Applied Informatics Software Engineering GmbH.
1111
// and Contributors.
1212
//
1313
// SPDX-License-Identifier: BSL-1.0
@@ -21,44 +21,50 @@
2121

2222
namespace Poco {
2323
namespace Net {
24-
enum ProxyAuthentication {
25-
PROXY_AUTH_NONE, /// No proxy authentication
26-
PROXY_AUTH_HTTP_BASIC, /// HTTP Basic proxy authentication (default, if username and password are supplied)
27-
PROXY_AUTH_HTTP_DIGEST, /// HTTP Digest proxy authentication
28-
PROXY_AUTH_NTLM /// NTLMv2 proxy authentication
29-
};
3024

31-
struct ProxyConfig
32-
/// HTTP proxy server configuration.
33-
{
34-
ProxyConfig() :
35-
port(HTTPSession::HTTP_PORT),
36-
protocol("http"),
37-
tunnel(true),
38-
authMethod(PROXY_AUTH_HTTP_BASIC) {
39-
}
4025

41-
std::string host;
42-
/// Proxy server host name or IP address.
43-
Poco::UInt16 port;
44-
/// Proxy server TCP port.
45-
std::string protocol;
46-
/// Protocol to use (http or https).
47-
bool tunnel;
48-
/// Use proxy as tunnel (establish 2-way communication through CONNECT request).
49-
/// If tunnel option is 'false' request will be send directly to proxy without CONNECT request.
50-
std::string username;
51-
/// Proxy server username.
52-
std::string password;
53-
/// Proxy server password.
54-
std::string nonProxyHosts;
55-
/// A regular expression defining hosts for which the proxy should be bypassed,
56-
/// e.g. "localhost|127\.0\.0\.1|192\.168\.0\.\d+". Can also be an empty
57-
/// string to disable proxy bypassing.
26+
enum ProxyAuthentication
27+
{
28+
PROXY_AUTH_NONE, /// No proxy authentication
29+
PROXY_AUTH_HTTP_BASIC, /// HTTP Basic proxy authentication (default, if username and password are supplied)
30+
PROXY_AUTH_HTTP_DIGEST, /// HTTP Digest proxy authentication
31+
PROXY_AUTH_NTLM /// NTLMv2 proxy authentication
32+
};
33+
34+
35+
struct ProxyConfig
36+
/// HTTP proxy server configuration.
37+
{
38+
ProxyConfig():
39+
port(HTTPSession::HTTP_PORT),
40+
protocol("http"),
41+
tunnel(true),
42+
authMethod(PROXY_AUTH_HTTP_BASIC)
43+
{
44+
}
45+
46+
std::string host;
47+
/// Proxy server host name or IP address.
48+
Poco::UInt16 port;
49+
/// Proxy server TCP port.
50+
std::string protocol;
51+
/// Protocol to use (http or https).
52+
bool tunnel;
53+
/// Use proxy as tunnel (establish 2-way communication through CONNECT request).
54+
/// If tunnel option is 'false' request will be sent directly to proxy without CONNECT request.
55+
std::string username;
56+
/// Proxy server username.
57+
std::string password;
58+
/// Proxy server password.
59+
std::string nonProxyHosts;
60+
/// A regular expression defining hosts for which the proxy should be bypassed,
61+
/// e.g. "localhost|127\.0\.0\.1|192\.168\.0\.\d+". Can also be an empty
62+
/// string to disable proxy bypassing.
63+
64+
ProxyAuthentication authMethod;
65+
/// The authentication method to use - HTTP Basic or NTLM.
66+
};
5867

59-
ProxyAuthentication authMethod;
60-
/// The authentication method to use - HTTP Basic or NTLM.
61-
};
6268

6369
} } // namespace Poco::Net
6470

Net/src/HTTPClientSession.cpp

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ HTTPClientSession::HTTPClientSession():
5252
_responseReceived(false),
5353
_ntlmProxyAuthenticated(false)
5454
{
55-
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
55+
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
5656
}
5757

5858

@@ -69,7 +69,7 @@ HTTPClientSession::HTTPClientSession(const StreamSocket& socket):
6969
_responseReceived(false),
7070
_ntlmProxyAuthenticated(false)
7171
{
72-
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
72+
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
7373
}
7474

7575

@@ -86,7 +86,7 @@ HTTPClientSession::HTTPClientSession(const SocketAddress& address):
8686
_responseReceived(false),
8787
_ntlmProxyAuthenticated(false)
8888
{
89-
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
89+
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
9090
}
9191

9292

@@ -103,7 +103,7 @@ HTTPClientSession::HTTPClientSession(const std::string& host, Poco::UInt16 port)
103103
_responseReceived(false),
104104
_ntlmProxyAuthenticated(false)
105105
{
106-
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
106+
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
107107
}
108108

109109

@@ -133,13 +133,13 @@ HTTPClientSession::HTTPClientSession(const StreamSocket& socket, const ProxyConf
133133
_expectResponseBody(false),
134134
_responseReceived(false)
135135
{
136-
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
136+
_proxySessionFactory.registerProtocol("http", new HTTPSessionInstantiator);
137137
}
138138

139139

140140
HTTPClientSession::~HTTPClientSession()
141141
{
142-
_proxySessionFactory.unregisterProtocol("http");
142+
_proxySessionFactory.unregisterProtocol("http");
143143
}
144144

145145

@@ -196,17 +196,17 @@ const SocketAddress& HTTPClientSession::getSourceAddress6()
196196

197197
void HTTPClientSession::setProxy(const std::string& host, Poco::UInt16 port, const std::string& protocol, bool tunnel)
198198
{
199-
if (protocol != "http" && protocol != "https")
200-
throw IllegalStateException("Protocol must be either http or https");
199+
if (protocol != "http" && protocol != "https")
200+
throw IllegalStateException("Protocol must be either http or https");
201201

202-
if (!connected())
202+
if (!connected())
203203
{
204204
_proxyConfig.host = host;
205205
_proxyConfig.port = port;
206206
_proxyConfig.protocol = protocol;
207207
_proxyConfig.tunnel = tunnel;
208208
}
209-
else throw IllegalStateException("Cannot set the proxy host, port and protocol for an already connected session");
209+
else throw IllegalStateException("Cannot set the proxy host, port and protocol for an already connected session");
210210
}
211211

212212

@@ -230,23 +230,22 @@ void HTTPClientSession::setProxyPort(Poco::UInt16 port)
230230

231231
void HTTPClientSession::setProxyProtocol(const std::string& protocol)
232232
{
233-
if (protocol != "http" && protocol != "https")
234-
throw IllegalStateException("Protocol must be either http or https");
233+
if (protocol != "http" && protocol != "https")
234+
throw IllegalStateException("Protocol must be either http or https");
235235

236-
if (!connected())
237-
_proxyConfig.protocol = protocol;
238-
else
239-
throw IllegalStateException("Cannot set the proxy port number for an already connected session");
236+
if (!connected())
237+
_proxyConfig.protocol = protocol;
238+
else
239+
throw IllegalStateException("Cannot set the proxy protocol for an already connected session");
240240
}
241241

242242

243243
void HTTPClientSession::setProxyTunnel(bool tunnel)
244244
{
245-
if (!connected())
246-
_proxyConfig.tunnel = tunnel;
247-
else
248-
throw IllegalStateException("Cannot set the proxy tunnel for an already connected session");
249-
245+
if (!connected())
246+
_proxyConfig.tunnel = tunnel;
247+
else
248+
throw IllegalStateException("Cannot set the proxy tunnel for an already connected session");
250249
}
251250

252251

@@ -623,9 +622,9 @@ void HTTPClientSession::sendChallengeRequest(const HTTPRequest& request, HTTPRes
623622
StreamSocket HTTPClientSession::proxyConnect()
624623
{
625624
URI proxyUri;
626-
proxyUri.setScheme(getProxyProtocol());
627-
proxyUri.setHost(getProxyHost());
628-
proxyUri.setPort(getProxyPort());
625+
proxyUri.setScheme(getProxyProtocol());
626+
proxyUri.setHost(getProxyHost());
627+
proxyUri.setPort(getProxyPort());
629628

630629
SharedPtr<HTTPClientSession> proxySession (_proxySessionFactory.createClientSession(proxyUri));
631630

0 commit comments

Comments
 (0)