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

org.webpieces.httpclientx.impl.StreamWriterImpl Maven / Gradle / Ivy

Go to download

http2 client api that talks http1 in case you want to convert from http2 to http1.1 without changing code

There is a newer version: 2.1.1
Show newest version
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);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy