Skip to content

Commit 9e5edf1

Browse files
committed
removed sse write in proxy close
1 parent d2a18e0 commit 9e5edf1

2 files changed

Lines changed: 74 additions & 6 deletions

File tree

‎moco-core/src/main/java/com/github/dreamhead/moco/handler/AbstractProxyResponseHandler.java‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,6 @@ private void close() {
410410
return;
411411
}
412412
closed = true;
413-
if (onEvent != null) {
414-
ImmutableList<SseEvent> collectedEvents = collected.build();
415-
if (!collectedEvents.isEmpty()) {
416-
onEvent.accept(collectedEvents);
417-
}
418-
}
419413
try {
420414
closeable.close();
421415
} catch (IOException ignored) {
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.github.dreamhead.moco;
2+
3+
import com.github.dreamhead.moco.helper.Http2TestHelper;
4+
import org.junit.jupiter.api.Test;
5+
6+
import java.net.http.HttpResponse;
7+
8+
import static com.github.dreamhead.moco.HttpsCertificate.certificate;
9+
import static com.github.dreamhead.moco.Moco.by;
10+
import static com.github.dreamhead.moco.Moco.httpsServer;
11+
import static com.github.dreamhead.moco.Moco.pathResource;
12+
import static com.github.dreamhead.moco.Moco.uri;
13+
import static com.github.dreamhead.moco.Runner.running;
14+
import static com.github.dreamhead.moco.helper.RemoteTestUtils.httpsRoot;
15+
import static org.hamcrest.CoreMatchers.is;
16+
import static org.hamcrest.MatcherAssert.assertThat;
17+
18+
public class MocoHttps2Test {
19+
private static final HttpsCertificate DEFAULT_CERTIFICATE = certificate(pathResource("cert.jks"), "mocohttps", "mocohttps");
20+
21+
@Test
22+
void should_send_https_get_request() throws Exception {
23+
HttpsServer server = httpsServer(DEFAULT_CERTIFICATE);
24+
server.request(by(uri("/https"))).response("HTTPS OK");
25+
26+
running(server, () -> {
27+
try (Http2TestHelper helper = new Http2TestHelper(true)) {
28+
String response = helper.get(httpsRoot(server.port()) + "/https");
29+
assertThat(response, is("HTTPS OK"));
30+
}
31+
});
32+
}
33+
34+
@Test
35+
void should_send_https_post_request() throws Exception {
36+
HttpsServer server = httpsServer(DEFAULT_CERTIFICATE);
37+
server.request(by(uri("/secure-post"))).response("Secure Post OK");
38+
39+
running(server, () -> {
40+
try (Http2TestHelper helper = new Http2TestHelper(true)) {
41+
String response = helper.post(httpsRoot(server.port()) + "/secure-post", "secure data");
42+
assertThat(response, is("Secure Post OK"));
43+
}
44+
});
45+
}
46+
47+
@Test
48+
void should_get_https_full_response() throws Exception {
49+
HttpsServer server = httpsServer(DEFAULT_CERTIFICATE);
50+
server.request(by(uri("/secure-status"))).response("Secure Content");
51+
52+
running(server, () -> {
53+
try (Http2TestHelper helper = new Http2TestHelper(true)) {
54+
HttpResponse<String> response = helper.getResponse(httpsRoot(server.port()) + "/secure-status");
55+
assertThat(response.statusCode(), is(200));
56+
assertThat(response.body(), is("Secure Content"));
57+
}
58+
});
59+
}
60+
61+
@Test
62+
void should_send_https_post_with_headers() throws Exception {
63+
HttpsServer server = httpsServer(DEFAULT_CERTIFICATE);
64+
server.request(by(uri("/secure-headers"))).response("Secure Headers OK");
65+
66+
running(server, () -> {
67+
try (Http2TestHelper helper = new Http2TestHelper(true)) {
68+
String response = helper.post(httpsRoot(server.port()) + "/secure-headers", "secure data",
69+
com.google.common.collect.ImmutableMultimap.of("X-Custom", "secure-value"));
70+
assertThat(response, is("Secure Headers OK"));
71+
}
72+
});
73+
}
74+
}

0 commit comments

Comments
 (0)