You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2024/01/20 10:48:07 UTC

(arrow-rs) branch master updated: Test parse_url_opts for HTTP (#5310) (#5316)

This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new b03613eb00 Test parse_url_opts for HTTP (#5310) (#5316)
b03613eb00 is described below

commit b03613eb002302a85f5761f2b16753d4777552e5
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Sat Jan 20 10:48:01 2024 +0000

    Test parse_url_opts for HTTP (#5310) (#5316)
    
    * Test parse_url_opts for HTTP (#5310)
    
    * Format
---
 object_store/src/parse.rs | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/object_store/src/parse.rs b/object_store/src/parse.rs
index 47e537cc9f..116c2ad2ac 100644
--- a/object_store/src/parse.rs
+++ b/object_store/src/parse.rs
@@ -109,7 +109,7 @@ impl ObjectStoreScheme {
 macro_rules! builder_opts {
     ($builder:ty, $url:expr, $options:expr) => {{
         let builder = $options.into_iter().fold(
-            <$builder>::new().with_url($url.as_str()),
+            <$builder>::new().with_url($url.to_string()),
             |builder, (key, value)| match key.as_ref().parse() {
                 Ok(k) => builder.with_config(k, value),
                 Err(_) => builder,
@@ -164,6 +164,7 @@ where
         }
         #[cfg(feature = "http")]
         ObjectStoreScheme::Http => {
+            let url = &url[..url::Position::BeforePath];
             builder_opts!(crate::http::HttpBuilder, url, _options)
         }
         #[cfg(not(all(feature = "aws", feature = "azure", feature = "gcp", feature = "http")))]
@@ -305,4 +306,28 @@ mod tests {
         let (_, path) = parse_url(&url).unwrap();
         assert_eq!(path.as_ref(), "my file with spaces");
     }
+
+    #[tokio::test]
+    #[cfg(feature = "http")]
+    async fn test_url_http() {
+        use crate::client::mock_server::MockServer;
+        use hyper::{header::USER_AGENT, Body, Response};
+
+        let server = MockServer::new();
+
+        server.push_fn(|r| {
+            assert_eq!(r.uri().path(), "/foo/bar");
+            assert_eq!(r.headers().get(USER_AGENT).unwrap(), "test_url");
+            Response::new(Body::empty())
+        });
+
+        let test = format!("{}/foo/bar", server.url());
+        let opts = [("user_agent", "test_url"), ("allow_http", "true")];
+        let url = test.parse().unwrap();
+        let (store, path) = parse_url_opts(&url, opts).unwrap();
+        assert_eq!(path.as_ref(), "foo/bar");
+        store.get(&path).await.unwrap();
+
+        server.shutdown().await;
+    }
 }