All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.webpieces.webserver.impl.WebpiecesStreamHandle Maven / Gradle / Ivy

There is a newer version: 2.1.1
Show newest version
package org.webpieces.webserver.impl;

import java.util.concurrent.CompletableFuture;

import org.webpieces.frontend2.api.HttpStream;
import org.webpieces.frontend2.api.ResponseStream;

import com.webpieces.hpack.api.dto.Http2Request;
import com.webpieces.http2engine.api.StreamWriter;
import com.webpieces.http2parser.api.dto.CancelReason;

public class WebpiecesStreamHandle implements HttpStream {

	private RequestHelpFacade facade;
	private RequestStreamWriter writer;

	public WebpiecesStreamHandle(RequestHelpFacade facade) {
		this.facade = facade;
	}

	@Override
	public CompletableFuture incomingRequest(Http2Request headers, ResponseStream stream) {
		writer = new RequestStreamWriter(facade, stream, headers);
		
		if(headers.isEndOfStream()) {
			CompletableFuture future = writer.handleCompleteRequest();
			writer.setOutstandingRequest(future);
			return future.thenApply( v -> writer);
		}

		return CompletableFuture.completedFuture(writer);
	}

	@Override
	public CompletableFuture incomingCancel(CancelReason c) {
		writer.cancelOutstandingRequest();
		return CompletableFuture.completedFuture(null);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy