Extract URL Path

Stuck at this stage.

Here’s the code (Rust) :

use std::io::{BufRead, BufReader, Read, Write};
#[allow(unused_imports)]
use std::net::TcpListener;
fn main() {
    let listener = TcpListener::bind("127.0.0.1:4221").unwrap();
    for stream in listener.incoming() {
        match stream {
            Ok(mut stream) => {
                let buf_reader = std::io::BufReader::new(&mut stream);
                let request_line = buf_reader.lines().next().unwrap().unwrap();
                let response = match request_line.as_str() {    
                    "GET / HTTP/1.1" => "HTTP/1.1 200 OK\r\n\r\n",
                    _ => "HTTP/1.1 404 Not Found\r\n\r\n",
                };
                stream.write_all(response.as_bytes()).unwrap();
            }
            Err(e) => {
                println!("error: {}", e);
            }
        }
    }
}

Error:

remote: [compile]    Compiling codecrafters-http-server v0.1.0 (/app)
remote: [compile] warning: unused `Result` that must be used
remote: [compile]   --> src/main.rs:16:17
remote: [compile]    |
remote: [compile] 16 |                 stream.write("HTTP/1.1 200 OK\r\n\r\n".as_bytes());
remote: [compile]    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
remote: [compile]    |
remote: [compile]    = note: this `Result` may be an `Err` variant, which should be handled
remote: [compile]    = note: `#[warn(unused_must_use)]` on by default
remote: [compile] help: use `let _ = ...` to ignore the resulting value
remote: [compile]    |
remote: [compile] 16 |                 let _ = stream.write("HTTP/1.1 200 OK\r\n\r\n".as_bytes());
remote: [compile]    |                 +++++++
remote: [compile]
remote: [compile] warning: `codecrafters-http-server` (bin "codecrafters-http-server") generated 1 warning
remote: [compile]     Finished `release` profile [optimized] target(s) in 0.96s
remote: [compile] Moved ./.codecrafters/run.sh → ./your_program.sh
remote: [compile] Compilation successful.

FYI: I am not using stream.write() but i am using stream.write_all(), don’t why it’s considering stream.write() and throwing error.

@Himanshu-7-Clou, could you upload your code to GitHub and share the link? It will be much easier to debug if I can run it directly.

Hey @andy1li , here’s the link - GitHub - Himanshu-7-Clou/extract-url

@Himanshu-7-Clou, I ran the code from your GitHub repo, and it passed the stage #ih0 Extract URL path:

Could you try cloning your repo from our server again and see if it contains an older version of your code?

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.