HTTP module

Authenticator

Maintains HTTP Basic or Digest authentication state for outbound requests.

Authenticator

#include <icy/http/authenticator.h>

Maintains HTTP Basic or Digest authentication state for outbound requests.

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 Methods

ReturnNameDescription
AuthenticatorCreates an empty authenticator.
AuthenticatorCreates an authenticator with the given username and password.
~AuthenticatorDestroys the authenticator.
voidfromUserInfoParses username:password std::string and sets username and password of the credentials object. Throws SyntaxException on invalid user information.
voidfromURIExtracts 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.
voidsetUsernameSets the username.
const std::string &username constReturns the username.
voidsetPasswordSets the password.
const std::string &password constReturns the password.
voidauthenticateInspects WWW-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request.
voidupdateAuthInfoUpdates internal state (in case of digest authentication) and replaces authentication information in the request accordingly.
voidproxyAuthenticateInspects Proxy-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request.
voidupdateProxyAuthInfoUpdates internal state (in case of digest authentication) and replaces proxy authentication information in the request accordingly.

Authenticator

Authenticator()

Creates an empty authenticator.


Authenticator

Authenticator(const std::string & username, const std::string & password)

Creates an authenticator with the given username and password.


~Authenticator

~Authenticator()

Destroys the authenticator.


fromUserInfo

void fromUserInfo(std::string_view userInfo)

Parses username:password std::string and sets username and password of the credentials object. Throws SyntaxException on invalid user information.


fromURI

void fromURI(const http::URL & 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.


setUsername

void setUsername(const std::string & username)

Sets the username.


username

const

const std::string & username() const

Returns the username.


setPassword

void setPassword(const std::string & password)

Sets the password.


password

const

const std::string & password() const

Returns the password.


authenticate

void authenticate(http::Request & request, const http::Response & response)

Inspects WWW-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request.


updateAuthInfo

void updateAuthInfo(http::Request & request)

Updates internal state (in case of digest authentication) and replaces authentication information in the request accordingly.


proxyAuthenticate

void proxyAuthenticate(http::Request & request, const http::Response & response)

Inspects Proxy-Authenticate header of the response, initializes the internal state (in case of digest authentication) and adds required information to the given http::Request.


updateProxyAuthInfo

void updateProxyAuthInfo(http::Request & request)

Updates internal state (in case of digest authentication) and replaces proxy authentication information in the request accordingly.

Private Attributes

ReturnNameDescription
std::string_username
std::string_password

_username

std::string _username

_password

std::string _password

Private Methods

ReturnNameDescription
AuthenticatorDeleted constructor.

Authenticator

Authenticator(const Authenticator &) = delete

Deleted constructor.