Skip to content

Commit

Permalink
Add support for did:web with port (#519)
Browse files Browse the repository at this point in the history
Close #460

Co-authored-by: Simon Bihel <[email protected]>
  • Loading branch information
TaylorBeeston and sbihel authored Jul 14, 2023
1 parent af8d958 commit db906df
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
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

0 comments on commit db906df

Please sign in to comment.