Note: this only show when i create cefUrlRequestClient, ResourceHandler, and set header in GetResponseHeaders callback function
- Code: Select all
cef_return_value_t ResourceRequest::OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
CefRefPtr<CefRequest> request,
CefRefPtr<CefRequestCallback> callback) {
CEF_REQUIRE_IO_THREAD();
request->SetFlags(UR_FLAG_STOP_ON_REDIRECT | UR_FLAG_ALLOW_STORED_CREDENTIALS);
CefRefPtr<UrlRequestClient> client = new UrlRequestClient(callback, this);
auto _ = CefURLRequest::Create(request, client, nullptr);
return RV_CONTINUE_ASYNC;
}
void ResourceHandler::GetResponseHeaders(CefRefPtr<CefResponse> response, int64 & response_length, CefString & redirectUrl) {
response_length = resource_request_->download_data_.length();
CefRefPtr<CefResponse> & resp = resource_request_->response_;
CefResponse::HeaderMap headermap;
resp->GetHeaderMap(headermap);
response->SetHeaderMap(headermap);
response->SetStatus(resp->GetStatus());
response->SetStatusText(resp->GetStatusText());
response->SetCharset(resp->GetCharset());
response->SetMimeType(resp->GetMimeType());
response->SetURL(resp->GetURL());
auto found = headermap.find("Location");
if (found != headermap.end()) {
// warn: when write to this, devtool will show status code 307.
// redirectUrl = (*found).second;
return void();
}
response->SetError(resp->GetError());
};
I write a server to watch header info in the cefurlrequest, here is the server output
- Code: Select all
Sec-Fetch-User: ?1
Accept-Language: zh-CN,zh;q=0.9
Accept-Encoding: gzip, deflate, br
Sec-Fetch-Site: none
Connection: keep-alive
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Upgrade-Insecure-Requests: 1
Host: localhost:8888
Cookie: redirect=found
Sec-Fetch-Mode: no-cors
If-None-Match: "90f43fb22c73207e600d7122bd85ff095ea8f07d"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
i think the cefurlrequest header is ok, but the devtools request header shows: Provisional headers are shown
How to make devtools request headers show correct ?