use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-framework by TAKETODAY.
the class AbstractServerHttpResponse method writeWith.
@Override
@SuppressWarnings("unchecked")
public final Mono<Void> writeWith(Publisher<? extends DataBuffer> body) {
// We must resolve value first however, for a chance to handle potential error.
if (body instanceof Mono) {
return ((Mono<? extends DataBuffer>) body).flatMap(buffer -> {
touchDataBuffer(buffer);
AtomicBoolean subscribed = new AtomicBoolean();
return doCommit(() -> {
try {
return writeWithInternal(Mono.fromCallable(() -> buffer).doOnSubscribe(s -> subscribed.set(true)).doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release));
} catch (Throwable ex) {
return Mono.error(ex);
}
}).doOnError(ex -> DataBufferUtils.release(buffer)).doOnCancel(() -> {
if (!subscribed.get()) {
DataBufferUtils.release(buffer);
}
});
}).doOnError(t -> getHeaders().clearContentHeaders()).doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
} else {
return new ChannelSendOperator<>(body, inner -> doCommit(() -> writeWithInternal(inner))).doOnError(t -> getHeaders().clearContentHeaders());
}
}
use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-framework by TAKETODAY.
the class DefaultPartHttpMessageReaderTests method noHeaders.
@ParameterizedDefaultPartHttpMessageReaderTest
public void noHeaders(String displayName, DefaultPartHttpMessageReader reader) {
MockServerHttpRequest request = createRequest(new ClassPathResource("no-header.multipart", getClass()), "boundary");
Flux<Part> result = reader.read(fromClass(Part.class), request, emptyMap());
StepVerifier.create(result).consumeNextWith(part -> {
assertThat(part.headers()).isEmpty();
part.content().subscribe(DataBufferUtils::release);
}).verifyComplete();
}
use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-framework by TAKETODAY.
the class DefaultPartHttpMessageReaderTests method noEndBoundary.
@ParameterizedDefaultPartHttpMessageReaderTest
public void noEndBoundary(String displayName, DefaultPartHttpMessageReader reader) {
MockServerHttpRequest request = createRequest(new ClassPathResource("no-end-boundary.multipart", getClass()), "boundary");
Flux<Part> result = reader.read(fromClass(Part.class), request, emptyMap());
StepVerifier.create(result).consumeNextWith(part -> {
assertThat(part.headers().getFirst("Header")).isEqualTo("Value");
part.content().subscribe(DataBufferUtils::release);
}).expectError(DecodingException.class).verify();
}
use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-framework by TAKETODAY.
the class PartEventHttpMessageReaderTests method exceedHeaderLimit.
@Test
public void exceedHeaderLimit() {
Flux<DataBuffer> body = DataBufferUtils.readByteChannel((new ClassPathResource("files.multipart", getClass()))::readableChannel, bufferFactory, 282);
MediaType contentType = new MediaType("multipart", "form-data", Collections.singletonMap("boundary", "----WebKitFormBoundaryG8fJ50opQOML0oGD"));
MockServerHttpRequest request = MockServerHttpRequest.post("/").contentType(contentType).body(body);
this.reader.setMaxHeadersSize(230);
Flux<PartEvent> result = this.reader.read(fromClass(PartEvent.class), request, emptyMap());
StepVerifier.create(result).assertNext(data(headersFile("file2", "a.txt"), DataBufferUtils::release, true)).assertNext(data(headersFile("file2", "b.txt"), DataBufferUtils::release, true)).verifyComplete();
}
use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-framework by TAKETODAY.
the class PartEventHttpMessageReaderTests method firefox.
@Test
public void firefox() {
MockServerHttpRequest request = createRequest(new ClassPathResource("firefox.multipart", getClass()), "---------------------------18399284482060392383840973206");
Flux<PartEvent> result = this.reader.read(fromClass(PartEvent.class), request, emptyMap());
StepVerifier.create(result).assertNext(data(headersFormField("text1"), bodyText("a"), true)).assertNext(data(headersFormField("text2"), bodyText("b"), true)).assertNext(data(headersFile("file1", "a.txt"), DataBufferUtils::release, false)).assertNext(data(headersFile("file1", "a.txt"), DataBufferUtils::release, false)).assertNext(data(headersFile("file1", "a.txt"), DataBufferUtils::release, true)).assertNext(data(headersFile("file2", "a.txt"), DataBufferUtils::release, false)).assertNext(data(headersFile("file2", "a.txt"), DataBufferUtils::release, false)).assertNext(data(headersFile("file2", "a.txt"), DataBufferUtils::release, true)).assertNext(data(headersFile("file2", "b.txt"), DataBufferUtils::release, false)).assertNext(data(headersFile("file2", "b.txt"), DataBufferUtils::release, false)).assertNext(data(headersFile("file2", "b.txt"), DataBufferUtils::release, true)).verifyComplete();
}
Aggregations