mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 19:51:58 +01:00
trunk: sync from 1.4.3
make & cmake fixes
This commit is contained in:
@@ -269,12 +269,20 @@ protected:
|
||||
/// proxy username and password have been set.
|
||||
|
||||
void proxyAuthenticateImpl(HTTPRequest& request);
|
||||
/// Sets the proxy credentials (Proxy-Authorization header), if
|
||||
/// proxy username and password have been set.
|
||||
/// Sets the proxy credentials (Proxy-Authorization header), if
|
||||
/// proxy username and password have been set.
|
||||
|
||||
StreamSocket proxyConnect();
|
||||
/// Sends a CONNECT request to the proxy server and returns
|
||||
/// a StreamSocket for the resulting connection.
|
||||
|
||||
void proxyTunnel();
|
||||
/// Calls proxyConnect() and attaches the resulting StreamSocket
|
||||
/// to the HTTPClientSession.
|
||||
|
||||
private:
|
||||
std::string _host;
|
||||
Poco::UInt16 _port;
|
||||
std::string _host;
|
||||
Poco::UInt16 _port;
|
||||
std::string _proxyHost;
|
||||
Poco::UInt16 _proxyPort;
|
||||
std::string _proxyUsername;
|
||||
@@ -286,9 +294,11 @@ private:
|
||||
bool _expectResponseBody;
|
||||
std::ostream* _pRequestStream;
|
||||
std::istream* _pResponseStream;
|
||||
|
||||
HTTPClientSession(const HTTPClientSession&);
|
||||
HTTPClientSession& operator = (const HTTPClientSession&);
|
||||
|
||||
HTTPClientSession(const HTTPClientSession&);
|
||||
HTTPClientSession& operator = (const HTTPClientSession&);
|
||||
|
||||
friend class WebSocket;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
//
|
||||
// Library: Net
|
||||
// Package: HTTP
|
||||
// Module: HTTPCredentials
|
||||
// Module: HTTPCredentials
|
||||
//
|
||||
// Definition of the HTTPCredentials class.
|
||||
//
|
||||
@@ -58,91 +58,107 @@ class HTTPResponse;
|
||||
|
||||
|
||||
class Net_API HTTPCredentials
|
||||
/// This is a utility class for working with HTTP
|
||||
/// authentication (basic or digest) in HTTPRequest objects.
|
||||
///
|
||||
/// Usage is as follows:
|
||||
/// First, create a HTTPCredentials object containing
|
||||
/// the username and password.
|
||||
/// Poco::Net::HTTPCredentials creds("user", "s3cr3t");
|
||||
///
|
||||
/// Second, send the HTTP request with Poco::Net::HTTPClientSession.
|
||||
/// Poco::Net::HTTPClientSession session("pocoproject.org");
|
||||
/// Poco::Net::HTTPRequest request(HTTPRequest::HTTP_GET, "/index.html", HTTPMessage::HTTP_1_1);
|
||||
/// session.sendRequest(request);
|
||||
/// Poco::Net::HTTPResponse;
|
||||
/// std::istream& istr = session.receiveResponse(response);
|
||||
///
|
||||
/// If the server responds with a 401 status, authenticate the
|
||||
/// request and resend it:
|
||||
/// if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED)
|
||||
/// {
|
||||
/// creds.authenticate(request, response);
|
||||
/// session.sendRequest(request);
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// To perform multiple authenticated requests, call updateAuthInfo()
|
||||
/// instead of authenticate() on subsequent requests.
|
||||
/// creds.updateAuthInfo(request);
|
||||
/// session.sendRequest(request);
|
||||
/// ...
|
||||
///
|
||||
/// Note: Do not forget to read the entire response stream from the 401 response
|
||||
/// before sending the authenticated request, otherwise there may be
|
||||
/// problems if a persistent connection is used.
|
||||
/// This is a utility class for working with HTTP
|
||||
/// authentication (basic or digest) in HTTPRequest objects.
|
||||
///
|
||||
/// Usage is as follows:
|
||||
/// First, create a HTTPCredentials object containing
|
||||
/// the username and password.
|
||||
/// Poco::Net::HTTPCredentials creds("user", "s3cr3t");
|
||||
///
|
||||
/// Second, send the HTTP request with Poco::Net::HTTPClientSession.
|
||||
/// Poco::Net::HTTPClientSession session("pocoproject.org");
|
||||
/// Poco::Net::HTTPRequest request(HTTPRequest::HTTP_GET, "/index.html", HTTPMessage::HTTP_1_1);
|
||||
/// session.sendRequest(request);
|
||||
/// Poco::Net::HTTPResponse;
|
||||
/// std::istream& istr = session.receiveResponse(response);
|
||||
///
|
||||
/// If the server responds with a 401 status, authenticate the
|
||||
/// request and resend it:
|
||||
/// if (response.getStatus() == Poco::Net::HTTPResponse::HTTP_UNAUTHORIZED)
|
||||
/// {
|
||||
/// creds.authenticate(request, response);
|
||||
/// session.sendRequest(request);
|
||||
/// ...
|
||||
/// }
|
||||
///
|
||||
/// To perform multiple authenticated requests, call updateAuthInfo()
|
||||
/// instead of authenticate() on subsequent requests.
|
||||
/// creds.updateAuthInfo(request);
|
||||
/// session.sendRequest(request);
|
||||
/// ...
|
||||
///
|
||||
/// Note: Do not forget to read the entire response stream from the 401 response
|
||||
/// before sending the authenticated request, otherwise there may be
|
||||
/// problems if a persistent connection is used.
|
||||
{
|
||||
public:
|
||||
HTTPCredentials();
|
||||
/// Creates an empty HTTPCredentials object.
|
||||
HTTPCredentials();
|
||||
/// Creates an empty HTTPCredentials object.
|
||||
|
||||
HTTPCredentials(const std::string& username, const std::string& password);
|
||||
/// Creates an HTTPCredentials object with the given username and password.
|
||||
HTTPCredentials(const std::string& username, const std::string& password);
|
||||
/// Creates an HTTPCredentials object with the given username and password.
|
||||
|
||||
~HTTPCredentials();
|
||||
/// Destroys the HTTPCredentials.
|
||||
|
||||
void fromUserInfo(const std::string& userInfo);
|
||||
/// Parses username:password string and sets username and password of
|
||||
/// the credentials object.
|
||||
/// Throws SyntaxException on invalid user information.
|
||||
|
||||
void fromURI(const URI& uri);
|
||||
/// Extracts username and password from the given URI and sets username
|
||||
/// and password of the credentials object.
|
||||
/// Does nothing if URI has no user info part.
|
||||
|
||||
void setUsername(const std::string& username);
|
||||
/// Sets the username.
|
||||
|
||||
const std::string& getUsername() const;
|
||||
/// Returns the username.
|
||||
const std::string& getUsername() const;
|
||||
/// Returns the username.
|
||||
|
||||
void setPassword(const std::string& password);
|
||||
/// Sets the password.
|
||||
void setPassword(const std::string& password);
|
||||
/// Sets the password.
|
||||
|
||||
const std::string& getPassword() const;
|
||||
/// Returns the password.
|
||||
const std::string& getPassword() const;
|
||||
/// Returns the password.
|
||||
|
||||
void authenticate(HTTPRequest& request, const HTTPResponse& response);
|
||||
/// Inspects authenticate header of the response, initializes
|
||||
/// the internal state (in case of digest authentication) and
|
||||
/// adds required information to the given HTTPRequest.
|
||||
///
|
||||
/// Does nothing if there is no authentication header in the
|
||||
/// HTTPResponse.
|
||||
void authenticate(HTTPRequest& request, const HTTPResponse& response);
|
||||
/// Inspects authenticate header of the response, initializes
|
||||
/// the internal state (in case of digest authentication) and
|
||||
/// adds required information to the given HTTPRequest.
|
||||
///
|
||||
/// Does nothing if there is no authentication header in the
|
||||
/// HTTPResponse.
|
||||
|
||||
void updateAuthInfo(HTTPRequest& request);
|
||||
/// Updates internal state (in case of digest authentication) and
|
||||
/// replaces authentication information in the request accordingly.
|
||||
void updateAuthInfo(HTTPRequest& request);
|
||||
/// Updates internal state (in case of digest authentication) and
|
||||
/// replaces authentication information in the request accordingly.
|
||||
|
||||
static bool isBasicCredentials(const std::string& header);
|
||||
/// Returns true if authentication header is for Basic authentication.
|
||||
static bool isBasicCredentials(const std::string& header);
|
||||
/// Returns true if authentication header is for Basic authentication.
|
||||
|
||||
static bool isDigestCredentials(const std::string& header);
|
||||
/// Returns true if authentication header is for Digest authentication.
|
||||
|
||||
static bool hasBasicCredentials(const HTTPRequest& request);
|
||||
/// Returns true if Authorization with Basic credentials header is present in the request.
|
||||
|
||||
static bool hasDigestCredentials(const HTTPRequest& request);
|
||||
/// Returns true if Authorization with Digest credentials header is present in the request.
|
||||
|
||||
static void extractCredentials(const std::string& userInfo, std::string& username, std::string& password);
|
||||
/// Extracts username and password from user:password information string.
|
||||
|
||||
static void extractCredentials(const Poco::URI& uri, std::string& username, std::string& password);
|
||||
/// Extracts username and password from the given URI (e.g.: "http://user:pass@sample.com/secret").
|
||||
static void extractCredentials(const Poco::URI& uri, std::string& username, std::string& password);
|
||||
/// Extracts username and password from the given URI (e.g.: "http://user:pass@sample.com/secret").
|
||||
|
||||
private:
|
||||
HTTPCredentials(const HTTPCredentials&);
|
||||
HTTPCredentials& operator = (const HTTPCredentials&);
|
||||
HTTPCredentials(const HTTPCredentials&);
|
||||
HTTPCredentials& operator = (const HTTPCredentials&);
|
||||
|
||||
HTTPDigestCredentials _digest;
|
||||
HTTPDigestCredentials _digest;
|
||||
};
|
||||
|
||||
|
||||
@@ -151,25 +167,25 @@ private:
|
||||
//
|
||||
inline void HTTPCredentials::setUsername(const std::string& username)
|
||||
{
|
||||
_digest.setUsername(username);
|
||||
_digest.setUsername(username);
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPCredentials::getUsername() const
|
||||
{
|
||||
return _digest.getUsername();
|
||||
return _digest.getUsername();
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline void HTTPCredentials::setPassword(const std::string& password)
|
||||
{
|
||||
_digest.setPassword(password);
|
||||
_digest.setPassword(password);
|
||||
}
|
||||
|
||||
|
||||
inline const std::string& HTTPCredentials::getPassword() const
|
||||
{
|
||||
return _digest.getPassword();
|
||||
return _digest.getPassword();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -70,6 +70,7 @@ POCO_DECLARE_EXCEPTION(Net_API, SMTPException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, POP3Exception, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, ICMPException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, HTMLFormException, NetException)
|
||||
POCO_DECLARE_EXCEPTION(Net_API, WebSocketException, NetException)
|
||||
|
||||
|
||||
} } // namespace Poco::Net
|
||||
|
||||
Reference in New Issue
Block a user