Cannot intercept HTTP response (ARM64)

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.

Cannot intercept HTTP response (ARM64)

Postby dmklementiev » Mon Sep 02, 2019 7:20 pm

Hi All,

I am trying to intercept HTTP response and cannot make it working. I've searched this forum and googled my question, tried several things, but nothing seemed to work. I've added the following code to cefsimple:

Code: Select all
class  MyResourceHandler : public CefResourceHandler
{
public:
    bool ProcessRequest(CefRefPtr<CefRequest> request, CefRefPtr<CefCallback> callback)
    {
        std::cout << "ProcessRequest is called" << std::endl;
        callback->Continue();
        return true;
    }

    void GetResponseHeaders(CefRefPtr<CefResponse> response, int64& response_length, CefString& redirectUrl)
    {
        std::cout << "GetResponseHeaders is called" << std::endl;
        response->SetStatus(200);
        response_length = -1;
    }

    bool ReadResponse(void* data_out,int bytes_to_read,int& bytes_read,CefRefPtr<CefCallback> callback)
    {
        std::cout << "ReadResponse is called" << std::endl;
        return true;
    }

    void Cancel(){}

    private:
        IMPLEMENT_REFCOUNTING(MyResourceHandler);
};

class MyHandler : public CefClient, public CefRequestHandler, public CefResourceRequestHandler
{
    CefRefPtr<CefRequestHandler> GetRequestHandler()
    {
        std::cout << "GetRequestHandler is called" << std::endl;
        return this;
    }

    CefRefPtr<CefResourceHandler> GetResourceHandler(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request)
    {
        std::cout << "GetResourceHandler is called" << std::endl;
        return new MyResourceHandler();
    }

private:
    IMPLEMENT_REFCOUNTING(MyHandler);
};


and replaced CefRefPtr<SimpleHandler> handler(new SimpleHandler(use_views)) with CefRefPtr<MyHandler> handler(new MyHandler) in simpleapp. I am getting "GetRequestHandler is called" but no messages related to resources. What am I doing wrong?
dmklementiev
Mentor
 
Posts: 54
Joined: Wed Jul 31, 2019 7:11 pm

Re: Cannot intercept HTTP response (ARM64)

Postby Czarek » Tue Sep 03, 2019 12:58 am

When you implement CefResourceHandler you are responsible for making an actual request, you can i.e. use CefURLRequest for that. You have to read carefully all the comments in cef_resource_handler.h file. An example implementation in Python can be found here: https://github.com/cztomczak/cefpython/ ... se.py#L122
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Cannot intercept HTTP response (ARM64)

Postby dmklementiev » Tue Sep 03, 2019 12:43 pm

Thank you Czarek for helping me again : ) Am I correct that when you are saying:
When you implement CefResourceHandler you are responsible for making an actual request

it corresponds to the following code in your sample:

Code: Select all
def ProcessRequest(self, request, callback):
        print("ProcessRequest()")
        # 1. Start the request using WebRequest
        # 2. Return True to handle the request
        # 3. Once response headers are ready call
        #    callback.Continue()
        .....

        self._webRequest = cefpython.WebRequest.Create(
                request, self._webRequestClient)
        return True


In my case I am not even getting to ProcessRequest - not seeing "ProcessRequest is called" (cout in my example). Also my understanding is that in order to enable handler of "class MyResourceHandler : public CefResourceHandler" (in my case), MyHandler::GetResourceHandler has to be called, but then again - I don't see "GetResourceHandler is called" in cout.
dmklementiev
Mentor
 
Posts: 54
Joined: Wed Jul 31, 2019 7:11 pm

Re: Cannot intercept HTTP response (ARM64)

Postby magreenblatt » Tue Sep 03, 2019 12:51 pm

Did you implement CefRequestHandler::GetResourceRequestHandler or CefRequestContextHandler::GetResourceRequestHandler (if you're using a request context)? You're also not specifying 'override' on your virtual methods, so the signatures might be wrong.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Cannot intercept HTTP response (ARM64)

Postby dmklementiev » Tue Sep 03, 2019 1:16 pm

Yes I implemented CefRequestHandler::GetResourceRequestHandler as follows:

Code: Select all
class MyHandler : public CefClient, public CefRequestHandler, public CefResourceRequestHandler
{
    CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE
    {
        std::cout << "GetRequestHandler is called" << std::endl;
        return this;
    }

    CefRefPtr<CefResourceHandler> GetResourceHandler(CefRefPtr<CefBrowser> browser, CefRefPtr<CefFrame> frame, CefRefPtr<CefRequest> request) OVERRIDE
    {
        std::cout << "GetResourceHandler is called" << std::endl;
        return new MyResourceHandler();
    }


added overrides, however, this didn't change the behavior. Interestingly I see "GetRequestHandler is called", but not "GetResourceHandler is called"
dmklementiev
Mentor
 
Posts: 54
Joined: Wed Jul 31, 2019 7:11 pm

Re: Cannot intercept HTTP response (ARM64)

Postby magreenblatt » Tue Sep 03, 2019 1:29 pm

I don’t see a GetResourceRequestHandler method in your example?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: Cannot intercept HTTP response (ARM64)

Postby dmklementiev » Tue Sep 03, 2019 1:55 pm

One of those wonderful moments when you feel totally stupid for missing obvious part and happy that everything works : ) Thank you Marshall and Czarek!
dmklementiev
Mentor
 
Posts: 54
Joined: Wed Jul 31, 2019 7:11 pm


Return to Support Forum

Who is online

Users browsing this forum: No registered users and 46 guests