CefResponse
Header: cef_response.h
Category: Core APIs
Overview
Foundational interfaces: process bootstrap, browser lifecycle, frames, DOM, requests, and data objects.
CefResponse
Source File: include/cef_response.h
Process / Thread Context: Any thread (per class comment: "The methods of this class may be called on any thread.")
Purpose: USER-CALLED library interface representing an HTTP-style response. Used by scheme handlers, CefResourceHandler, and CefURLRequest callbacks to inspect or build responses.
Methods
static CefRefPtr<CefResponse> Create()
Return Value: Creates a new mutable response. Call on any thread.
Threading Constraint: Threading constraint not specified in source.
bool IsReadOnly()
Return Value: True if object is read-only (e.g., supplied to a callback that disallows mutation).
Threading Constraint: Threading constraint not specified in source.
cef_errorcode_t GetError()
Return Value: Returns ERR_NONE if no error. Defaults to ERR_NONE.
Threading Constraint: Threading constraint not specified in source.
void SetError(cef_errorcode_t error)
Return Value: Set error code. Custom scheme handlers use this to return errors during initial processing.
Threading Constraint: Threading constraint not specified in source.
CefString GetHeaderByName(const CefString& name)
Return Value: First value for name or empty if not found.
Threading Constraint: Threading constraint not specified in source.
void SetHeaderByName(const CefString& name, const CefString& value, bool overwrite)
Return Value: Set header. If overwrite is true, replaces existing values; otherwise appends.
Threading Constraint: Threading constraint not specified in source.
void GetHeaderMap(HeaderMap& headerMap)
Return Value: Get all headers as multimap.
Threading Constraint: Threading constraint not specified in source.
void SetHeaderMap(const HeaderMap& headerMap)
Return Value: Replace all headers.
Threading Constraint: Threading constraint not specified in source.
Usage Example
// CefResourceHandler::GetResponseHeaders — populate a CefResponse:
void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64_t& response_length,
CefString& redirectUrl) override {
response->SetStatus(200);
response->SetStatusText("OK");
response->SetMimeType("application/json");
response->SetCharset("utf-8");
response->SetHeaderByName("Cache-Control", "no-store", true);
response_length = body_.size();
}
// CefURLRequestClient::OnResponseHeaderReceived — read a CefResponse:
void OnResponseHeaderReceived(CefRefPtr<CefURLRequest> request,
CefRefPtr<CefResponse> response) override {
int status = response->GetStatus();
CefString mime = response->GetMimeType();
if (response->IsReadOnly()) { /* cannot mutate */ }
}