2010-10-06 13 views
3

如何在使用HTTP觀察者時將傳入響應映射到傳出請求:https://developer.mozilla.org/en/Setting_HTTP_request_headers#Observers如何在使用「http-on-modify-request」和「http-on-examine-response」時映射對請求的響應?

+1

只是存儲在陣列中的請求,因爲他們走出去,然後用的indexOf找出哪個是哪個?我想這就是HttpFox所做的。 – MatrixFrog 2010-10-06 15:52:20

+0

調查HttpFox源代碼:http://code.google.com/p/httpfox/source/browse/trunk/components/HttpFoxService.js感謝您指出! – spektom 2010-10-06 16:20:15

回答

1

比較nsIHttpChannel對象,如HttpFox作用:

getPendingRequestForRequestEvent: function(request) { 
    // check for matching request 
    for (var i = 0; i < this.Requests.length; i++) { 
     if (request.HttpChannel === this.Requests[i].HttpChannel) { 
     return i; 
     } 
    } 

    // no match found 
    return -1; 
},