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

Internal server error when sending duplicate cookie #567

Closed
viniciusffj opened this issue Jan 10, 2017 · 8 comments
Closed

Internal server error when sending duplicate cookie #567

viniciusffj opened this issue Jan 10, 2017 · 8 comments
Labels

Comments

@viniciusffj
Copy link

Hi.

I'm experiencing a strange error in wiremock.

Let's say I have the following mapping:

{
    "request": {
        "method": "GET",
        "url": "/test"
    },
    "response": {
        "status": 200,
        "body": "More content\n"
    }
}

If I make a request with two values for one cookie, like this:

$ curl 'http://localhost:8080/test' -H 'Cookie: cookie1=190283aJDS;cookie1=190283aJDS'

I get the following response:

<html>

<head>
    <meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1" />
    <title>Error 500 </title>
</head>

<body>
    <h2>HTTP ERROR: 500</h2>
    <p>Problem accessing /test. Reason:
        <pre>    java.lang.IllegalArgumentException: Multiple entries with same key: cookie1=190283aJDS and cookie1=190283aJDS</pre></p>
    <hr /><i><small>Powered by Jetty://</small></i>
</body>

</html>

But if I remove the duplication, it works. For example:

$ curl 'http://localhost:8080/test' -H 'Cookie: cookie1=190283aJDS'

I know that we shouldn't set the cookie value twice, but in my real life case I really can't control that.
What could I do?

Also, I've tried to debug wiremock but I didn't go too far. Is there any debug flag (I'm already using --verbose) that I can see the stacktrace?

@tomakehurst
Copy link
Member

Yeah, poor modelling decision on my part. Cookies are represented by a map internally and the map builder blows up if you try to add more than one with the same key.

I'll switch to a list when I get the chance.

@viniciusffj
Copy link
Author

Thanks.

If you need help I can try to make a PR, but I need some guidance first given that I'm not familiar with the code.

@tomakehurst
Copy link
Member

If you fancy having a go at it, it's primarily about changing Request.getCookies() to return a List<Cookie> rather than a map, changing WireMockHttpServletRequestAdapter so it adapts to a list (and therefore duplicates being OK), and dealing with the consequences of the switch in the handful of features that read cookies.

@viniciusffj
Copy link
Author

Ok, I'll take a look on those and try to open a PR.

@mmodenesi
Copy link

Hi, I'm facing the same problem. Can you suggest any workarround for this issue without changing the version of wiremock? Thanks in advance!

@viniciusffj
Copy link
Author

Hi @mmodenesi

I solved the problem by removing the duplicated cookies in my front end app.

Unfortunately I failed to submit a PR to fix this, I'll try again when I have a free time

@mmodenesi
Copy link

Thank you. Going that way I found that the issue was related to Firefox 46.0 sending duplicate cookies, not my application. Upgrading the browser solved the issue.

@tomakehurst
Copy link
Member

Fixed in 827e7cc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants