Skip to content

Commit

Permalink
fix: remote url in config is read as file (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
laststylebender14 authored May 2, 2024
1 parent 276a612 commit fc96336
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/config/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rustls_pemfile;
use rustls_pki_types::{
CertificateDer, PrivateKeyDer, PrivatePkcs1KeyDer, PrivatePkcs8KeyDer, PrivateSec1KeyDer,
};
use url::Url;

use super::{ConfigModule, Content, Link, LinkType};
use crate::config::{Config, ConfigReaderContext, Source};
Expand Down Expand Up @@ -233,10 +234,12 @@ impl ConfigReader {
Ok(config_module)
}

/// Checks if path is absolute else it joins file path with relative dir
/// path
/// Checks if path is a URL or absolute path, returns directly if so.
/// Otherwise, it joins file path with relative dir path.
fn resolve_path(src: &str, root_dir: Option<&Path>) -> String {
if Path::new(&src).is_absolute() {
if let Ok(url) = Url::parse(src) {
url.to_string()
} else if Path::new(&src).is_absolute() {
src.to_string()
} else {
let path = root_dir.unwrap_or(Path::new(""));
Expand Down Expand Up @@ -361,13 +364,18 @@ mod reader_tests {
let path_dir = Path::new("abc/xyz");
let file_relative = "foo/bar/my.proto";
let file_absolute = "/foo/bar/my.proto";
let remote_url_path = "https://raw.githubusercontent.com/tailcallhq/tailcall/main/tailcall-fixtures/fixtures/protobuf/news.proto";
assert_eq!(
path_dir.to_path_buf().join(file_relative),
PathBuf::from(ConfigReader::resolve_path(file_relative, Some(path_dir)))
);
assert_eq!(
"/foo/bar/my.proto",
file_absolute,
ConfigReader::resolve_path(file_absolute, Some(path_dir))
);
assert_eq!(
remote_url_path,
ConfigReader::resolve_path(remote_url_path, Some(path_dir))
);
}
}

1 comment on commit fc96336

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running 30s test @ http://localhost:8000/graphql

4 threads and 100 connections

Thread Stats Avg Stdev Max +/- Stdev
Latency 7.58ms 3.55ms 111.91ms 73.46%
Req/Sec 3.34k 273.26 3.75k 85.00%

399280 requests in 30.01s, 2.00GB read

Requests/sec: 13305.82

Transfer/sec: 68.29MB

Please sign in to comment.