Compare commits
5 commits
2aeed9773f
...
3cfc86a8fd
Author | SHA1 | Date | |
---|---|---|---|
3cfc86a8fd | |||
dba9a93e2e | |||
76783eabe4 | |||
a74ee45f6e | |||
0001c43f79 |
2 changed files with 32 additions and 10 deletions
|
@ -82,8 +82,12 @@ impl HostMetaDocument {
|
||||||
let mime_type = extract_mime_from_content_type(content_type)
|
let mime_type = extract_mime_from_content_type(content_type)
|
||||||
.ok_or(ContentTypeInvalid)?;
|
.ok_or(ContentTypeInvalid)?;
|
||||||
|
|
||||||
log::trace!("Ensuring MIME type of `{mime_type}` is acceptable for JRD parsing...");
|
log::trace!("Ensuring MIME type is acceptable for JRD parsing...");
|
||||||
if mime_type != "application/json" {
|
if mime_type == "application/jrd+json" {
|
||||||
|
log::warn!("MIME type `{mime_type}` would not be acceptable for JRD parsing, but is temporarily allowed anyways due to widespread use.")
|
||||||
|
}
|
||||||
|
else if mime_type != "application/json" {
|
||||||
|
log::error!("MIME type `{mime_type}` is not acceptable for JRD parsing.");
|
||||||
return Err(ContentTypeInvalid)
|
return Err(ContentTypeInvalid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,20 @@
|
||||||
|
const CARGO_PKG_NAME: &str = env!("CARGO_PKG_NAME");
|
||||||
|
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
const CARGO_PKG_REPOSITORY: &str = env!("CARGO_PKG_REPOSITORY");
|
||||||
|
|
||||||
|
|
||||||
|
fn init_log() {
|
||||||
|
let mut builder = pretty_env_logger::formatted_builder();
|
||||||
|
builder.filter_level(log::LevelFilter::max());
|
||||||
|
builder.is_test(true);
|
||||||
|
|
||||||
|
if builder.try_init().is_ok() {
|
||||||
|
log::debug!("Initialized logging!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn make_client() -> reqwest::Client {
|
fn make_client() -> reqwest::Client {
|
||||||
let crate_name = env!("CARGO_PKG_NAME");
|
let user_agent = format!("{CARGO_PKG_NAME}/{CARGO_PKG_VERSION} ({CARGO_PKG_REPOSITORY})");
|
||||||
let crate_version = env!("CARGO_PKG_VERSION");
|
|
||||||
let crate_repository = env!("CARGO_PKG_REPOSITORY");
|
|
||||||
let user_agent = format!("{crate_name}/{crate_version} ({crate_repository})");
|
|
||||||
|
|
||||||
reqwest::Client::builder()
|
reqwest::Client::builder()
|
||||||
.user_agent(user_agent)
|
.user_agent(user_agent)
|
||||||
|
@ -22,6 +34,7 @@ macro_rules! test {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
$(#[$tag])*
|
$(#[$tag])*
|
||||||
async fn test_hostmeta() {
|
async fn test_hostmeta() {
|
||||||
|
init_log();
|
||||||
let client = make_client();
|
let client = make_client();
|
||||||
|
|
||||||
let base: reqwest::Url = $url.parse()
|
let base: reqwest::Url = $url.parse()
|
||||||
|
@ -31,12 +44,13 @@ macro_rules! test {
|
||||||
.await
|
.await
|
||||||
.expect("host-meta discovery to succeed");
|
.expect("host-meta discovery to succeed");
|
||||||
|
|
||||||
println!("{doc:#?}");
|
log::info!("Parsed host-meta document: {doc:#?}");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
$(#[$tag])*
|
$(#[$tag])*
|
||||||
async fn test_nodeinfo() {
|
async fn test_nodeinfo() {
|
||||||
|
init_log();
|
||||||
let client = make_client();
|
let client = make_client();
|
||||||
|
|
||||||
let base: reqwest::Url = $url.parse()
|
let base: reqwest::Url = $url.parse()
|
||||||
|
@ -44,9 +58,9 @@ macro_rules! test {
|
||||||
|
|
||||||
let doc = HostMetaDocument::discover_nodeinfo(&client, base)
|
let doc = HostMetaDocument::discover_nodeinfo(&client, base)
|
||||||
.await
|
.await
|
||||||
.expect("host-meta discovery to succeed");
|
.expect("nodeinfo discovery to succeed");
|
||||||
|
|
||||||
println!("{doc:#?}");
|
log::info!("Parsed nodeinfo document: {doc:#?}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -62,6 +76,10 @@ test!(iceshrimpnet, "https://ice.frieren.quest");
|
||||||
|
|
||||||
test!(gotosocial, "https://alpha.polymaths.social");
|
test!(gotosocial, "https://alpha.polymaths.social");
|
||||||
|
|
||||||
test!(bridgyfed, "https://fed.brid.gy", ignore = "Returns application/jrd+json");
|
test!(bridgyfed, "https://fed.brid.gy");
|
||||||
|
|
||||||
test!(threads, "https://threads.net", ignore = "Not implemented on their end");
|
test!(threads, "https://threads.net", ignore = "Not implemented on their end");
|
||||||
|
|
||||||
|
test!(snac, "https://ngoa.giao.loan", ignore = "Does not support host-meta");
|
||||||
|
|
||||||
|
test!(hollo, "https://hollo.social", ignore = "Does not support host-meta");
|
||||||
|
|
Loading…
Reference in a new issue