lib/OptimizelyClient.js
function parseHttpHeaders(headers) {
    var meta = {};
    
    for (var headerName in headers) {
        var headerValue = headers[headerName];
        
        if (headerName=="x-ratelimit-limit") {
            meta.rateLimit = headerValue;
        } else if (headerName=="x-ratelimit-remaining") {
            meta.rateLimitRemaining = headerValue;
        } else if (headerName=="x-ratelimit-reset") {
            meta.rateLimitReset = headerValue;
        } else if (headerName=="link") {
            var regexp = /<(.+)>; rel=(.+),?/g;
            var match;
            do {
                match = regexp.exec(headerValue);
                if (match) {
                    var url = match[1];
                    var rel = match[2];
                    
                    var regexp2 = /[\?|&]page=(\d+)/;
                    var match2 = regexp2.exec(url);
                    if (match2) {
                        var page = match2[1];
                        if (rel=='prev') {
                            meta.prevPage = page;
                        } else if (rel=='next') {
                            meta.nextPage = page;
                        } else if (rel=='last') {
                            meta.lastPage = page;
                        }
                    }
                }
            } while (match);
        } 
    }
    
    return meta;
}
function parseHttpHeaders(headers) {
    var meta = {};
    
    for (var headerName in headers) {
        var headerValue = headers[headerName];
        
        if (headerName=="x-ratelimit-limit") {
            meta.rateLimit = headerValue;
        } else if (headerName=="x-ratelimit-remaining") {
            meta.rateLimitRemaining = headerValue;
        } else if (headerName=="x-ratelimit-reset") {
            meta.rateLimitReset = headerValue;
        } else if (headerName=="link") {
            var regexp = /<(.+)>; rel=(.+),?/g;
            var match;
            do {
                match = regexp.exec(headerValue);
                if (match) {
                    var url = match[1];
                    var rel = match[2];
                    
                    var regexp2 = /[\?|&]page=(\d+)/;
                    var match2 = regexp2.exec(url);
                    if (match2) {
                        var page = match2[1];
                        if (rel=='prev') {
                            meta.prevPage = page;
                        } else if (rel=='next') {
                            meta.nextPage = page;
                        } else if (rel=='last') {
                            meta.lastPage = page;
                        }
                    }
                }
            } while (match);
        } 
    }
    
    return meta;
}
function parseHttpHeaders ( headers ) { var meta = { } ; for ( var headerName in headers ) { var headerValue = headers [ headerName ] ; if ( headerName == "x-ratelimit-limit" ) { meta . rateLimit = headerValue ; } else if ( headerName == "x-ratelimit-remaining" ) { meta . rateLimitRemaining = headerValue ; } else if ( headerName == "x-ratelimit-reset" ) { meta . rateLimitReset = headerValue ; } else if ( headerName == "link" ) { var regexp = / <(.+)>; rel=(.+),? / g ; var match ; do { match = regexp . exec ( headerValue ) ; if ( match ) { var url = match [ 1 ] ; var rel = match [ 2 ] ; var regexp2 = / [\?|&]page=(\d+) / ; var match2 = regexp2 . exec ( url ) ; if ( match2 ) { var page = match2 [ 1 ] ; if ( rel == 'prev' ) { meta . prevPage = page ; } else if ( rel == 'next' ) { meta . nextPage = page ; } else if ( rel == 'last' ) { meta . lastPage = page ; } } } } while ( match ) ; } } return meta ; }
Private function that retrieves meta information from HTTP headers.
Private function that retrieves meta information from HTTP headers .