ResourceManager is a tool for monitoring, modifying, and creating network activity.
ID fields
- Resource IDs: a resource is essentially what a URL points to. For each unique URL, there is at least one unique resource ID. Resources are kept alive as long as something is using them. Note that ResourceManager does not retain resources; Opera may free resources if they are not used anywhere. An OnUrlUnload event will be sent in this case.
- Request IDs: represents HTTP requests. The purpose of these IDs is to make it possible to match related request/response events together.
External ID fields
- Window IDs are the same in all services, and can be used interchangeably everywhere. See WindowManager for window-centric commands and events.
- Frame IDs are described in DocumentManager.
- Document IDs are also described in DocumentManager.
Changelog
1.0: |
Initial release. |
1.1: |
Added GetResourceID. |
1.2: |
Added LoadOrigin. |
1.3: |
Added RequestRetry.requestID. |
Add one or more overrides for HTTP headers. An override can be either adding a new header, overwriting an existing one, or removing it completely (if present).
{
-
A list of headers to override. If the 'value' field of any Header is missing, that header will be removed from the request (if present).
{
-
The name of the HTTP header, for instance "Accept-Charset".
-
The value of the HTTP header, for instance "utf-8" when using Accept-Charset, or "text/html; charset=utf8" for Content-Type.
}
}
Clear cached resources, or as many of the resources as possible. (Resources currently in use will not be cleared).
command ClearCache(Default)
returns (Default)
= 9;
Remove all overrides previously added with AddHeaderOverride.
Create a HTTP request from scratch. It is possible to let Opera choose some common headers, or control everything by hand.
command CreateRequest(CreateRequestArg)
{
-
required uint32 windowID = 1;
The Window to perform the request in. (The events triggered by this command will appear to come from this Window).
-
required string url = 2;
-
required string method = 3;
The HTTP method, e.g. "GET", "POST".
-
Set HTTP headers for this request. When HeaderPolicy NORMAL is chosen, Opera will set reasonable default headers. With HeaderPolicy NORMAL, the following headers can not be set by the caller:
- Accept-Charset
- Accept-Encoding
- Cache-Control
- Connection
- Cookie
- Cookie2
- Date
- Expect
- Host
- If-Range
- Pragma
- Range
- TE
- Trailer
- Upgrade
- User-Agent
- Via
Use either HeaderPolicy OVERWRITE, or REPLACE to set these headers.
{
-
The name of the HTTP header, for instance "Accept-Charset".
-
The value of the HTTP header, for instance "utf-8" when using Accept-Charset, or "text/html; charset=utf8" for Content-Type.
}
-
optional Payload payload = 5;
-
Controls how custom headers are handled.
{
-
NORMAL = 1;
Let's Opera choose request headers depending on how the resource is fetched. Custom headers will be set but only if allowed.
-
OVERWRITE = 2;
Similar to NORMAL but any header in headerList will overwrite those chosen by Opera.
-
REPLACE = 3;
Replaces all headers with the custom ones. Care must be taken as illegal requests can easily be created with this. It is primarly used for re-running a previous request with the same or slighly altered headers.
}
-
optional ReloadPolicy reloadPolicy = 7 [default = 1];
Override the global reload policy for this resource.
{
-
DEFAULT = 1;
Do not interfere with caching policy. This means there might be no OnRequest-events from a certain URL-load if the resource is cached.
-
NO_CACHE = 2;
Load resources in full from the server, even if the resource is unchanged and could be fetched from cache.
}
-
optional ContentMode requestContentMode = 8;
Override the global request content mode for this resource.
{
-
optional Transport transport = 1 [default = 4];
Indicates how to send the payload.
{
-
STRING = 1;
Send the payload as a string.
Selecting this transport mode will automatically enable decoding, and the string will automatically converted to the correct character encoding.
If this transport mode is used an unsuitable content type, the payload will not be sent (without errors).
-
BYTES = 2;
Send the payload as bytes. When this transport mode is chosen, character conversion will not be performed. If the payload contains text data, it will be sent in its original encoding.
-
DATA_URI = 3;
Send the payload as a base64-encoded data URI in the string field. When this transport mode is chosen, character conversion will not be performed. If the payload contains text data, it will be sent in its original encoding.
-
OFF = 4;
Do not send the payload at all.
}
-
optional bool decode = 2 [default = false];
Decode the data (for instance, decompress it, decrypt it, etc). This is unrelated to character encoding.
-
optional uint32 sizeLimit = 3 [default = 1000000];
Even if other conditions are met, do not send the payload if it exceeds the specified amout (in bytes).
By default, only payloads under one megabyte are sent.
}
-
optional ContentMode responseContentMode = 9;
Override the global response content mode for this resource.
{
-
optional Transport transport = 1 [default = 4];
Indicates how to send the payload.
{
-
STRING = 1;
Send the payload as a string.
Selecting this transport mode will automatically enable decoding, and the string will automatically converted to the correct character encoding.
If this transport mode is used an unsuitable content type, the payload will not be sent (without errors).
-
BYTES = 2;
Send the payload as bytes. When this transport mode is chosen, character conversion will not be performed. If the payload contains text data, it will be sent in its original encoding.
-
DATA_URI = 3;
Send the payload as a base64-encoded data URI in the string field. When this transport mode is chosen, character conversion will not be performed. If the payload contains text data, it will be sent in its original encoding.
-
OFF = 4;
Do not send the payload at all.
}
-
optional bool decode = 2 [default = false];
Decode the data (for instance, decompress it, decrypt it, etc). This is unrelated to character encoding.
-
optional uint32 sizeLimit = 3 [default = 1000000];
Even if other conditions are met, do not send the payload if it exceeds the specified amout (in bytes).
By default, only payloads under one megabyte are sent.
}
}
returns (ResourceID)
= 8;
Get ResourceData for a certain resource.
This command provides a way to get data from a resource after the request has completed, or in cases where there is no request.
It is possible to get the resource with a different content mode than what has been set by SetResponseMode.
command GetResource(GetResourceArg)
returns (ResourceData)
{
-
required uint32 resourceID = 1;
-
required string url = 2;
-
optional string mimeType = 3;
The used mime type. This may be different from the mime type advertised in the HTTP headers.
-
optional string characterEncoding = 4;
Original character encoding (if applicable).
-
optional uint32 contentLength = 5;
Content-Length, as advertised by HTTP headers.
-
optional Content content = 6;
{
-
optional uint32 length = 1;
If BYTES or DATA_URI was chosen as the transport mode, this field contains the size of the data. (If, in addition, decoding was enabled, the field contains the size of the decoded data).
If STRING was chosen as the transport mode, this field contains the string length (regardless of encoding), i.e. the number of characters, not including zero terminator.
-
optional string characterEncoding = 2;
The (original) character encoding of the data (if applicable).
-
optional bytes byteData = 3;
This field contains the data if BYTES was chosen as the transport mode. If other modes were chosen, this field is not set.
@see ContentMode::Transport
-
optional string stringData = 4;
This field contains the data if either STRING or DATA_URI were chosen as transport mode. If some other mode was chosen, this field is not set.
@see ContentMode::Transport
}
}
= 1;
Get the resource ID of a URL that is either in cache, or otherwise in use (for instance currently being loaded).
In some cases the same resource may have multiple IDs, for instance POST form results. Trying to get an ID for resources with multiple IDs will result in an error.
An error will also be returned if the specified URL is not in use. Use CreateRequest
to generate a resource ID in this case.
Note that setting the reload policy to NO_CACHE does not exclude the use of this command. Setting the reload policy to NO_CACHE does not prevent resources from entering cache, it merely prevents reloading from it.
Added in version 1.1
command GetResourceID(GetResourceIDArg)
returns (ResourceID)
= 21;
Remove overrides previously added with AddHeaderOverrides.
{
-
A list of header names to remove overrides for. If there is no override for a certain name, it will be ignored.
}
Choose whether resources should be allowed to load from cache, or whether they should be fully downloaded over the network on each reload.
The default mode is to always load resources fully.
command SetReloadPolicy(SetReloadPolicyArg)
returns (Default)
= 2;
Choose how (and if) request data should be reported. It's possible to set a filter with different settings based on MIME type.
command SetRequestMode(SetRequestModeArg)
{
-
optional ContentMode defaultContentMode = 1;
If there is no matching mode for a certain mime type, then this mode will be used. If not present, no data is received by default.
{
-
optional Transport transport = 1 [default = 4];
Indicates how to send the payload.
{
-
STRING = 1;
Send the payload as a string.
Selecting this transport mode will automatically enable decoding, and the string will automatically converted to the correct character encoding.
If this transport mode is used an unsuitable content type, the payload will not be sent (without errors).
-
BYTES = 2;
Send the payload as bytes. When this transport mode is chosen, character conversion will not be performed. If the payload contains text data, it will be sent in its original encoding.
-
DATA_URI = 3;
Send the payload as a base64-encoded data URI in the string field. When this transport mode is chosen, character conversion will not be performed. If the payload contains text data, it will be sent in its original encoding.
-
OFF = 4;
Do not send the payload at all.
}
-
optional bool decode = 2 [default = false];
Decode the data (for instance, decompress it, decrypt it, etc). This is unrelated to character encoding.
-
optional uint32 sizeLimit = 3 [default = 1000000];
Even if other conditions are met, do not send the payload if it exceeds the specified amout (in bytes).
By default, only payloads under one megabyte are sent.
}
-
repeated MimeMode mimeModeList = 2;
Whenever a resource matches a mime type found in this list, the corresponding ContentMode is used for that resource.
-
repeated MimeMode multipartMimeModeList = 3;
Whenever an individual part of a multipart/form-data matches a type found in this list, the corresponding ContentMode is used for that part.
}
returns (Default)
= 4;
Choose how (and if) response data should be reported. It's possible to set a filter with different settings based on MIME type.
command SetResponseMode(SetResponseModeArg)
returns (Default)
= 3;
Fired when a request is created.
event OnRequest returns (Request)
= 14;
Fired after the entire request (including payload, if any) has been sent.
event OnRequestFinished returns (RequestFinished)
{
-
required uint32 requestID = 1;
-
required uint32 resourceID = 2;
-
required double time = 3;
Milliseconds since Unix epoch.
-
optional RequestData data = 4;
{
-
required uint32 requestID = 1;
-
required uint32 resourceID = 2;
-
optional string mimeType = 3;
-
optional string characterEncoding = 4;
The character encoding of the payload. Not applicable when the payload is of a non-text type.
Example: utf-8
-
optional uint32 contentLength = 5;
-
optional Content content = 6;
{
-
optional uint32 length = 1;
If BYTES or DATA_URI was chosen as the transport mode, this field contains the size of the data. (If, in addition, decoding was enabled, the field contains the size of the decoded data).
If STRING was chosen as the transport mode, this field contains the string length (regardless of encoding), i.e. the number of characters, not including zero terminator.
-
optional string characterEncoding = 2;
The (original) character encoding of the data (if applicable).
-
optional bytes byteData = 3;
This field contains the data if BYTES was chosen as the transport mode. If other modes were chosen, this field is not set.
@see ContentMode::Transport
-
optional string stringData = 4;
This field contains the data if either STRING or DATA_URI were chosen as transport mode. If some other mode was chosen, this field is not set.
@see ContentMode::Transport
}
-
repeated Part partList = 7;
If the payload is multipart, this list contains the individual parts.
}
}
= 16;
Fired after the request headers are composed.
{
-
-
-
Milliseconds since Unix epoch.
-
-
{
-
The name of the HTTP header, for instance "Accept-Charset".
-
The value of the HTTP header, for instance "utf-8" when using Accept-Charset, or "text/html; charset=utf8" for Content-Type.
}
}
If pipelining is enabled, a request can sometimes be moved to another connection if the previous connection failed, for some reason.
In these cases, this event will fire to indicate that we are retrying the same request under a new requestID.
event OnRequestRetry returns (RequestRetry)
= 17;
Fired when data is first received from the server, before any headers are parsed.
event OnResponse returns (Response)
= 18;
Fired when the the client stops listening for a response, for example because the entire response (including payload) has been downloaded or the request has been aborted.
event OnResponseFinished returns (ResponseFinished)
{
-
required uint32 requestID = 1;
-
required uint32 resourceID = 2;
-
required double time = 3;
Milliseconds since Unix epoch.
-
required uint32 contentLength = 4;
-
optional ResourceData data = 5;
{
-
required uint32 resourceID = 1;
-
required string url = 2;
-
optional string mimeType = 3;
The used mime type. This may be different from the mime type advertised in the HTTP headers.
-
optional string characterEncoding = 4;
Original character encoding (if applicable).
-
optional uint32 contentLength = 5;
Content-Length, as advertised by HTTP headers.
-
optional Content content = 6;
{
-
optional uint32 length = 1;
If BYTES or DATA_URI was chosen as the transport mode, this field contains the size of the data. (If, in addition, decoding was enabled, the field contains the size of the decoded data).
If STRING was chosen as the transport mode, this field contains the string length (regardless of encoding), i.e. the number of characters, not including zero terminator.
-
optional string characterEncoding = 2;
The (original) character encoding of the data (if applicable).
-
optional bytes byteData = 3;
This field contains the data if BYTES was chosen as the transport mode. If other modes were chosen, this field is not set.
@see ContentMode::Transport
-
optional string stringData = 4;
This field contains the data if either STRING or DATA_URI were chosen as transport mode. If some other mode was chosen, this field is not set.
@see ContentMode::Transport
}
}
}
= 20;
Fired when headers are received and parsed.
{
-
-
-
Milliseconds since Unix epoch.
-
-
{
-
The name of the HTTP header, for instance "Accept-Charset".
-
The value of the HTTP header, for instance "utf-8" when using Accept-Charset, or "text/html; charset=utf8" for Content-Type.
}
}
Resource was completely loaded or failed.
No request events should happen after this point.
event OnUrlFinished returns (UrlFinished)
= 11;
A resource was requested by the browser.
Depending on the protocol used it may result in OnRequest/OnResponse events. When resource is loaded OnUrlFinished is sent.
event OnUrlLoad returns (UrlLoad)
= 10;
Sent when a URL is redirect to another URL. Contains both the original resource ID and the new resource ID.
event OnUrlRedirect returns (UrlRedirect)
= 12;
The specified URL and resource ID is no longer in use in the browser. Any references to them should be removed.
Trying to use the resource ID after this event will not work.
event OnUrlUnload returns (UrlUnload)
= 13;