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.

3
  • did you look at firebug? it's open source developer.mozilla.org/en/Firebug_internals Commented Oct 24, 2011 at 17:23
  • Good question; have an upvote. Commented Oct 24, 2011 at 17:23
  • could you rephrase this to include what types of information you need from the tcp connection object? Or better yet, explain your end goal. Commented Oct 26, 2011 at 19:57

4 Answers 4

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, but Firebug only shows information about the request/response pair (all headers) but no information about the connection on which it runs.
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.

Comments

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);

1 Comment

I'm working with the Firefox-Extension HttpFox and I have such a kind of this code already. <br>But what is missing is the information about the tcp-connection.<br>I can see the headers "keep-alive" and "connection" but no mapping to a connection itself.
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;
    }
};

2 Comments

Looks good but this answer is also restricted to the http-request/response and delivers no info about the tcp-connection. Thanks anyway!
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.