Callbacks¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Details¶
- Soup.AuthDomainBasicAuthCallback(domain, msg, username, password, *user_data)¶
- Parameters:
domain (
Soup.AuthDomainBasic) – the domainmsg (
Soup.ServerMessage) – the message being authenticatedusername (
str) – the username provided by the clientpassword (
str) – the password provided by the clientuser_data (
objectorNone) – the data passed to [method`AuthDomainBasic`.set_auth_callback]
- Returns:
Trueif username and password are valid- Return type:
Callback used by
Soup.AuthDomainBasicfor authentication purposes.The application should verify that username and password and valid and return
TrueorFalse.If you are maintaining your own password database (rather than using the password to authenticate against some other system like PAM or a remote server), you should make sure you know what you are doing. In particular, don’t store cleartext passwords, or easily-computed hashes of cleartext passwords, even if you don’t care that much about the security of your server, because users will frequently use the same password for multiple sites, and so compromising any site with a cleartext (or easily-cracked) password database may give attackers access to other more-interesting sites as well.
- Soup.AuthDomainDigestAuthCallback(domain, msg, username, *user_data)¶
- Parameters:
domain (
Soup.AuthDomainDigest) – the domainmsg (
Soup.ServerMessage) – the message being authenticatedusername (
str) – the username provided by the clientuser_data (
objectorNone) – the data passed to [method`AuthDomainDigest`.set_auth_callback]
- Returns:
the encoded password, or
Noneif username is not a valid user. domain will free the password when it is done with it.- Return type:
Callback used by
Soup.AuthDomainDigestfor authentication purposes.The application should look up username in its password database, and return the corresponding encoded password (see [func`AuthDomainDigest`.encode_password].
- Soup.AuthDomainFilter(domain, msg, *user_data)¶
- Parameters:
domain (
Soup.AuthDomain) – aSoup.AuthDomainmsg (
Soup.ServerMessage) – aSoup.ServerMessageuser_data (
objectorNone) – the data passed to [method`AuthDomain`.set_filter]
- Returns:
- Return type:
The prototype for a
Soup.AuthDomainfilter.See [method`AuthDomain`.set_filter] for details.
- Soup.AuthDomainGenericAuthCallback(domain, msg, username, *user_data)¶
- Parameters:
domain (
Soup.AuthDomain) – aSoup.AuthDomainmsg (
Soup.ServerMessage) – theSoup.ServerMessagebeing authenticatedusername (
str) – the username from msguser_data (
objectorNone) – the data passed to [method`AuthDomain`.set_generic_auth_callback]
- Returns:
- Return type:
The prototype for a
Soup.AuthDomaingeneric authentication callback.The callback should look up the user’s password, call [method`AuthDomain`.check_password], and use the return value from that method as its own return value.
In general, for security reasons, it is preferable to use the auth-domain-specific auth callbacks (eg, [callback`AuthDomainBasicAuthCallback`] and [callback`AuthDomainDigestAuthCallback`]), because they don’t require keeping a cleartext password database. Most users will use the same password for many different sites, meaning if any site with a cleartext password database is compromised, accounts on other servers might be compromised as well. For many of the cases where [class`Server`] is used, this is not really relevant, but it may still be worth considering.
- Soup.LoggerFilter(logger, msg, *user_data)¶
- Parameters:
logger (
Soup.Logger) – theSoup.Loggermsg (
Soup.Message) – the message being loggeduser_data (
objectorNone) – the data passed to [method`Logger`.set_request_filter] or [method`Logger`.set_response_filter]
- Returns:
a [enum`LoggerLogLevel`] value indicating how much of the message to log
- Return type:
The prototype for a logging filter.
The filter callback will be invoked for each request or response, and should analyze it and return a [enum`LoggerLogLevel`] value indicating how much of the message to log.
- Soup.LoggerPrinter(logger, level, direction, data, *user_data)¶
- Parameters:
logger (
Soup.Logger) – theSoup.Loggerlevel (
Soup.LoggerLogLevel) – the level of the information being printed.direction (
int) – a single-character prefix to datadata (
str) – data to printuser_data (
objectorNone) – the data passed to [method`Logger`.set_printer]
The prototype for a custom printing callback.
level indicates what kind of information is being printed. Eg, it will be
Soup.LoggerLogLevel.HEADERSif data is header data.direction is either ‘<’, ‘>’, or ‘ ‘, and data is the single line to print; the printer is expected to add a terminating newline.
To get the effect of the default printer, you would do:
``c printf (“%c %sn”, direction, data); ``
- Soup.MessageHeadersForeachFunc(name, value, *user_data)¶
- Parameters:
The callback passed to [method`MessageHeaders`.foreach].
- Soup.ServerCallback(server, msg, path, query, *user_data)¶
- Parameters:
server (
Soup.Server) – theSoup.Servermsg (
Soup.ServerMessage) – the message being processedpath (
str) – the path component of msg's Request-URIquery ({
str:str} orNone) – the parsed query component of msg's Request-URIuser_data (
objectorNone) – the data passed to [method`Server`.add_handler] or [method`Server`.add_early_handler].
A callback used to handle requests to a [class`Server`].
path and query contain the likewise-named components of the Request-URI, subject to certain assumptions. By default, [class`Server`] decodes all percent-encoding in the URI path, such that
"/foo%2Fbar"is treated the same as"/foo/bar". If your server is serving resources in some non-POSIX-filesystem namespace, you may want to distinguish those as two distinct paths. In that case, you can set the [property`Server`:raw-paths] property when creating the [class`Server`], and it will leave those characters undecoded.query contains the query component of the Request-URI parsed according to the rules for HTML form handling. Although this is the only commonly-used query string format in HTTP, there is nothing that actually requires that HTTP URIs use that format; if your server needs to use some other format, you can just ignore query, and call [method`Message`.get_uri] and parse the URI’s query field yourself.
See [method`Server`.add_handler] and [method`Server`.add_early_handler] for details of what handlers can/should do.
- Soup.ServerWebsocketCallback(server, msg, path, connection, *user_data)¶
- Parameters:
server (
Soup.Server) – theSoup.Servermsg (
Soup.ServerMessage) – theSoup.ServerMessagepath (
str) – the path component of msg's Request-URIconnection (
Soup.WebsocketConnection) – the newly created WebSocket connectionuser_data (
objectorNone) – the data passed to soup_server_add_handler
A callback used to handle WebSocket requests to a
Soup.Server.The callback will be invoked after sending the handshake response back to the client (and is only invoked if the handshake was successful).
path contains the path of the Request-URI, subject to the same rules as [callback`ServerCallback`]
(qv).