http-useragent
http-useragent copied to clipboard
Timeout support
HTTP::UserAgent should have timeout feature.
Hi, it probably should, however I don''t think the IO::Socket::INET supports a timeout currentlly and I'm not sure if there's a nice way to do it otherwise.
But of course if you have a suggestion .....
I've had a think about this and I think it can be implemented with a small bit of asynchronous code to perform the timeout.
I want to do some refactoring around the request() method first so that I can isolate the connection parts in its own method first.
I've tried this before but it did not seem to actually work
await Promise.anyof(
Promise.in(60),
start {
# make request
},
);
@ugexe yeah that's https://rt.perl.org/Ticket/Display.html?id=126390 but for me:
await Promise.anyof(Promise.in(60), start {
my $sock = IO::Socket::INET.new(host => 'localhost', port => 80, timeout => 10);
$sock.print("GET /\r\n\r\n");
say $sock.recv(:bin);
$sock.close;
});
Works fine here. Obviously that's somewhat different to the actually code but you get the idea.