Response headers always in sync with native response
ServerHttpResponse implementations now immediately propagate HttpHeaders changes as they so there is no need to call applyHeaders(). The writeHeaders from ServerHttpResponse is also removed. RxNetty and Reactor Net both support implicitly completing if the handler completes without explicitly writing the headers or the response body.
This commit is contained in:
@@ -49,11 +49,6 @@ public class MockServerHttpResponse implements ServerHttpResponse {
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Publisher<Void> writeHeaders() {
|
||||
return Publishers.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Publisher<Void> setBody(Publisher<ByteBuffer> body) {
|
||||
this.body = body;
|
||||
|
||||
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
import reactor.Publishers;
|
||||
import reactor.io.buffer.Buffer;
|
||||
import reactor.rx.Streams;
|
||||
|
||||
@@ -67,7 +68,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFoo() throws Exception {
|
||||
public void testFooHandler() throws Exception {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@@ -80,7 +81,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBar() throws Exception {
|
||||
public void testBarHandler() throws Exception {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
@@ -92,6 +93,19 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
|
||||
assertArrayEquals("bar".getBytes(UTF_8), response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHeaderSettingHandler() throws Exception {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
URI url = new URI("http://localhost:" + port + "/header");
|
||||
RequestEntity<Void> request = RequestEntity.get(url).build();
|
||||
ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
|
||||
|
||||
assertEquals(HttpStatus.OK, response.getStatusCode());
|
||||
assertEquals("bar", response.getHeaders().getFirst("foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotFound() throws Exception {
|
||||
|
||||
@@ -114,6 +128,7 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("/foo", new FooHandler());
|
||||
map.put("/bar", new BarHandler());
|
||||
map.put("/header", new HeaderSettingHandler());
|
||||
setHandlers(map);
|
||||
}
|
||||
}
|
||||
@@ -134,4 +149,13 @@ public class SimpleUrlHandlerMappingIntegrationTests extends AbstractHttpHandler
|
||||
}
|
||||
}
|
||||
|
||||
private static class HeaderSettingHandler implements HttpHandler {
|
||||
|
||||
@Override
|
||||
public Publisher<Void> handle(ServerHttpRequest request, ServerHttpResponse response) {
|
||||
response.getHeaders().add("foo", "bar");
|
||||
return Publishers.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user