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

added request headers matching #89

Closed

Conversation

vizio360
Copy link

Added the ability to match request headers.

I'm in the middle of testing some oauth2 services and I needed an easy way to create mocks which would be valid only if an Authorization header was sent in the request.

This pull requests adds a new property you can define in the mockjax options object called requestHeaders.
requestHeaders is just an object with key, value pairs defining which headers are needed by the request to be validated.

here is an example which will match all the requests to /me only if the request includes an header called Authorization with value "Bearer vsdfjsdf+adfvadfv="

$.mockjax({
    url: "/me",
    requestHeaders: {
        Authorization: "Bearer vsdfjsdf+adfvadfv="
    },
    responseText: "YEAH!"
}

@gregfr
Copy link

gregfr commented May 1, 2013

I also would like this feature implemented.

@thejuan
Copy link

thejuan commented Jun 23, 2013

+1

@jakerella
Copy link
Owner

Hello! Our apologies for the very delayed response, we're just starting to ramp this project back into active development.

I like this update and we'd like to get it in, but there are some things to address. Check the line notes in the commit for some of those comments, but first of all there is a merge conflict (the current repo is 2 patch versions ahead of your file). Also, we're using tab indentation, can you update that please?

Thank you for adding tests!! Many people forget about that. Can you add 1 more test? We need to see that the response is correct when there are multiple headers expected and the correct multiple headers are provided.

Last thing: can we enhance the header matching to be either exact string or regex? If you need help with that let us know!

// Inspect the request headers submitted
if ( handler.requestHeaders )
{
console.log("checking headers");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to use $.mockjaxSettings.log(...) for these log calls to support older browsers.

@jakerella
Copy link
Owner

@vizio360 I haven't heard back from you on this PR. If you aren't interested in continuing the work I'd be happy to help out. Please let us know if that's the case and I'll switch this PR to a new branch and start the modifications.

Thanks!

@vizio360
Copy link
Author

@jakerella just finished updating the code. Gonna put it up soon.

@vizio360
Copy link
Author

@jakerella I've created a new pull request (#193) as I do not have access to the previous fork.
I've included all the changes mentioned in this pull request.

@vizio360 vizio360 closed this Oct 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants