Skip to content

Commit

Permalink
Prevent SSE writing from potentially causing accumulation of headers
Browse files Browse the repository at this point in the history
This could happen if a MessageBodyWriter writes the headers map
(which does not make sense for streaming responses, but it's
nevertheless allowed by the contract of the MessageBodyWriter)

Fixes: quarkusio#31559
  • Loading branch information
geoand committed Mar 3, 2023
1 parent 45c38c1 commit 4cb3797
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import jakarta.ws.rs.client.Entity;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.StatusType;

Expand All @@ -17,6 +16,7 @@
import org.jboss.resteasy.reactive.client.spi.ClientRestHandler;
import org.jboss.resteasy.reactive.common.core.Serialisers;
import org.jboss.resteasy.reactive.common.jaxrs.StatusTypeImpl;
import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedHashMap;

import io.vertx.core.buffer.Buffer;

Expand Down Expand Up @@ -88,7 +88,7 @@ private ByteArrayInputStream entityStreamOfAbortedResponseOf(RestClientRequestCo
entity = Entity.entity(untypedEntity, mediaType);
}
// FIXME: pass headers?
Buffer buffer = context.writeEntity(entity, (MultivaluedMap) Serialisers.EMPTY_MULTI_MAP,
Buffer buffer = context.writeEntity(entity, new QuarkusMultivaluedHashMap<>(),
Serialisers.NO_WRITER_INTERCEPTOR);
return new ByteArrayInputStream(buffer.getBytes());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import org.jboss.resteasy.reactive.common.core.Serialisers;
import org.jboss.resteasy.reactive.common.jaxrs.ConfigurationImpl;
import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedHashMap;

public class InboundSseEventImpl implements InboundSseEvent {

Expand Down Expand Up @@ -120,7 +121,7 @@ public <T> T readData(GenericType<T> type, MediaType mediaType) {
InputStream in = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8));
try {
return (T) ClientSerialisers.invokeClientReader(null, type.getRawType(), type.getType(),
mediaType, null, null, Serialisers.EMPTY_MULTI_MAP,
mediaType, null, null, new QuarkusMultivaluedHashMap<>(),
serialisers, in, Serialisers.NO_READER_INTERCEPTOR, configuration);
} catch (IOException e) {
throw new UncheckedIOException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import jakarta.ws.rs.RuntimeType;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.MultivaluedMap;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.ext.MessageBodyReader;
import jakarta.ws.rs.ext.MessageBodyWriter;
Expand All @@ -32,7 +31,6 @@
public abstract class Serialisers {
public static final Annotation[] NO_ANNOTATION = new Annotation[0];
public static final ReaderInterceptor[] NO_READER_INTERCEPTOR = new ReaderInterceptor[0];
public static final MultivaluedMap<String, Object> EMPTY_MULTI_MAP = new QuarkusMultivaluedHashMap<>();
public static final WriterInterceptor[] NO_WRITER_INTERCEPTOR = new WriterInterceptor[0];
protected static final Map<Class<?>, Class<?>> primitivesToWrappers = new HashMap<>();
// FIXME: spec says we should use generic type, but not sure how to pass that type from Jandex to reflection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.jboss.resteasy.reactive.common.core.Serialisers;
import org.jboss.resteasy.reactive.common.util.CommonSseUtil;
import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedHashMap;
import org.jboss.resteasy.reactive.server.handlers.PublisherResponseHandler;
import org.jboss.resteasy.reactive.server.jaxrs.OutboundSseEventImpl;
import org.jboss.resteasy.reactive.server.spi.ServerHttpResponse;
Expand Down Expand Up @@ -138,7 +139,7 @@ private static String serialiseDataToString(ResteasyReactiveRequestContext conte
if (writer.isWriteable(entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType)) {
// FIXME: spec doesn't really say what headers we should use here
writer.writeTo(entity, entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType,
Serialisers.EMPTY_MULTI_MAP, baos);
new QuarkusMultivaluedHashMap<>(), baos);
wrote = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import jakarta.ws.rs.ext.MessageBodyWriter;

import org.jboss.resteasy.reactive.common.core.Serialisers;
import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedHashMap;
import org.jboss.resteasy.reactive.server.StreamingOutputStream;
import org.jboss.resteasy.reactive.server.handlers.PublisherResponseHandler;
import org.jboss.resteasy.reactive.server.spi.ServerHttpResponse;
Expand Down Expand Up @@ -66,7 +67,7 @@ private static byte[] serialiseEntity(ResteasyReactiveRequestContext context, Ob
if (writer.isWriteable(entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType)) {
// FIXME: spec doesn't really say what headers we should use here
writer.writeTo(entity, entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType,
Serialisers.EMPTY_MULTI_MAP, baos);
new QuarkusMultivaluedHashMap<>(), baos);
wrote = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import org.jboss.resteasy.reactive.common.core.Serialisers;
import org.jboss.resteasy.reactive.common.reflection.ReflectionBeanFactoryCreator;
import org.jboss.resteasy.reactive.common.util.QuarkusMultivaluedHashMap;
import org.jboss.resteasy.reactive.multipart.FileDownload;
import org.jboss.resteasy.reactive.server.NoopCloseAndFlushOutputStream;
import org.jboss.resteasy.reactive.server.core.CurrentRequestManager;
Expand Down Expand Up @@ -192,7 +193,7 @@ private void writeEntity(OutputStream os, Object entity, MediaType mediaType, Re
try (NoopCloseAndFlushOutputStream writerOutput = new NoopCloseAndFlushOutputStream(os)) {
// FIXME: spec doesn't really say what headers we should use here
writer.writeTo(entity, entityClass, entityType, Serialisers.NO_ANNOTATION, mediaType,
Serialisers.EMPTY_MULTI_MAP, writerOutput);
new QuarkusMultivaluedHashMap<>(), writerOutput);
wrote = true;
}

Expand Down

0 comments on commit 4cb3797

Please sign in to comment.