Skip to content

Commit 107c8e6

Browse files
authored
fix GHNotificationStream "Unable to parse If-Modified-Since request header" (#1984)
* fix GitHub notification interface return "Unable to parse If-Modified-Since request header" * updated test for GHNotificationStream
1 parent 460c9fe commit 107c8e6

File tree

5 files changed

+57
-3
lines changed

5 files changed

+57
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,9 @@ GHThread fetch() {
187187
Thread.sleep(waitTime);
188188
}
189189

190-
req.setHeader("If-Modified-Since", lastModified);
190+
if (lastModified != null) {
191+
req.setHeader("If-Modified-Since", lastModified);
192+
}
191193

192194
Requester requester = req.withUrlPath(apiUrl);
193195
GitHubResponse<GHThread[]> response = ((GitHubPageContentsIterable<GHThread>) requester

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1709,6 +1709,7 @@ public void notifications() throws Exception {
17091709
}
17101710
assertThat(found, is(true));
17111711
gitHub.listNotifications().markAsRead();
1712+
gitHub.listNotifications().iterator().next();
17121713
}
17131714

17141715
/**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"message": "Unable to parse If-Modified-Since request header. Please make sure value is in an acceptable format.",
3+
"documentation_url": "https://docs.github.com/rest/activity/notifications#list-notifications-for-the-authenticated-user",
4+
"status": "422"
5+
}

src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/26-notifications.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"X-XSS-Protection": "1; mode=block",
4141
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
4242
"Content-Security-Policy": "default-src 'none'",
43-
"X-GitHub-Request-Id": "CB13:833E:A1F759:BFE352:5DB3A151",
44-
"Link": "<https://api.github.com/notifications?page=2>; rel=\"next\", <https://api.github.com/notifications?page=5>; rel=\"last\""
43+
"X-GitHub-Request-Id": "CB13:833E:A1F759:BFE352:5DB3A151"
4544
}
4645
},
4746
"uuid": "ac22e3e2-f0d3-4ff1-af23-23e9c79c725c",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"id": "ac22e3e2-f0d3-4ff1-af23-23e9c7915874",
3+
"name": "notifications",
4+
"request": {
5+
"url": "/notifications",
6+
"method": "GET",
7+
"headers": {
8+
"Accept": {
9+
"equalTo": "application/vnd.github+json"
10+
},
11+
"If-Modified-Since":{
12+
"equalTo": "null"
13+
}
14+
}
15+
},
16+
"response": {
17+
"status": 422,
18+
"bodyFileName": "27-notifications.json",
19+
"headers": {
20+
"Date": "Wed, 20 Nov 2024 13:55:23 GMT",
21+
"Content-Type": "application/json; charset=utf-8",
22+
"X-OAuth-Scopes": "repo",
23+
"X-Accepted-OAuth-Scopes": "notifications, repo",
24+
"X-GitHub-Media-Type": "github.v3; format=json",
25+
"x-github-api-version-selected": "2022-11-28",
26+
"X-RateLimit-Limit": "5000",
27+
"X-RateLimit-Remaining": "4992",
28+
"X-RateLimit-Reset": "1732111985",
29+
"X-RateLimit-Used": "8",
30+
"X-RateLimit-Resource": "core",
31+
"Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset",
32+
"Access-Control-Allow-Origin": "*",
33+
"Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
34+
"X-Frame-Options": "deny",
35+
"X-Content-Type-Options": "nosniff",
36+
"X-XSS-Protection": "0",
37+
"Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
38+
"Content-Security-Policy": "default-src 'none'",
39+
"Vary": "Accept-Encoding, Accept, X-Requested-With",
40+
"Server": "github.com",
41+
"X-GitHub-Request-Id": "052F:2E353B:3FE0C:42EBB:673DEA4B"
42+
}
43+
},
44+
"uuid": "ac22e3e2-f0d3-4ff1-af23-23e9c7915874",
45+
"persistent": true,
46+
"insertionIndex": 26
47+
}

0 commit comments

Comments
 (0)