wjones127 commented on code in PR #8:
URL: https://github.com/apache/arrow-experiments/pull/8#discussion_r1520114945


##########
http/get_simple/rs/client/src/main.rs:
##########
@@ -0,0 +1,106 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use arrow_ipc::reader::StreamReader;
+use std::{
+    io::{BufRead, BufReader, Read, Write},
+    net::{IpAddr, Ipv4Addr, SocketAddr, TcpStream},
+};
+use tracing::{error, info, info_span};
+use tracing_subscriber::fmt::format::FmtSpan;
+
+fn main() {
+    // Configure tracing subscriber.
+    tracing_subscriber::fmt()
+        .with_span_events(FmtSpan::CLOSE)
+        .init();
+
+    info_span!("get_simple").in_scope(|| {
+        // Connect to server.
+        let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), 8000);
+        match TcpStream::connect(addr) {
+            Ok(mut stream) => {
+                info_span!("Reading Arrow IPC stream", %addr).in_scope(|| {
+                    info!("Connected");
+
+                    // Send request.
+                    stream
+                        .write_all(format!("GET / HTTP/1.1\r\nHost: 
{addr}\r\n\r\n").as_bytes())
+                        .unwrap();
+
+                    // Ignore response header.
+                    let mut reader = BufReader::new(&mut stream);
+                    let mut chunked = false;
+                    loop {
+                        let mut line = String::default();
+                        reader.read_line(&mut line).unwrap();
+                        if let Some(("transfer-encoding", "chunked")) = line
+                            .to_lowercase()
+                            .split_once(':')
+                            .map(|(key, value)| (key.trim(), value.trim()))
+                        {
+                            chunked = true;
+                        }
+                        if line == "\r\n" {
+                            break;
+                        }
+                    }

Review Comment:
   It feels a bit sad we are manually parsing headers and such. Makes the 
example a bit harder to follow.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to