mirror of
https://github.com/storytold/artcraft.git
synced 2026-11-05 17:58:55 +00:00
wip
This commit is contained in:
1 parent
8c0358009a
commit
bce628bdac
2 files changed
+61
-2
No files matched your search
+45
@@ -27,6 +27,7 @@ pub async fn create_listen_websocket_new_raw() -> Result<(), GrokError> {
|
||||
let mut client_builder = Client::builder()
|
||||
.emulation(Emulation::Firefox143)
|
||||
.default_headers(HeaderMap::new())
|
||||
.cookie_store(true)
|
||||
.connection_verbose(true)
|
||||
.connect_timeout(Duration::from_secs(10));
|
||||
|
||||
@@ -45,6 +46,17 @@ pub async fn create_listen_websocket_new_raw() -> Result<(), GrokError> {
|
||||
.build()
|
||||
.map_err(|err| GrokClientError::WreqClientError(err))?;
|
||||
|
||||
println!();
|
||||
println!();
|
||||
let result = request_tasks(&client).await;
|
||||
println!();
|
||||
println!();
|
||||
|
||||
match result {
|
||||
Ok(_) => println!("Request tasks succeeded"),
|
||||
Err(err) => println!("Request tasks failed: {:?}", err),
|
||||
}
|
||||
|
||||
//.http1_only() // NB: Not needed - websockets are sent over HTTP/1.1 without this configuration
|
||||
//.cookie_store(true)
|
||||
|
||||
@@ -96,6 +108,39 @@ pub async fn create_listen_websocket_new_raw() -> Result<(), GrokError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn request_tasks(client: &Client) -> Result<(), GrokError> {
|
||||
const TASKS_URL: &str = "https://grok.com/rest/tasks";
|
||||
|
||||
let builder = client.get(TASKS_URL)
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(USER_AGENT, FIREFOX_143_MAC_USER_AGENT)
|
||||
.header(ACCEPT_LANGUAGE, "en-US,en;q=0.5")
|
||||
.header(ACCEPT_ENCODING, "gzip, deflate, br, zstd")
|
||||
.header(ORIGIN, "https://grok.com")
|
||||
.header(COOKIE, SESSION_COOKIES_WITHOUT_CF_CLEARANCE)
|
||||
.header(PRAGMA, "no-cache")
|
||||
.header(CACHE_CONTROL, "no-cache");
|
||||
|
||||
let response = builder.send()
|
||||
.await
|
||||
.map_err(|err| GrokClientError::WreqClientError(err))?;
|
||||
|
||||
println!("Tasks response version: {:?}", response.version());
|
||||
|
||||
let status = response.status();
|
||||
println!("Tasks Status: {}", status);
|
||||
|
||||
for cookie in response.cookies() {
|
||||
println!("Tasks cookie: {}={}", cookie.name(), cookie.value());
|
||||
}
|
||||
|
||||
for (name, value) in response.headers() {
|
||||
println!("Tasks header: {}: {}", name.as_str(), value.to_str().unwrap());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
+16
-2
@@ -1,8 +1,8 @@
|
||||
use crate::error::grok_client_error::GrokClientError;
|
||||
use crate::error::grok_error::GrokError;
|
||||
use std::time::Duration;
|
||||
use wreq::header::USER_AGENT;
|
||||
use wreq::Client;
|
||||
use wreq::header::{HeaderMap, USER_AGENT};
|
||||
use wreq::{Client, Proxy};
|
||||
use wreq_util::Emulation;
|
||||
|
||||
const FINGERPRINT_URL : &str = "https://tools.scrapfly.io/api/tls";
|
||||
@@ -34,6 +34,20 @@ fn build_firefox_143_client() -> Result<Client, GrokError> {
|
||||
.map_err(|err| GrokClientError::WreqClientError(err))?)
|
||||
}
|
||||
|
||||
fn build_raw_firefox_client_with_proxy() -> Result<Client, GrokError> {
|
||||
let proxy = Proxy::https("http://127.0.0.1:8080")
|
||||
.map_err(|err| GrokClientError::WreqClientError(err))?;
|
||||
Ok(Client::builder()
|
||||
.emulation(Emulation::Firefox143)
|
||||
.default_headers(HeaderMap::new())
|
||||
.proxy(proxy)
|
||||
.cert_verification(false)
|
||||
.connection_verbose(true)
|
||||
.connect_timeout(Duration::from_secs(10))
|
||||
.build()
|
||||
.map_err(|err| GrokClientError::WreqClientError(err))?)
|
||||
}
|
||||
|
||||
async fn get_with_client(client: &Client) -> Result<String, GrokError> {
|
||||
let builder = client.get(FINGERPRINT_URL)
|
||||
.header("Accept", "application/json");
|
||||
|
||||
Reference in new issue
Block a user