diff --git a/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java b/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java
index 83068492..26059303 100644
--- a/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java
+++ b/spring-graphql/src/main/java/org/springframework/graphql/web/WebOutput.java
@@ -29,6 +29,7 @@ import graphql.GraphQLError;
import org.springframework.graphql.RequestOutput;
import org.springframework.http.HttpHeaders;
import org.springframework.lang.Nullable;
+import org.springframework.util.Assert;
/**
* Decorate an {@link ExecutionResult}, provide a way to {@link #transform(Consumer)
@@ -40,37 +41,35 @@ import org.springframework.lang.Nullable;
*/
public class WebOutput extends RequestOutput {
- @Nullable
private final HttpHeaders responseHeaders;
/**
- * Create an instance that wraps the given {@link ExecutionResult}.
+ * Create an instance from the given {@link RequestOutput}.
* @param requestOutput the output from an executed request
*/
public WebOutput(RequestOutput requestOutput) {
- this(requestOutput.getExecutionInput(), requestOutput, null);
+ this(requestOutput.getExecutionInput(), requestOutput, new HttpHeaders());
}
- private WebOutput(
- ExecutionInput executionInput, ExecutionResult executionResult,
- @Nullable HttpHeaders responseHeaders) {
+ private WebOutput(ExecutionInput executionInput, ExecutionResult executionResult,
+ HttpHeaders responseHeaders) {
super(executionInput, executionResult);
+ Assert.notNull(responseHeaders, "HttpHeaders is required");
this.responseHeaders = responseHeaders;
}
/**
- * Return a read-only view of any custom headers to be added to the HTTP response, or
- * {@code null} until {@link #transform(Consumer)} is used to add such headers.
- * @return the read-only HTTP response headers
- * @see #transform(Consumer)
- * @see Builder#responseHeader(String, String...)
+ * Return the headers to be added to the HTTP response.
+ *
By default, this is empty.
+ *
Note: This is for use with GraphQL over HTTP requests
+ * but not for GraphQL over WebSocket where the initial handshake HTTP
+ * request completes before queries begin.
*/
- @Nullable
public HttpHeaders getResponseHeaders() {
- return (this.responseHeaders != null) ? HttpHeaders.readOnlyHttpHeaders(this.responseHeaders) : null;
+ return this.responseHeaders;
}
/**
@@ -91,7 +90,7 @@ public class WebOutput extends RequestOutput {
*/
public static final class Builder {
- private final ExecutionInput executionInput;
+ private final WebOutput webOutput;
@Nullable
private Object data;
@@ -101,15 +100,11 @@ public class WebOutput extends RequestOutput {
@Nullable
private Map