org.webpieces.httpclientx.impl.StreamWriterImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http2to1_1-client Show documentation
Show all versions of http2to1_1-client Show documentation
http2 client api that talks http1 in case you want to convert from http2 to http1.1 without changing code
package org.webpieces.httpclientx.impl;
import java.util.concurrent.CompletableFuture;
import org.webpieces.http2translations.api.Http2ToHttp1_1;
import org.webpieces.httpclient11.api.HttpDataWriter;
import org.webpieces.httpparser.api.dto.HttpData;
import org.webpieces.httpparser.api.dto.HttpRequest;
import com.webpieces.http2engine.api.StreamWriter;
import com.webpieces.http2parser.api.dto.DataFrame;
import com.webpieces.http2parser.api.dto.lib.StreamMsg;
public class StreamWriterImpl implements StreamWriter {
private HttpDataWriter dataWriter;
private HttpRequest req;
public StreamWriterImpl(HttpDataWriter dataWriter, HttpRequest req) {
this.dataWriter = dataWriter;
this.req = req;
}
@Override
public CompletableFuture processPiece(StreamMsg data) {
if(!(data instanceof DataFrame))
throw new IllegalArgumentException("You must feed in http1_1 compatible http2 payloads like DataFrame. this is not http1_1 compatible="+data.getClass());
HttpData chunk = Http2ToHttp1_1.translate((DataFrame)data, req);
return dataWriter.send(chunk);
}
}