Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow resolving did:webs with ports #519

Merged
merged 3 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion did-web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "did-web"
version = "0.2.1"
version = "0.2.2"
authors = ["Spruce Systems, Inc."]
edition = "2021"
license = "Apache-2.0"
Expand Down
18 changes: 14 additions & 4 deletions did-web/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@ fn did_web_url(did: &str) -> Result<String, ResolutionMetadata> {
None => ".well-known".to_string(),
};
// Use http for localhost, for testing purposes.
let proto = if domain_name == "localhost" {
let proto = if domain_name.starts_with("localhost") {
"http"
} else {
"https"
};
#[allow(unused_mut)]
let mut url = format!("{}://{}/{}/did.json", proto, domain_name, path);
let mut url = format!(
"{}://{}/{}/did.json",
proto,
domain_name.replacen("%3A", ":", 1),
path
);
#[cfg(test)]
PROXY.with(|proxy| {
if let Some(ref proxy) = *proxy.borrow() {
Expand Down Expand Up @@ -128,8 +133,8 @@ impl DIDResolver for DIDWeb {
Err(err) => {
return (
ResolutionMetadata::from_error(&format!(
"Error sending HTTP request : {}",
err
"Error sending HTTP request ({}): {}",
url, err
)),
Vec::new(),
None,
Expand Down Expand Up @@ -206,6 +211,11 @@ mod tests {
did_web_url("did:web:example.com:u:bob").unwrap(),
"https://example.com/u/bob/did.json"
);
// https://w3c-ccg.github.io/did-method-web/#example-creating-the-did-with-optional-path-and-port
assert_eq!(
did_web_url("did:web:example.com%3A443:u:bob").unwrap(),
"https://example.com:443/u/bob/did.json"
);
}

const DID_URL: &str = "http://localhost/.well-known/did.json";
Expand Down