intercepting http and opening sockets? - Mozilla

This is a discussion on intercepting http and opening sockets? - Mozilla ; Hi. I'm a (complete) newbie to Firefox extension development, and there are a number of items I would like to accomplish. I've been digging through some of the docs, and I haven't found any clear description that would tell me ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: intercepting http and opening sockets?

  1. intercepting http and opening sockets?

    Hi.

    I'm a (complete) newbie to Firefox extension development, and there are
    a number of items I would like to accomplish. I've been digging through
    some of the docs, and I haven't found any clear description that would
    tell me how to do some of this stuff. Here's what I'd like to be able
    to do:

    - Whenever an HTTP request is made, I'd like to intercept this and
    based on a condition I check, either:
    - let the request proceed as is
    - redirect the request to another ip address/port.

    - If I redirected the request, I would like to intercept the data
    that's returned (i.e., the HTTP response) do some minor processing on
    it, and then let the data be fed back to Firefox in such a way that it
    appears that this is the return data coming from the original request.

    - I would also like to be able to open a server socket. Is this going
    to require a native (C++) component, or is it doable from within
    javascript with XPCOM/XPConnect?

    - Finally, I would like to be able to look up content in the cache and
    be able to serve this to anyone who connects to my server socket and
    makes an appropriate request.

    - Related to this, when does content become available in the
    cache? Is it after a request has completed, or can "partial" data be
    read from the cache while the request is still in progress? (For
    example: If I request http://mycompany.com/large_data_set, will the
    data become accessible in the cache as the data streams back, or only
    once the entire response is finished?)

    How difficult is this stuff to do with Firefox extensions? Can anyone
    point me to any good tutorials that may help me get started?

    Thanks.


  2. Re: intercepting http and opening sockets?

    Has anyone found any way of dealing with the first item in the original
    message below? I'm trying to do something similar - I need to intercept
    an HTTP request before it leaves the browser and possibly change the URL
    depending on a condition, but have the response be returned as the
    response to the original requesting page/XHR. I'd prefer to be able to
    do it in Javascript, if possible.

    One solution I've found is to programmatically create a new handler
    whose methods are all just copies of the originals, then register that
    handler with the HTTP contract ID using the nsIComponentRegistrar
    interface's registerFactory method (see
    http://blues.ath.cx/firekeeper/resou...tp_tracer.html for an
    example). The problem with this technique, as noted on
    http://blues.ath.cx/firekeeper/archi...2T21_55_39.txt,
    is that "there is an addition[al] security check when component code is
    written in JavaScript. It checks out if JavaScript version of HTTP
    handler can be accessed from the context of a web page that performed
    XMLHttpRequest." This causes all sorts of problems, including complete
    incapacitation of the XHR object and problems with manipulating the
    location object. Does anyone know of any way around this problem?

    Thanks,
    Jesse

    Venqin wrote:
    > Hi.
    >
    > I'm a (complete) newbie to Firefox extension development, and there are
    > a number of items I would like to accomplish. I've been digging through
    > some of the docs, and I haven't found any clear description that would
    > tell me how to do some of this stuff. Here's what I'd like to be able
    > to do:
    >
    > - Whenever an HTTP request is made, I'd like to intercept this and
    > based on a condition I check, either:
    > - let the request proceed as is
    > - redirect the request to another ip address/port.
    >
    > - If I redirected the request, I would like to intercept the data
    > that's returned (i.e., the HTTP response) do some minor processing on
    > it, and then let the data be fed back to Firefox in such a way that it
    > appears that this is the return data coming from the original request.
    >
    > - I would also like to be able to open a server socket. Is this going
    > to require a native (C++) component, or is it doable from within
    > javascript with XPCOM/XPConnect?
    >
    > - Finally, I would like to be able to look up content in the cache and
    > be able to serve this to anyone who connects to my server socket and
    > makes an appropriate request.
    >
    > - Related to this, when does content become available in the
    > cache? Is it after a request has completed, or can "partial" data be
    > read from the cache while the request is still in progress? (For
    > example: If I request http://mycompany.com/large_data_set, will the
    > data become accessible in the cache as the data streams back, or only
    > once the entire response is finished?)
    >
    > How difficult is this stuff to do with Firefox extensions? Can anyone
    > point me to any good tutorials that may help me get started?
    >
    > Thanks.
    >


  3. Re: intercepting http and opening sockets?

    Has anyone found any way of dealing with the first item in the original
    message below? I'm trying to do something similar - I need to intercept
    an HTTP request before it leaves the browser and possibly change the URL
    depending on a condition, but have the response be returned as the
    response to the original requesting page/XHR. I'd prefer to be able to
    do it in Javascript, if possible.

    One solution I've found is to programmatically create a new handler
    whose methods are all just copies of the originals, then register that
    handler with the HTTP contract ID using the nsIComponentRegistrar
    interface's registerFactory method (see
    http://blues.ath.cx/firekeeper/resou...tp_tracer.html for an
    example). The problem with this technique, as noted on
    http://blues.ath.cx/firekeeper/archi...2T21_55_39.txt,
    is that "there is an addition[al] security check when component code is
    written in JavaScript. It checks out if JavaScript version of HTTP
    handler can be accessed from the context of a web page that performed
    XMLHttpRequest." This causes all sorts of problems, including complete
    incapacitation of the XHR object and problems with manipulating the
    location object. Does anyone know of any way around this problem?

    Thanks,
    Jesse

    Venqin wrote:
    > Hi.
    >
    > I'm a (complete) newbie to Firefox extension development, and there are
    > a number of items I would like to accomplish. I've been digging through
    > some of the docs, and I haven't found any clear description that would
    > tell me how to do some of this stuff. Here's what I'd like to be able
    > to do:
    >
    > - Whenever an HTTP request is made, I'd like to intercept this and
    > based on a condition I check, either:
    > - let the request proceed as is
    > - redirect the request to another ip address/port.
    >
    > - If I redirected the request, I would like to intercept the data
    > that's returned (i.e., the HTTP response) do some minor processing on
    > it, and then let the data be fed back to Firefox in such a way that it
    > appears that this is the return data coming from the original request.
    >
    > - I would also like to be able to open a server socket. Is this going
    > to require a native (C++) component, or is it doable from within
    > javascript with XPCOM/XPConnect?
    >
    > - Finally, I would like to be able to look up content in the cache and
    > be able to serve this to anyone who connects to my server socket and
    > makes an appropriate request.
    >
    > - Related to this, when does content become available in the
    > cache? Is it after a request has completed, or can "partial" data be
    > read from the cache while the request is still in progress? (For
    > example: If I request http://mycompany.com/large_data_set, will the
    > data become accessible in the cache as the data streams back, or only
    > once the entire response is finished?)
    >
    > How difficult is this stuff to do with Firefox extensions? Can anyone
    > point me to any good tutorials that may help me get started?
    >
    > Thanks.
    >


  4. Re: intercepting http and opening sockets?

    Jesse D wrote:
    > Has anyone found any way of dealing with the first item in the original
    > message below? I'm trying to do something similar - I need to intercept
    > an HTTP request before it leaves the browser and possibly change the URL
    > depending on a condition, but have the response be returned as the
    > response to the original requesting page/XHR. I'd prefer to be able to
    > do it in Javascript, if possible.
    >

    ....
    >>
    >> - Whenever an HTTP request is made, I'd like to intercept this and
    >> based on a condition I check, either:
    >> - let the request proceed as is
    >> - redirect the request to another ip address/port.
    >>


    This is the work of a proxy server, that is a network component designed
    to intercept HTTP traffic and do the kinds of modifications you
    describe. There is a Javascript HTTP server, it may have proxy ability.

    John.

  5. Re: intercepting http and opening sockets?


    Venqin wrote:
    [snip]
    > - I would also like to be able to open a server socket. Is this going
    > to require a native (C++) component, or is it doable from within
    > javascript with XPCOM/XPConnect?


    I'm interested as to whether there's any solution for this one. I want
    to write an extension that will open a port in localhost (not exposed
    to public) for testing. For example, I can type http://localhost:2345
    on Firefox address bar and the extension will pop out and I can then
    specify the response to the HTTP request.

    Thanks for the help!

    Chris

+ Reply to Thread