Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extending timeout during body read #594

Open
PAStheLoD opened this issue Feb 19, 2023 · 3 comments
Open

extending timeout during body read #594

PAStheLoD opened this issue Feb 19, 2023 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@PAStheLoD
Copy link

Hello,

I'm writing an SSE (server-sent events) client that processes a chunked response, with a server-supplied expected max time. So it'd be great to be able to reset the timeout when a new message is received. Is this possible currently? (If not then this is a request for enhancement :))

Last but not least, many thanks for this great library!

@algesten
Copy link
Owner

Hello @PAStheLoD! Welcome to ureq!

Do I get this right, you want to be able to set the socket.set_read_timeout(n) also after you sent the request, i.e. when you have the Response object?

@PAStheLoD
Copy link
Author

I'm not familiar with the low-level API, but something like that, yes :)

An excerpt from the current version:

use std::io::{BufRead, BufReader, Write};


// ...

    let result = ureq::get(&conf.url)
        .timeout(Duration::from_secs(conf.first_byte_timeout_sec as u64))
        .call();



     match result {
         Ok(response) => process(response)
         Err ...
     }


fn process(response: Response) {
    let mut buf: Vec<String> = Vec::with_capacity(10);

    let reader = response.into_reader();
  
    let bufreader = BufReader::new(reader);

    for line in bufreader.lines() {
        // match ..
        // ... I guess this is where I'd reset the timeout after each "line"
    }
}

Thanks again!

@algesten algesten added the help wanted Extra attention is needed label Nov 26, 2024
@algesten
Copy link
Owner

Help wanted. It can be implemented using Body::reset_body_timeout() or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants