From 9d991e2df72e65cbe780af7140a1469cf81d4c8f Mon Sep 17 00:00:00 2001 From: Thomas Bouffard Date: Thu, 10 Oct 2019 17:42:56 +0200 Subject: [PATCH] refactor: do not send cookie if not available This avoids passing empty cookie in requestq --- .../jenkins/rest/filters/JenkinsAuthenticationFilter.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/cdancy/jenkins/rest/filters/JenkinsAuthenticationFilter.java b/src/main/java/com/cdancy/jenkins/rest/filters/JenkinsAuthenticationFilter.java index 670b5a7a..9228f87d 100644 --- a/src/main/java/com/cdancy/jenkins/rest/filters/JenkinsAuthenticationFilter.java +++ b/src/main/java/com/cdancy/jenkins/rest/filters/JenkinsAuthenticationFilter.java @@ -17,6 +17,7 @@ package com.cdancy.jenkins.rest.filters; +import java.util.Optional; import javax.inject.Inject; import javax.inject.Singleton; @@ -61,7 +62,8 @@ public HttpRequest filter(final HttpRequest request) throws HttpException { final Pair localCrumb = getCrumb(); if (localCrumb.getKey().value() != null) { builder.addHeader(CRUMB_HEADER, localCrumb.getKey().value()); - builder.addHeader(HttpHeaders.COOKIE, localCrumb.getKey().sessionIdCookie()); + Optional.ofNullable(localCrumb.getKey().sessionIdCookie()) + .ifPresent(sessionId -> builder.addHeader(sessionId)); } else { if (localCrumb.getValue() == false) { throw new RuntimeException("Unexpected exception being thrown: error=" + localCrumb.getKey().errors().get(0));