Request - rentouch/cefpython GitHub Wiki

Request class

Object of this class is used in RequestHandler.OnBeforeBrowse() and RequestHandler.OnBeforeResourceLoad().

CEF 3

static Request CreateRequest()

You cannot instantiate Request class directly, use this static method instead by calling cefpython.Request.CreateRequest().

bool IsReadOnly()

Returns true if this object is read-only.

str GetUrl()

Get the fully qualified url.

void SetUrl(string url)

Set the fully qualified url.

str GetMethod()

Get the request method type. The value will default to POST if post data is provided and GET otherwise.

void SetMethod(string method)

Set the request method type.

list|dict GetPostData()

Get the post data. If the form content type is "multipart/form-data" then the post data will be returned as a list. If the form content type is "application/x-www-form-urlencoded" then the post data will be returned as a dict.

void SetPostData(list|dict postData)

Set the post data. See GetPostData() for an explanation of the postData type.

dict GetHeaderMap()

Get all header fields with duplicate keys overwritten by last.

list GetHeaderMultimap()

Get all header fields. Returns list of tuples (name, value). Headers may have duplicate keys, if you want to ignore duplicates use GetHeaderMap().

void SetHeaderMap(dict headerMap)

Set all header fields.

void SetHeaderMultimap(list headerMultimap)

Set all header fields. headerMultimap must be a list of tuples (name, value).

int GetFlags()

Get the flags used in combination with WebRequest.

Available flags (access via cefpython.Request.Flags["xxx"]):

  • None - Default behavior.
  • SkipCache - If set the cache will be skipped when handling the request.
  • AllowCachedCredentials - If set user name, password, and cookies may be sent with the request.
  • AllowCookies - If set cookies may be sent with the request and saved from the response. AllowCachedCredentials must also be set.
  • ReportUploadProgress - If set upload progress events will be generated when a request has a body.
  • ReportLoadTiming - If set load timing info will be collected for the request.
  • ReportRawHeaders - If set the headers sent and received for the request will be recorded.
  • NoDownloadData - If set the WebRequestClient::OnDownloadData method will not be called.
  • NoRetryOn5xx - If set 5xx redirect errors will be propagated to the observer instead of automatically re-tried. This currently only applies for requests originated in the browser process.

void SetFlags(int flags)

Set the flags used in combination with WebRequest.

str GetFirstPartyForCookies()

Get the url to the first party for cookies used in combination with
WebRequest.

void SetFirstPartyForCookies(string url)

Set the url to the first party for cookies used in combination with
WebRequest.

int GetResourceType()

Not yet implemented in CEF Python.
Get the resource type for this request. Accurate resource type information may only be available in the browser process.
  // Top level page.
RT_MAIN_FRAME
// Frame or iframe.
RT_SUB_FRAME,
// CSS stylesheet.
RT_STYLESHEET,
// External script.
RT_SCRIPT,
// Image (jpg/gif/png/etc).
RT_IMAGE,
// Font.
RT_FONT_RESOURCE,
// Some other subresource. This is the default type if the actual type is unknown.
RT_SUB_RESOURCE,
// Object (or embed) tag for a plugin, or a resource that a plugin requested.
RT_OBJECT,
// Media resource.
RT_MEDIA,
// Main resource of a dedicated worker.
RT_WORKER,
// Main resource of a shared worker.
RT_SHARED_WORKER,
// Explicitly requested prefetch.
RT_PREFETCH,
// Favicon.
RT_FAVICON,
// XMLHttpRequest.
RT_XHR,

int GetTransitionType()

Not yet implemented in CEF Python.
Get the transition type for this request. Only available in the browser
process and only applies to requests that represent a main frame or
sub-frame navigation.
///
// Transition type for a request. Made up of one source value and 0 or more
// qualifiers.
///
enum cef_transition_type_t {
///
// Source is a link click or the JavaScript window.open function. This is
// also the default value for requests like sub-resource loads that are not
// navigations.
///
TT_LINK = 0,

///
// Source is some other "explicit" navigation action such as creating a new
// browser or using the LoadURL function. This is also the default value
// for navigations where the actual type is unknown.
///
TT_EXPLICIT = 1,

///
// Source is a subframe navigation. This is any content that is automatically
// loaded in a non-toplevel frame. For example, if a page consists of several
// frames containing ads, those ad URLs will have this transition type.
// The user may not even realize the content in these pages is a separate
// frame, so may not care about the URL.
///
TT_AUTO_SUBFRAME = 3,

///
// Source is a subframe navigation explicitly requested by the user that will
// generate new navigation entries in the back/forward list. These are
// probably more important than frames that were automatically loaded in
// the background because the user probably cares about the fact that this
// link was loaded.
///
TT_MANUAL_SUBFRAME = 4,

///
// Source is a form submission by the user. NOTE: In some situations
// submitting a form does not result in this transition type. This can happen
// if the form uses a script to submit the contents.
///
TT_FORM_SUBMIT = 7,

///
// Source is a "reload" of the page via the Reload function or by re-visiting
// the same URL. NOTE: This is distinct from the concept of whether a
// particular load uses "reload semantics" (i.e. bypasses cached data).
///
TT_RELOAD = 8,

///
// General mask defining the bits used for the source values.
///
TT_SOURCE_MASK = 0xFF,

// Qualifiers.
// Any of the core values above can be augmented by one or more qualifiers.
// These qualifiers further define the transition.

///
// Attempted to visit a URL but was blocked.
///
TT_BLOCKED_FLAG = 0x00800000,

///
// Used the Forward or Back function to navigate among browsing history.
///
TT_FORWARD_BACK_FLAG = 0x01000000,

///
// The beginning of a navigation chain.
///
TT_CHAIN_START_FLAG = 0x10000000,

///
// The last transition in a redirect chain.
///
TT_CHAIN_END_FLAG = 0x20000000,

///
// Redirects caused by JavaScript or a meta refresh tag on the page.
///
TT_CLIENT_REDIRECT_FLAG = 0x40000000,

///
// Redirects sent from the server by HTTP headers.
///
TT_SERVER_REDIRECT_FLAG = 0x80000000,

///
// Used to test whether a transition involves a redirect.
///
TT_IS_REDIRECT_MASK = 0xC0000000,

///
// General mask defining the bits used for the qualifiers.
///
TT_QUALIFIER_MASK = 0xFFFFFF00,
};

CEF 1

static Request CreateRequest()

You cannot instantiate Request class directly, use this static method
instead by calling cefpython.Request.CreateRequest().

str GetUrl()

Get the fully qualified url.

void SetUrl(string url)

Set the fully qualified url.

str GetMethod()

Get the request method type. The value will default to POST
if post data is provided and GET otherwise.

void SetMethod(string method)

Set the request method type.

list|dict GetPostData()

Get the post data. If the form content type is "multipart/form-data"
then the post data will be returned as a list. If the form content
type is "application/x-www-form-urlencoded" then the post data will
be returned as a dict.

void SetPostData(list|dict postData)

Set the post data. See GetPostData() for an explanation of the
postData type.

dict GetHeaderMap()

Get all header fields with duplicate keys overwritten by last.

list GetHeaderMultimap()

Get all header fields. Returns list of tuples (name, value). Headers may have duplicate keys, if you want to ignore duplicates use GetHeaderMap().

void SetHeaderMap(dict headerMap)

Set all header fields.

void SetHeaderMultimap(list headerMultimap)

Set all header fields. headerMultimap must be a list of tuples (name, value).

int GetFlags()

Get the flags used in combination with WebRequest.
Available flags (access via cefpython.Request.Flags["xxx"]):
None
SkipCache
AllowCachedCredentials
AllowCookies
ReportUploadProgress
ReportLoadTiming
ReportRawHeaders

void SetFlags(int flags)

Set the flags used in combination with WebRequest.

str GetFirstPartyForCookies()

Get the url to the first party for cookies used in combination with
WebRequest.

void SetFirstPartyForCookies(string url)

Set the url to the first party for cookies used in combination with
WebRequest.
⚠️ **GitHub.com Fallback** ⚠️