public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {

        final CookieOrigin cookieOrigin = cookieOriginFromUri(requestSpec.getURI());
        for (Cookie cookie : cookieStore.getCookies()) {
            if (cookieSpec.match(cookie, cookieOrigin) && allowMultipleCookiesWithTheSameNameOrCookieNotPreviouslyDefined(requestSpec, cookie)) {
                requestSpec.cookie(cookie.getName(), cookie.getValue());
            }
        }

        final Response response = ctx.next(requestSpec, responseSpec);

        List<Cookie> responseCookies = extractResponseCookies(response, cookieOrigin);
        cookieStore.addCookies(responseCookies.toArray(new Cookie[0]));
        return response;
    }
@Test
    public void addDuplicateNameCookiesLikeInBrowser() {
        FilterableRequestSpecification reqOriginDomainDuplicate = (FilterableRequestSpecification)
                given().with().baseUri("https://foo.com/bar");
        DuplicateTestFilterContext duplicateTestFilterContext = new DuplicateTestFilterContext();
        final CookieFilter cookieFilterDuplicate = new CookieFilter(true);

        cookieFilterDuplicate.filter(reqOriginDomainDuplicate, response, duplicateTestFilterContext);
        cookieFilterDuplicate.filter(reqOriginDomainDuplicate, response, duplicateTestFilterContext);

        assertThat(reqOriginDomainDuplicate.getCookies().size(), Matchers.is(2));
        final List<Cookie> list = reqOriginDomainDuplicate.getCookies().getList("cookieName");
        assertThat(list.get(0).getName(), Matchers.is("cookieName"));
        assertThat(list.get(0).getValue(), Matchers.anyOf(Matchers.is("xxx"), Matchers.is("yyy")));
        assertThat(list.get(1).getName(), Matchers.is("cookieName"));
        assertThat(list.get(1).getValue(), Matchers.anyOf(Matchers.is("xxx"), Matchers.is("yyy")));
    }