how to get http_only cookies

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

how to get http_only cookies

Postby ZMer2019 » Thu Jul 09, 2020 11:05 pm

In cefclient, I want to get a cookie of type http_only, but I found that there is no cookie of this type, what should I do?
here is my code:
Code: Select all
class CCookieVisitor: public CefCookieVisitor{
    public:
        CCookieVisitor(){}
        ~CCookieVisitor(){}
        static int sum ;
        bool Visit(const CefCookie& cookie, int count, int total, bool &deleteCookie)override {
           
            if(cookie.name.str && cookie.value.str){
                CefString name = cookie.name.str;
                CefString value = cookie.value.str;
                LOG(INFO)<<count<<" of "<<total<<" ||| "<< name.ToString() <<":" << value.ToString()<<"\n";
            }
            return true;
        }
    IMPLEMENT_REFCOUNTING(CCookieVisitor);
    };

bool ClientHandler::OnProcessMessageReceived(
            CefRefPtr<CefBrowser> browser,
            CefRefPtr<CefFrame> frame,
            CefProcessId source_process,
            CefRefPtr<CefProcessMessage> message) {
        CEF_REQUIRE_UI_THREAD();
        //edward
        LOG(INFO)<< "=========OnProcessMessageReceived\n";
        //LOG(INFO)<< request->GetURL().c_str();
        CefRefPtr<CefCookieManager> manager = CefCookieManager::GetGlobalManager(nullptr);
        CefRefPtr<CCookieVisitor> visitor = new CCookieVisitor();
        manager->VisitAllCookies(visitor);
        if (message_router_->OnProcessMessageReceived(browser, frame, source_process,
                                                      message)) {
            return true;
        }

        // Check for messages from the client renderer.
        std::string message_name = message->GetName();
        if (message_name == kFocusedNodeChangedMessage) {
            // A message is sent from ClientRenderDelegate to tell us whether the
            // currently focused DOM node is editable. Use of |focus_on_editable_field_|
            // is redundant with CefKeyEvent.focus_on_editable_field in OnPreKeyEvent
            // but is useful for demonstration purposes.
            focus_on_editable_field_ = message->GetArgumentList()->GetBool(0);
            return true;
        }

        return false;
    }
ZMer2019
Newbie
 
Posts: 1
Joined: Thu Jul 09, 2020 10:54 pm

Re: how to get http_only cookies

Postby magreenblatt » Fri Jul 10, 2020 10:58 am

CefCookie has an |httponly| member that you can check, and CefCookieManager::VisitUrlCookies has an |includeHttpOnly| parameter.
magreenblatt
Site Admin
 
Posts: 12383
Joined: Fri May 29, 2009 6:57 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 37 guests