ureq icon indicating copy to clipboard operation
ureq copied to clipboard

interrupt redirects or save all cookies per redirect

Open cyberpunkbln opened this issue 2 years ago • 5 comments

Hello,

i have a little problem. UReq takes all redirects and after the request it is an 200.statuscode. I wish i can interrupting each redirect per an iteration or so.

Or ist it possible to save all cookies per redirect individual?

thx

cyberpunkbln avatar Dec 21 '22 21:12 cyberpunkbln

Hi!

You can stop the redirects by setting the redirect count to 0 on agent.

Check out AgentBuilder::redirects

algesten avatar Dec 21 '22 22:12 algesten

@algesten Thx, wonderful, but now, after heavy experimenting, i want to use the cookie_store in an agent (ureq::Builder) for read (after redirect interruption where i have save the cookies) and became this error message:

.cookie_store(my_store)
    |      ------------ ^^^^^^^^ expected struct `cookie_store::cookie_store::CookieStore`, found struct `CookieStore`

is the new agent for the next location-request after saving the cookiestore

ps: some code from my project:

let file = File::open("cookies_agent.json").unwrap();
	let read = std::io::BufReader::new(file);
	let my_store = CookieStore::load_json(read).unwrap();
let agent = ureq::builder()
    .redirects(0)
	.cookie_store(my_store)
    .build();
	let response = agent.get(&gogUri)
	.call().unwrap();
	for variable in response.headers_names()
	{
		println!("{:?} - {:?}", variable, response.header(&variable).unwrap());
	}

cyberpunkbln avatar Dec 21 '22 22:12 cyberpunkbln

Can you share the full code from your project? Debugging the error you shared requires looking at the imports.

jsha avatar Dec 22 '22 01:12 jsha

@jsha hi, sure the imports i have forgot:

extern crate ureq;
extern crate serde_json;
extern crate select;
extern crate cookie_store;

use std::fs::File;
use std::io;

use cookie_store::CookieStore;
use select::{document::*, predicate::*};
use regex::*;

At the moment i use .set("Cookie") and use my own cookies->string but i love the idea from CookieStore and the agents. #548 this is not the issue with my problem, or?

cyberpunkbln avatar Dec 22 '22 17:12 cyberpunkbln

The actual git version accept my my_store variable but i have another issue with the git version. Give it an middleway, that the cookiestore handling from git version can included in the 2.5.1 or so?

cyberpunkbln avatar Dec 22 '22 20:12 cyberpunkbln

Closing since we're moving to ureq 3.x.

algesten avatar Aug 13 '24 17:08 algesten