3

My goal is it to identify the TCP-Connections in a firefox-plugin.

For that I need to set a unique ID to every connection. My question is, if its possible and someone knows how to get access to the Object of the TCP-Connection from a HTTP-Request? Then I could set a unique ID to it and every request/response pair would be uniquely set to a connection.

August Lilleaas
  • 54,010
  • 13
  • 102
  • 111

4 Answers4

1

While I don't know the direct answer to your question, I would suggest taking a look at the source code for Firebug, it seems to have access to at least the HTTP request level of the network stack, maybe even lower.

Hope this helps, good luck!

Chris Cherry
  • 28,118
  • 6
  • 68
  • 71
  • Thanks, but Firebug only shows information about the request/response pair (all headers) but no information about the connection on which it runs. – Michael Gomringer Oct 24 '11 at 17:58
0

Assuming that you are talking about client side javascript, there are some projects which will help you to achieve this functionality.

  1. http://code.google.com/p/jssockets/ [flash is required]
  2. http://socket.io/

Hope it helps.

Hasin Hayder
  • 818
  • 7
  • 8
0

From MDN: How to monitor HTTP activity

Here's their sample code

// Define a reference to the interface
var nsIHttpActivityObserver = Components.interfaces.nsIHttpActivityObserver;

var httpObserver =
{
    observeActivity: function(aHttpChannel, aActivityType, aActivitySubtype, aTimestamp, aExtraSizeData, aExtraStringData)
    {
      if (aActivityType == nsIHttpActivityObserver.ACTIVITY_TYPE_HTTP_TRANSACTION) {
        switch(aActivitySubtype) {
          case nsIHttpActivityObserver.ACTIVITY_SUBTYPE_RESPONSE_HEADER:
            // received response header
            break;
          case nsIHttpActivityObserver.ACTIVITY_SUBTYPE_RESPONSE_COMPLETE:
            // received complete HTTP response
            break;
        }
      }
    }
};

var activityDistributor = 
    Components.classes["@mozilla.org/network/http-activity-distributor;1"]
    .getService(Components.interfaces.nsIHttpActivityDistributor);
activityDistributor.addObserver(httpObserver);
Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
  • I'm working with the Firefox-Extension HttpFox and I have such a kind of this code already.
    But what is missing is the information about the tcp-connection.
    I can see the headers "keep-alive" and "connection" but no mapping to a connection itself.
    – Michael Gomringer Oct 24 '11 at 18:03
0

I do something very similar in my own ff addon. I'm assuming that you want a reference to the nsiHttpChannel associated with the connection. However, I'm not sure you can just add properties to it (and have them persist), since its probably backed by native code, I'm not sure either way. But you can store the nsiHttpChannel elsewhere and keep an id on it that way.

Here's some simplified code that I use to monitor http traffic in my addon, which should solve your problem.

var Cc = Components.classes;
var Ci = Components.interfaces;

var MyHttpObserver = {
    // must be exposed so that the ObserverService can register itself
    observe: function(subject, topic, data) {
        subject.QueryInterface(Ci.nsIHttpChannel);
        if( topic === "http-on-modify-request" ){
            // store 'subject' somewhere
        } else if( topic === "http-on-examine-response" ){
            // look up 'subject' it will be the same reference as before
        }
    },

    register: function() {
        var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
        observerService.addObserver(this, "http-on-modify-request", false);
        observerService.addObserver(this, "http-on-examine-response", false);
    },

    unregister: function() {
        var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
        observerService.removeObserver(this, "http-on-modify-request");
        observerService.removeObserver(this, "http-on-examine-response");
    },

    QueryInterface: function (aIID) {
        if (aIID.equals(Ci.nsIObserver) || aIID.equals(Ci.nsISupports) ){
            return this;
        }
        throw Components.results.NS_NOINTERFACE;
    }
};
skabbes
  • 890
  • 7
  • 17
  • Looks good but this answer is also restricted to the http-request/response and delivers no info about the tcp-connection. Thanks anyway! – Michael Gomringer Oct 26 '11 at 08:20
  • I guess I don't understand the question, maybe you could rephrase it? What sort of info do you need? The closest thing to a "tcp connection" that I know of is an [nsiHttpChannel](https://developer.mozilla.org/en/XPCOM_Interface_Reference/nsIHttpChannel). – skabbes Oct 26 '11 at 19:54