WebResource
Superclasses: Object
Represents a resource at the end of a URI.
A WebResource
encapsulates content for each resource at the
end of a particular URI. For example, one WebResource
will
be created for each separate image and stylesheet when a page is
loaded.
You can access the response and the URI for a given
WebResource
, using get_uri()
and
get_response()
, as well as the raw data, using
get_data()
.
Methods
- class WebResource
- get_data(cancellable: Cancellable | None = None, callback: Callable[[...], None] | None = None, *user_data: Any) None
Asynchronously get the raw data for
resource
.When the operation is finished,
callback
will be called. You can then callget_data_finish()
to get the result of the operation.- Parameters:
cancellable – a
Cancellable
orNone
to ignorecallback – a
AsyncReadyCallback
to call when the request is satisfieduser_data – the data to pass to callback function
- get_data_finish(result: AsyncResult) bytes
Finish an asynchronous operation started with
get_data()
.- Parameters:
result – a
AsyncResult
- get_response() URIResponse
Retrieves the
URIResponse
of the resource load operation.This method returns
None
if called before the response is received from the server. You can connect to notify::response signal to be notified when the response is received.
- get_uri() str
Returns the current active URI of
resource
.The active URI might change during a load operation:
<orderedlist> <listitem><para>
When the resource load starts, the active URI is the requested URI
</para></listitem> <listitem><para>
When the initial request is sent to the server,
WebResource
::sent-request signal is emitted without a redirected response, the active URI is the URI of the request sent to the server.</para></listitem> <listitem><para>
In case of a server redirection,
WebResource
::sent-request signal is emitted again with a redirected response, the active URI is the URI the request was redirected to.</para></listitem> <listitem><para>
When the response is received from the server, the active URI is the final one and it will not change again.
</para></listitem> </orderedlist>
You can monitor the active URI by connecting to the notify::uri signal of
resource
.
Properties
- class WebResource
- props.response: URIResponse
The
URIResponse
associated with this resource.
- props.uri: str
The current active URI of the
WebResource
. Seeget_uri()
for more details.
Signals
- class WebResource.signals
- failed(error: GError) None
This signal is emitted when an error occurs during the resource load operation.
- Parameters:
error – the
Error
that was triggered
- failed_with_tls_errors(certificate: TlsCertificate, errors: TlsCertificateFlags) None
This signal is emitted when a TLS error occurs during the resource load operation.
Added in version 2.8.
- Parameters:
certificate – a
TlsCertificate
errors – a
TlsCertificateFlags
with the verification status ofcertificate
- finished() None
This signal is emitted when the resource load finishes successfully or due to an error. In case of errors
WebResource
::failed signal is emitted before this one.
- sent_request(request: URIRequest, redirected_response: URIResponse) None
This signal is emitted when
request
has been sent to the server. In case of a server redirection this signal is emitted again with therequest
argument containing the new request sent to the server due to the redirection and theredirected_response
parameter containing the response received by the server for the initial request.- Parameters:
request – a
URIRequest
redirected_response – a
URIResponse
, orNone