[wip] Making initial HTTP request

This commit is contained in:
Adam Cooper 2021-12-15 22:59:53 -05:00
parent 585b247297
commit bcd5090ebd

View file

@ -17,13 +17,28 @@ fn publicise() {
} }
#[allow(unused)] #[allow(unused)]
async fn traverse(password: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>> { async fn get_folder_contents(password: String, url_tail: &str) -> Result<reqwest::Response, Box<dyn std::error::Error>> {
debug!("Entering: get_folder_contents()");
let root_url = "https://theadamcooper.com"; let root_url = "https://theadamcooper.com";
let url_tail = "/nextcloud/remote.php/dav/files/adam/public";
let method = reqwest::Method::from_bytes(b"PROPFIND").unwrap(); let method = reqwest::Method::from_bytes(b"PROPFIND").unwrap();
let client = reqwest::Client::new(); let client = reqwest::Client::new();
let response = client.request(method, root_url) let url = format!("{}{}", root_url, url_tail);
debug!("url: {}", url);
let body = String::from(r#"<?xml version="1.0" encoding="UTF-8"?>
<d:propfind xmlns:d="DAV:">
<d:prop xmlns:oc="http://owncloud.org/ns">
<d:getlastmodified/>
<d:getcontentlength/>
<d:getcontenttype/>
<oc:permissions/>
<d:resourcetype/>
<d:getetag/>
<oc:share-types/>
</d:prop>
</d:propfind>"#);
let response = client.request(method, url)
.basic_auth("adam", Some(password)) .basic_auth("adam", Some(password))
.body(body)
.send() .send()
.await?; .await?;
debug!("{:?}", response); debug!("{:?}", response);
@ -41,9 +56,14 @@ fn get_password() -> Result<String, std::io::Error> {
} }
} }
fn main() { #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::Builder::from_env(Env::default().default_filter_or("trace")).target(Target::Stdout).init(); env_logger::Builder::from_env(Env::default().default_filter_or("trace")).target(Target::Stdout).init();
println!("Publicise it!"); println!("Publicise it!");
let password = get_password().unwrap(); let password = get_password().unwrap();
debug!("Received password: {}", password); debug!("Received password: {}", password);
let folder_contents = get_folder_contents(password, "/nextcloud/remote.php/dav/files/adam/public").await?;
debug!("{:?}", folder_contents);
Ok(())
} }