/** * Adds cookies into the "Cookie" header. If the name matches an already existing cookie, the value will be overwritten. * <p> * Note that this requires decoding the current header value before re-encoding, so it is most efficient to * add all new cookies in one call to the method rather than spreading them out. * * @param cookies new cookies * @return this builder */ @Override public Builder addCookies(Collection<RequestCookie> cookies) { requireNonNull(cookies); Set<RequestCookie> currentCookies = decode(headers.get(COOKIE)); List<RequestCookie> newCookies = concat(cookies.stream(), currentCookies.stream()).collect(toList()); return cookies(newCookies); }
/** * Adds cookies into the "Cookie" header. If the name matches an already existing cookie, the value will be overwritten. * <p> * Note that this requires decoding the current header value before re-encoding, so it is most efficient to * add all new cookies in one call to the method rather than spreading them out. * * @param cookies new cookies * @return {@code this} */ public Builder addCookies(Collection<RequestCookie> cookies) { requireNonNull(cookies); Set<RequestCookie> currentCookies = decode(headers.get(COOKIE)); List<RequestCookie> newCookies = concat(cookies.stream(), currentCookies.stream()).collect(toList()); return cookies(newCookies); }
private Builder removeCookiesIf(Predicate<String> removeIfName) { Predicate<RequestCookie> keepIf = cookie -> !removeIfName.test(cookie.name()); List<RequestCookie> newCookies = decode(headers.get(COOKIE)).stream() .filter(keepIf) .collect(toList()); return cookies(newCookies); }
private Builder removeCookiesIf(Predicate<String> removeIfName) { Predicate<RequestCookie> keepIf = cookie -> !removeIfName.test(cookie.name()); List<RequestCookie> newCookies = decode(headers.get(COOKIE)).stream() .filter(keepIf) .collect(toList()); return cookies(newCookies); }