Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

We should have a RequestContextCache component. #15

Open
bgaillard opened this issue Mar 26, 2015 · 0 comments
Open

We should have a RequestContextCache component. #15

bgaillard opened this issue Mar 26, 2015 · 0 comments
Assignees
Milestone

Comments

@bgaillard
Copy link
Member

When a Request Manager starts it overwrites 3 methods of XMLHttpRequest 👍

  • XMLHttpRequest#open(method, url, async, username, password)
  • XMLHttpRequest#send(data)
  • XMLHttpRequest#setRequestHeader(name, value)

The first time the XMLHttpRequest#open(method, url, async, username, password) is called it creates a RequestContext object which is stored inside a cache.

XMLHttpRequest.prototype.open = function() {

    // Creates a RequestContext object for the request
    var requestContext = OAuth.RequestContext.create(this, arguments);

    // Stores the RequestContext object in the RequestContext cache      
    This.addRequestContext(requestContext);

    // Calls the OAuth.JS overwritten 'open' method
    return This._open(requestContext);

};

The in the overwritten send and setRequestHeader methods we get the RequestObject back.

XMLHttpRequest.prototype.setRequestHeader = function(key, value) {

    // Gets the RequestContext associated to this original XMLHttpRequest object from the RequestContext cache 
    var requestContext = This.getRequestContext(this.getId());

    ...

};

For now the cache is managed directly in the AbstractRequestManager, to have something easy to test and update we should create a new dedicated RequestContextCache component.

Be careful in the implementation, the RequestContext objects associated to already used xhrs should be evicted to free memory.

@bgaillard bgaillard added this to the 1.0.0 milestone Nov 4, 2015
@bgaillard bgaillard self-assigned this Nov 4, 2015
@bgaillard bgaillard modified the milestones: 0.3.0, 1.0.0 Nov 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant