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
HTTP/2 client that talks HTTP/1.1 in case you want to convert from HTTP/2 to HTTP/1.1 without changing code
package org.webpieces.httpclientx.impl;
import org.webpieces.util.futures.XFuture;
import org.webpieces.http2translations.api.Http2ToHttp11;
import org.webpieces.httpclient11.api.HttpDataWriter;
import org.webpieces.httpparser.api.dto.HttpData;
import org.webpieces.httpparser.api.dto.HttpRequest;
import com.webpieces.http2.api.dto.lowlevel.DataFrame;
import com.webpieces.http2.api.dto.lowlevel.lib.StreamMsg;
import com.webpieces.http2.api.streaming.StreamWriter;
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 XFuture 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 = Http2ToHttp11.translate((DataFrame)data, req);
return dataWriter.send(chunk);
}
}