Callbacks¶
| AddressCallback(addr, status, *user_data) | |
| AuthDomainBasicAuthCallback(domain, msg, username, password, *user_data) | |
| AuthDomainDigestAuthCallback(domain, msg, username, *user_data) | |
| AuthDomainFilter(domain, msg, *user_data) | |
| AuthDomainGenericAuthCallback(domain, msg, username, *user_data) | |
| ChunkAllocator(msg, max_len, *user_data) | |
| LoggerFilter(logger, msg, *user_data) | |
| LoggerPrinter(logger, level, direction, data, *user_data) | |
| MessageHeadersForeachFunc(name, value, *user_data) | |
| PasswordManagerCallback(password_manager, msg, auth, retrying, *user_data) | |
| ProxyResolverCallback(proxy_resolver, msg, arg, addr, *user_data) | |
| ProxyURIResolverCallback(resolver, status, proxy_uri, *user_data) | |
| ServerCallback(server, msg, path, query, client, *user_data) | |
| ServerWebsocketCallback(server, connection, path, client, *user_data) | |
| SessionCallback(session, msg, *user_data) | |
| SessionConnectProgressCallback(session, event, connection, *user_data) | |
| SocketCallback(sock, status, *user_data) | 
Details¶
- 
Soup.AddressCallback(addr, status, *user_data)¶
- Parameters: - addr (Soup.Address) – theSoup.Addressthat was resolved
- status (int) –Soup.Status.OK,Soup.Status.CANT_RESOLVE, orSoup.Status.CANCELLED
- user_data (objectorNone) – the user data that was passed toSoup.Address.resolve_async()
 - The callback function passed to - Soup.Address.resolve_async().
- addr (
- 
Soup.AuthDomainBasicAuthCallback(domain, msg, username, password, *user_data)¶
- Parameters: - domain (Soup.AuthDomainBasic) – the domain
- msg (Soup.Message) – the message being authenticated
- username (str) – the username provided by the client
- password (str) – the password provided by the client
- user_data (objectorNone) – the data passed toSoup.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- Trueor- False.- 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. 
- domain (
- 
Soup.AuthDomainDigestAuthCallback(domain, msg, username, *user_data)¶
- Parameters: - domain (Soup.AuthDomainDigest) – the domain
- msg (Soup.Message) – the message being authenticated
- username (str) – the username provided by the client
- user_data (objectorNone) – the data passed toSoup.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- Soup.AuthDomainDigest.encode_password()).
- domain (
- 
Soup.AuthDomainFilter(domain, msg, *user_data)¶
- Parameters: - domain (Soup.AuthDomain) – aSoup.AuthDomain
- msg (Soup.Message) – aSoup.Message
- user_data (objectorNone) – the data passed toSoup.AuthDomain.set_filter()
 - Returns: - Return type: - The prototype for a - Soup.AuthDomainfilter; see- Soup.AuthDomain.set_filter() for details.
- domain (
- 
Soup.AuthDomainGenericAuthCallback(domain, msg, username, *user_data)¶
- Parameters: - domain (Soup.AuthDomain) – aSoup.AuthDomain
- msg (Soup.Message) – theSoup.Messagebeing authenticated
- username (str) – the username from msg
- user_data (objectorNone) – the data passed toSoup.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 - Soup.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, - Soup.AuthDomainBasicAuthCallbackand- Soup.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- Soup.Serveris used, this is not really relevant, but it may still be worth considering.
- domain (
- 
Soup.ChunkAllocator(msg, max_len, *user_data)¶
- Parameters: - msg (Soup.Message) – theSoup.Messagethe chunk is being allocated for
- max_len (int) – the maximum length that will be read, or 0.
- user_data (objectorNone) – the data passed toSoup.Message.set_chunk_allocator()
 - Returns: - the new buffer (or - None)- Return type: - Soup.Bufferor- None- The prototype for a chunk allocation callback. This should allocate a new - Soup.Bufferand return it for the I/O layer to read message body data off the network into.- If max_len is non-0, it indicates the maximum number of bytes that could be read, based on what is known about the message size. Note that this might be a very large number, and you should not simply try to allocate that many bytes blindly. If max_len is 0, that means that libsoup does not know how many bytes remain to be read, and the allocator should return a buffer of a size that it finds convenient. - If the allocator returns - None, the message will be paused. It is up to the application to make sure that it gets unpaused when it becomes possible to allocate a new buffer.- Deprecated since version ???: Use - Soup.Requestif you want to read into your own buffers.
- msg (
- 
Soup.LoggerFilter(logger, msg, *user_data)¶
- Parameters: - logger (Soup.Logger) – theSoup.Logger
- msg (Soup.Message) – the message being logged
- user_data (objectorNone) – the data passed toSoup.Logger.set_request_filter() orSoup.Logger.set_response_filter()
 - Returns: - a - Soup.LoggerLogLevelvalue 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 - Soup.LoggerLogLevelvalue indicating how much of the message to log. Eg, it might choose between- Soup.LoggerLogLevel.BODYand- Soup.LoggerLogLevel.HEADERSdepending on the Content-Type.
- logger (
- 
Soup.LoggerPrinter(logger, level, direction, data, *user_data)¶
- Parameters: - logger (Soup.Logger) – theSoup.Logger
- level (Soup.LoggerLogLevel) – the level of the information being printed.
- direction (int) – a single-character prefix to data
- data (str) – data to print
- user_data (objectorNone) – the data passed toSoup.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: - <informalexample><programlisting> printf (“%c %s\n”, direction, data); </programlisting></informalexample> 
- logger (
- 
Soup.MessageHeadersForeachFunc(name, value, *user_data)¶
- Parameters: - name (str) – the header name
- value (str) – the header value
- user_data (objectorNone) – the data passed toSoup.MessageHeaders.foreach()
 - The callback passed to - Soup.MessageHeaders.foreach().
- name (
- 
Soup.PasswordManagerCallback(password_manager, msg, auth, retrying, *user_data)¶
- Parameters: - password_manager (Soup.PasswordManager) –
- msg (Soup.Message) –
- auth (Soup.Auth) –
- retrying (bool) –
- user_data (objectorNone) –
 
- password_manager (
- 
Soup.ProxyResolverCallback(proxy_resolver, msg, arg, addr, *user_data)¶
- Parameters: - proxy_resolver (Soup.ProxyResolver) –
- msg (Soup.Message) –
- arg (int) –
- addr (Soup.Address) –
- user_data (objectorNone) –
 - Deprecated since version 2.28: Use - Soup.ProxyURIResolverinstead
- proxy_resolver (
- 
Soup.ProxyURIResolverCallback(resolver, status, proxy_uri, *user_data)¶
- Parameters: - resolver (Soup.ProxyURIResolver) – theSoup.ProxyURIResolver
- status (int) – aSoup.Status
- proxy_uri (Soup.URI) – the resolved proxy URI, orNone
- user_data (objectorNone) – data passed toSoup.ProxyURIResolver.get_proxy_uri_async()
 - Callback for - Soup.ProxyURIResolver.get_proxy_uri_async()
- resolver (
- 
Soup.ServerCallback(server, msg, path, query, client, *user_data)¶
- Parameters: - server (Soup.Server) – theSoup.Server
- msg (Soup.Message) – the message being processed
- path (str) – the path component of msg’s Request-URI
- query ({str:str} orNone) – the parsed query component of msg’s Request-URI
- client (Soup.ClientContext) – additional contextual information about the client
- user_data (objectorNone) – the data passed toSoup.Server.add_handler() orSoup.Server.add_early_handler().
 - A callback used to handle requests to a - Soup.Server.- path and query contain the likewise-named components of the Request-URI, subject to certain assumptions. By default, - Soup.Serverdecodes 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- Soup.SERVER_RAW_PATHSproperty when creating the- Soup.Server, and it will leave those characters undecoded. (You may want to call- Soup.URI.normalize() to decode any percent-encoded characters that you aren’t handling specially.)- 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 - Soup.Message.get_uri() and parse the URI’s query field yourself.- See - Soup.Server.add_handler() and- Soup.Server.add_early_handler() for details of what handlers can/should do.
- server (
- 
Soup.ServerWebsocketCallback(server, connection, path, client, *user_data)¶
- Parameters: - server (Soup.Server) – theSoup.Server
- connection (Soup.WebsocketConnection) – the newly created WebSocket connection
- path (str) – the path component of msg’s Request-URI
- client (Soup.ClientContext) – additional contextual information about the client
- user_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 - Soup.ServerCallback(qv).
- server (
- 
Soup.SessionCallback(session, msg, *user_data)¶
- Parameters: - session (Soup.Session) – the session
- msg (Soup.Message) – the message that has finished
- user_data (objectorNone) – the data passed toSoup.Session.queue_message
 - Prototype for the callback passed to - Soup.Session.queue_message(), qv.
- session (
- 
Soup.SessionConnectProgressCallback(session, event, connection, *user_data)¶
- Parameters: - session (Soup.Session) – theSoup.Session
- event (Gio.SocketClientEvent) – aGio.SocketClientEvent
- connection (Gio.IOStream) – the current state of the network connection
- user_data (objectorNone) – the data passed toSoup.Session.connect_async().
 - Prototype for the progress callback passed to - Soup.Session.connect_async().- New in version 2.62. 
- session (
- 
Soup.SocketCallback(sock, status, *user_data)¶
- Parameters: - sock (Soup.Socket) – theSoup.Socket
- status (int) – an HTTP status code indicating success or failure
- user_data (objectorNone) – the data passed toSoup.Socket.connect_async()
 - The callback function passed to - Soup.Socket.connect_async().
- sock (