Search code examples
clinuxhttpbrowsernpapi

How to get http response header in npapi plugin


i am new to plugin development. I was told to use Firebreath, for developing npapi plugins, and it turned out to be very easy. Now, i wish to access the http response header of the response passed on to plugin. But i couldn't figure out a way as their is scarce doc available for firebreath. In NPAPI tutorials, they use npstream, but i can't figure out how to use this structure in firebreath. Any help will be highly appreciated.

Update:

void tPlugin::handleUnsolicitedStream(FB::BrowserStreamRequest& req)
{ 
 const FB::PluginEventSinkPtr sinkPtr;
 req.setEventSink(sinkPtr);
 responseHeaders = req.headers;
 FB::HeaderMap::const_iterator it = responseHeaders.begin();
 str = (*it).first + " : " + (*it).second;                   // str is a class variable
 FB::DOM::WindowPtr window = m_host->getDOMWindow();
 window->alert(str);
 str = "hello";
 window->alert(fname);
}

None of the alert box appears!

void tPlugin::onPluginReady()
{
   FB::DOM::WindowPtr window = m_host->getDOMWindow();
   window->alert(str);
}

An empty alert box appears!


Solution

  • If you read the source for the BrowserStreamRequest object that you are using, or even better if you read the source for where it is created, you will find that there is a headers variable on the object.

    FB::HeaderMap headers;
    

    FB::HeaderMap, of course, is defined in SimpleStreamHelper.h:

    typedef std::multimap<std::string, std::string> HeaderMap;
    

    And, to clarify, there is plenty of documentation for FireBreath; just not a lot for this particular feature, which has only been in the tree for about a month.

    Edit: From past conversations I'm pretty sure you're already handling this, but the stream created by the browser is given to you with the BrowserStreamRequest object passed into the handleUnsolicitedStream method on your plugin object; this method isn't overridden by your plugin by default in the fbgen template, but you can add it.