Skip to content

Commit 7963fa8

Browse files
committed
Ensure withPreview can be called multiple times
1 parent 1aba601 commit 7963fa8

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/main/java/org/kohsuke/github/GitHubClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public <T> GitHubResponse<T> sendRequest(GitHubRequest request, @CheckForNull Gi
405405
// Setting "Cache-Control" to "no-cache" stops the cache from supplying
406406
// "If-Modified-Since" or "If-None-Match" values.
407407
// This makes GitHub give us current data (not incorrectly cached data)
408-
request = request.toBuilder().withHeader("Cache-Control", "no-cache").build();
408+
request = request.toBuilder().setHeader("Cache-Control", "no-cache").build();
409409
continue;
410410
}
411411
if (!(isRateLimitResponse(responseInfo) || isAbuseLimitResponse(responseInfo))) {

src/main/java/org/kohsuke/github/GitHubRequest.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,9 +384,11 @@ public B withApiUrl(String url) {
384384
* the name
385385
* @param value
386386
* the value
387+
* @return the request builder
387388
*/
388-
public void setHeader(String name, String value) {
389+
public B setHeader(String name, String value) {
389390
headers.put(name, value);
391+
return (B) this;
390392
}
391393

392394
/**
@@ -399,8 +401,11 @@ public void setHeader(String name, String value) {
399401
* @return the request builder
400402
*/
401403
public B withHeader(String name, String value) {
402-
setHeader(name, value);
403-
return (B) this;
404+
String oldValue = headers.get(name);
405+
if (!StringUtils.isBlank(oldValue)) {
406+
value = oldValue + ", " + value;
407+
}
408+
return setHeader(name, value);
404409
}
405410

406411
/**

0 commit comments

Comments
 (0)