Why response comes over protocol http2.0 although i set for http1.1

I have a few questions too:
2- How to make sure TCP connection is not closed and keep it alive ?
3- What can i do else to make faster request ?
The reason of these all is i want to make fast request.

Here is the code that i used


use reqwest::{redirect::Policy, Client, ClientBuilder,Version};
use serde_json::Value;
use std::time::Duration;
use std::time::Instant;



#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {


    let  client= ClientBuilder::new()
    .tcp_nodelay(true)
    .redirect(Policy::none())
    .build().unwrap();

    let mut counter = 0;
    let mut flag = true;
    let mut total = 0.0;

    while flag {
        
        if counter==20 {
            flag = false
        }
        else{

        let response_time = marketplace(&client).await?;
        println!("Difference->{:?}",response_time.as_secs_f64());
        total += response_time.as_secs_f64();
        counter +=1

        }




    }
    println!("Total fetch reqwest {} ",total);
    println!("Count reqwest {}",counter);
    println!("Avarage Time reqwest {}",total/counter as f64);
    
    Ok(())

}


pub async fn marketplace(client: &Client) -> Result<Duration,reqwest::Error> {
    let now = Instant::now();

    let resp = client
        .get("https://api.shadowpay.com/api/market/get_items?currency=USD&sort_column=price_rate&sort_dir=desc&search=&stack=false&offset=150&limit=50&sort=desc&game=csgo")
        .version(Version::HTTP_11)
        .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")
        .header("accept-language", "tr-TR,tr;q=0.9,en-US;q=0.8,en;q=0.7")
        .header("authority", "api.shadowpay.com")
        .header("origin", "https://shadowpay.com/")
        .header("authorization", "Bearer")
        .header("referer", "https://shadowpay.com/")
        .send()
        .await?;

        println!("{:?}",resp.version());

        let result = resp.json::<Value>()
        .await?;

        let elapsed = now.elapsed();
        Ok(elapsed)
    }


For TCP keepalive, you need to set a duration value as it defaults to disabled: client.rs - source

For the HTTP/1, you should use ClientBulider::http1_only() instead of trying to set the version on a per-request basis (I'm not sure why that code is there, it seems to be ignored): ClientBuilder in reqwest - Rust

But there is something wrong when i try same for http2.0, for example when i want to use http2.0 and set http2_prior_knowledge to ClientBuilder it giving FRAME_SIZE_ERROR but instead when i set for per request as i did in my code its fine with that. I am little confused.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.