use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-framework by TAKETODAY.
the class PartEventHttpMessageReaderTests method chrome.
@Test
public void chrome() {
MockServerHttpRequest request = createRequest(new ClassPathResource("chrome.multipart", getClass()), "----WebKitFormBoundaryEveBLvRT65n21fwU");
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, 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();
}
use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-framework by TAKETODAY.
the class PartEventHttpMessageReaderTests method safari.
@Test
public void safari() {
MockServerHttpRequest request = createRequest(new ClassPathResource("safari.multipart", getClass()), "----WebKitFormBoundaryG8fJ50opQOML0oGD");
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, 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();
}
use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-infrastructure by TAKETODAY.
the class MultipartHttpMessageWriter method writeMultipart.
private Mono<Void> writeMultipart(MultiValueMap<String, ?> map, ReactiveHttpOutputMessage outputMessage, @Nullable MediaType mediaType, Map<String, Object> hints) {
byte[] boundary = generateMultipartBoundary();
mediaType = getMultipartMediaType(mediaType, boundary);
outputMessage.getHeaders().setContentType(mediaType);
if (isDebugEnabled) {
LogFormatUtils.traceDebug(logger, traceOn -> Hints.getLogPrefix(hints) + "Encoding " + (isEnableLoggingRequestDetails() ? LogFormatUtils.formatValue(map, !traceOn) : "parts " + map.keySet() + " (content masked)"));
}
DataBufferFactory bufferFactory = outputMessage.bufferFactory();
Flux<DataBuffer> body = Flux.fromIterable(map.entrySet()).concatMap(entry -> encodePartValues(boundary, entry.getKey(), entry.getValue(), bufferFactory)).concatWith(generateLastLine(boundary, bufferFactory)).doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release);
if (isDebugEnabled) {
body = body.doOnNext(buffer -> Hints.touchDataBuffer(buffer, hints, logger));
}
return outputMessage.writeWith(body);
}
use of cn.taketoday.core.io.buffer.DataBufferUtils in project today-infrastructure 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-infrastructure by TAKETODAY.
the class Jackson2JsonEncoderTests method encodeAsStreamWithCustomStreamingType.
// SPR-15727
@Test
public void encodeAsStreamWithCustomStreamingType() {
MediaType fooMediaType = new MediaType("application", "foo");
MediaType barMediaType = new MediaType("application", "bar");
this.encoder.setStreamingMediaTypes(Arrays.asList(fooMediaType, barMediaType));
Flux<Pojo> input = Flux.just(new Pojo("foo", "bar"), new Pojo("foofoo", "barbar"), new Pojo("foofoofoo", "barbarbar"));
testEncode(input, ResolvableType.fromClass(Pojo.class), step -> step.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}\n").andThen(DataBufferUtils::release)).consumeNextWith(expectString("{\"foo\":\"foofoo\",\"bar\":\"barbar\"}\n").andThen(DataBufferUtils::release)).consumeNextWith(expectString("{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}\n").andThen(DataBufferUtils::release)).verifyComplete(), barMediaType, null);
}
Aggregations