Hey everyone trying to use http2 procotol with h2 crate and getting this error: Error: Error { kind: GoAway(b"", FRAME_SIZE_ERROR, Library) }
What can be wrong ?
Here is the example code that im using:
use h2::client;
use http::{HeaderMap, Request, Method,};
use std::error::Error;
use tokio::net::TcpStream;
#[tokio::main]
pub async fn main() -> Result<(), Box<dyn Error>> {
// Establish TCP connection to the server.
let tcp = TcpStream::connect("<ip>:443").await?;
let (h2, connection) = client::handshake(tcp).await?;
tokio::spawn(async move {
connection.await.unwrap();
});
let mut h2 = h2.ready().await?;
// Prepare the HTTP request to send to the server.
let request = Request::builder()
.uri("<url>")
.header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36")
.body(())
.unwrap();
// Send the request. The second tuple item allows the caller
// to stream a request body.
let (response, _) = h2.send_request(request, true).unwrap();
let (head, mut body) = response.await?.into_parts();
println!("Received response: {:?}", head);
// The `flow_control` handle allows the caller to manage
// flow control.
//
// Whenever data is received, the caller is responsible for
// releasing capacity back to the server once it has freed
// the data from memory.
let mut flow_control = body.flow_control().clone();
while let Some(chunk) = body.data().await {
let chunk = chunk?;
println!("RX: {:?}", chunk);
// Let the server send more data.
let _ = flow_control.release_capacity(chunk.len());
}
Ok(())
}
There are multiple ways for your browser to indicate protocol support, but the code you wrote isn't using any of them. Is there a reason you're using h2 as opposed to an HTTP client like reqwest?
I have tried to use reqwest first by using ClientBuilder in reqwest - Rust
this method allowing for only http2 and got same error when i use reqwest and then moved the h2 library and again got this frame_size_error in h2 library too.
So i got same error for both library