Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare 2.1.0 release #45

Merged
merged 72 commits into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
26dc142
add time threshold for backoff reset
eli-darkly Dec 11, 2018
881473f
Merge branch 'master' into eb/ch15975/backoff-reset
eli-darkly Dec 11, 2018
ca0865d
allow endpoint to be specified as either URI or HttpUrl
eli-darkly Dec 11, 2018
a35c7e6
add @since
eli-darkly Dec 11, 2018
8e4363b
add interface for customizing requests
eli-darkly Dec 11, 2018
54f11e0
Merge pull request #18 from launchdarkly/eb/ch15975/backoff-reset
eli-darkly Dec 13, 2018
7b104a0
Merge pull request #20 from launchdarkly/eb/ch28150/customize-request
eli-darkly Dec 13, 2018
32f80d8
Merge branch 'master' into eb/ch28144/okhttp-url
eli-darkly Dec 13, 2018
1bd8145
Merge pull request #19 from launchdarkly/eb/ch28144/okhttp-url
eli-darkly Dec 13, 2018
52d1732
javadoc fixes
eli-darkly Dec 13, 2018
e82ee5f
add changelog for past releases
eli-darkly Dec 13, 2018
5917b43
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Dec 13, 2018
d6a189b
remove JSR305
eli-darkly Mar 19, 2019
9674ef7
Merge pull request #21 from launchdarkly/eb/ch34379/annotations
eli-darkly Mar 20, 2019
ef15c12
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Mar 21, 2019
6d498fe
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Aug 1, 2019
890eada
replace SSL-specific config method with general-purpose HTTP config m…
eli-darkly Aug 1, 2019
7ba89f4
make helper method static
eli-darkly Aug 1, 2019
4acfb7e
Merge pull request #22 from launchdarkly/eb/ch44325/http-custom-config
eli-darkly Aug 1, 2019
95e4c37
add end-to-end EventSource tests
eli-darkly Aug 1, 2019
c93f4f0
spacing
eli-darkly Aug 1, 2019
0460bfe
Merge pull request #23 from launchdarkly/eb/ch28292/http-tests
eli-darkly Aug 1, 2019
5cd1b37
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Aug 1, 2019
64a67fc
Merge branch 'master' of github.com:launchdarkly/okhttp-eventsource
eli-darkly Aug 22, 2019
9f05a9a
omit default header value if there's a custom value
eli-darkly Oct 12, 2019
2e5354b
avoid trailing period in logger name
eli-darkly Oct 12, 2019
9f83742
Merge pull request #25 from launchdarkly/eb/ch52604/logger-name
eli-darkly Oct 18, 2019
3dd72a6
Merge pull request #24 from launchdarkly/eb/ch52602/override-header
eli-darkly Oct 18, 2019
b77ea93
merge from public after release
LaunchDarklyCI Oct 18, 2019
9874518
add 1.x branch
eli-darkly Jan 18, 2020
7ada28f
update to OkHttp 4.x and Java 8
eli-darkly Jan 18, 2020
bf2f83c
javadoc fixes
eli-darkly Jan 18, 2020
09d9173
Merge branch 'master' into eb/ch62055/okhttp-4.x
eli-darkly Jan 18, 2020
0c3695e
Merge pull request #26 from launchdarkly/eb/ch62055/okhttp-4.x
eli-darkly Jan 22, 2020
8c9ca57
remove EventSource setters, + test improvements
eli-darkly Jan 22, 2020
0c59325
Merge pull request #27 from launchdarkly/eb/ch62489/remove-setters
eli-darkly Jan 22, 2020
65e49b3
merge from public after release
LaunchDarklyCI Jan 22, 2020
7339b66
update Gradle release
eli-darkly Jan 31, 2020
8cabf86
enable Github Pages
eli-darkly Jan 31, 2020
cf995b9
Merge pull request #28 from launchdarkly/eb/ch63665/fix-release
eli-darkly Jan 31, 2020
0644277
skip tests in release
eli-darkly Jan 31, 2020
0814f3d
Merge branch 'public-master'
eli-darkly Jan 31, 2020
0f25a02
merge from public after release
LaunchDarklyCI Jan 31, 2020
9f9513a
merge from public after release
LaunchDarklyCI Jan 31, 2020
4f542e4
add ability to force a stream restart; improve tests so we can test this
eli-darkly Mar 14, 2020
7abb48b
revert whitespace change
eli-darkly Mar 14, 2020
2229c4b
add 1.x branch
eli-darkly Jan 18, 2020
685e03f
Merge branch '1.x' of github.com:launchdarkly/okhttp-eventsource into…
eli-darkly Mar 14, 2020
ce2509d
Merge branch '1.x' into eb/ch69336/restart-plus-tests-2.x
eli-darkly Mar 14, 2020
78fa088
Merge branch 'eb/ch69336/restart-stream-and-tests' into eb/ch69336/re…
eli-darkly Mar 14, 2020
c6d5b46
bump OkHttp version to latest Java 7-compatible version
eli-darkly Mar 20, 2020
2c2ca19
Merge pull request #30 from launchdarkly/eb/ch70366/okhttp-update
eli-darkly Mar 20, 2020
21c5e0d
prepare 1.10.2 release (#43)
LaunchDarklyCI Mar 20, 2020
0b3b5b8
Releasing version 1.10.2
LaunchDarklyCI Mar 20, 2020
e5c3b3d
merge from public after release
LaunchDarklyCI Mar 20, 2020
bf60873
Merge branch '1.x'
eli-darkly Mar 20, 2020
0599650
Gradle update + build fixes
eli-darkly Mar 20, 2020
a7e19ed
Merge branch '1.x' of github.com:launchdarkly/okhttp-eventsource into…
eli-darkly Mar 20, 2020
5c3c554
Merge branch '1.x'
eli-darkly Mar 20, 2020
48b0692
add ability to force a stream restart; improve tests so we can test t…
eli-darkly Mar 26, 2020
f5f6264
Merge branch '1.x' into eb/ch69336/restart-plus-tests-2.x
eli-darkly Mar 27, 2020
d2dad1c
Merge branch 'eb/ch69336/restart-plus-tests-2.x'
eli-darkly Mar 27, 2020
42ae118
prepare 1.11.0 release (#44)
LaunchDarklyCI Mar 30, 2020
989cc9d
Releasing version 1.11.0
LaunchDarklyCI Mar 30, 2020
b96e581
merge from public after release
LaunchDarklyCI Mar 30, 2020
e095fab
Gradle release fixes
eli-darkly Apr 6, 2020
3f431f1
Merge branch '1.x' of github.com:launchdarkly/okhttp-eventsource into…
eli-darkly Apr 6, 2020
e5e7a5d
Merge branch '1.x'
eli-darkly Apr 6, 2020
c2a6bb5
update to okhttp 4.5.0
eli-darkly Apr 7, 2020
439b9ff
longer timeout for cleaner shutdown of test servers
eli-darkly Apr 7, 2020
3e72475
Merge pull request #31 from launchdarkly/eb/ch72725/okhttp-update
eli-darkly Apr 7, 2020
91ae82e
fix Gradle scopes
eli-darkly Apr 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
omit default header value if there's a custom value
  • Loading branch information
eli-darkly committed Oct 12, 2019
commit 9f05a9a632a7ae0541975d578fea2165a8e9a6e8
17 changes: 13 additions & 4 deletions src/main/java/com/launchdarkly/eventsource/EventSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class EventSource implements ConnectionHandler, Closeable {
*/
public static final int DEFAULT_BACKOFF_RESET_THRESHOLD_MS = 1000 * 60;

private static final Headers defaultHeaders =
new Headers.Builder().add("Accept", "text/event-stream").add("Cache-Control", "no-cache").build();

private final String name;
private volatile HttpUrl url;
private final Headers headers;
Expand Down Expand Up @@ -364,11 +367,17 @@ private long nextLong(Random rand, long bound) {
private static Headers addDefaultHeaders(Headers custom) {
Headers.Builder builder = new Headers.Builder();

builder.add("Accept", "text/event-stream").add("Cache-Control", "no-cache");
for (String name : defaultHeaders.names()) {
if (!custom.names().contains(name)) { // skip the default if they set any custom values for this key
for (String value: defaultHeaders.values(name)) {
builder.add(name, value);
}
}
}

for (Map.Entry<String, List<String>> header : custom.toMultimap().entrySet()) {
for (String value : header.getValue()) {
builder.add(header.getKey(), value);
for (String name : custom.names()) {
for (String value : custom.values(name)) {
builder.add(name, value);
}
}

Expand Down
28 changes: 28 additions & 0 deletions src/test/java/com/launchdarkly/eventsource/EventSourceTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.launchdarkly.eventsource;

import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
Expand All @@ -16,6 +17,7 @@
import java.net.Proxy;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -215,4 +217,30 @@ public void defaultMethod() {
assertEquals("GET", req.method());
assertEquals(null, req.body());
}

@Test
public void customHeaders() throws IOException {
Headers headers = new Headers.Builder()
.add("header1", "value1").add("header1", "value2")
.add("header2", "value1")
.build();
builder.headers(headers);
Request req = builder.build().buildRequest();
assertEquals(Arrays.<String>asList("value1", "value2"), req.headers().values("header1"));
assertEquals(Arrays.<String>asList("value1"), req.headers().values("header2"));
assertEquals(Arrays.<String>asList("text/event-stream"), req.headers().values("Accept"));
assertEquals(Arrays.<String>asList("no-cache"), req.headers().values("Cache-Control"));
}

@Test
public void customHeadersOverwritingDefaults() throws IOException {
Headers headers = new Headers.Builder()
.add("Accept", "text/plain")
.add("header2", "value1")
.build();
builder.headers(headers);
Request req = builder.build().buildRequest();
assertEquals(Arrays.<String>asList("text/plain"), req.headers().values("Accept"));
assertEquals(Arrays.<String>asList("value1"), req.headers().values("header2"));
}
}