# Extract URL Path

**URL:** <https://forum.codecrafters.io/t/extract-url-path/8502>\
**Category:** Challenges\
**Tags:** challenge:http-server\
**Created:** [April 9, 2025, 4:58pm UTC](https://forum.codecrafters.io/t/extract-url-path/8502 "2025-04-09T16:58:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Himanshu-7-Clou](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/himanshu-7-clou/32/7822_2.png) [@Himanshu-7-Clou](https://forum.codecrafters.io/u/Himanshu-7-Clou)\
**Post date:** [April 9, 2025, 4:58pm UTC](https://forum.codecrafters.io/t/extract-url-path/8502/1 "2025-04-09T16:58:23Z")

</div>

Stuck at this stage.

Here’s the code (Rust) :

```auto
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:

```auto
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.

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 9, 2025, 5:59pm UTC](https://forum.codecrafters.io/t/extract-url-path/8502/3 "2025-04-09T17:59:28Z")

</div>

@Himanshu-7-Clou, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<div class="post-metadata">

**Author:** ![Himanshu-7-Clou](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/himanshu-7-clou/32/7822_2.png) [@Himanshu-7-Clou](https://forum.codecrafters.io/u/Himanshu-7-Clou)\
**Post date:** [April 11, 2025, 12:07pm UTC](https://forum.codecrafters.io/t/extract-url-path/8502/4 "2025-04-11T12:07:20Z")

</div>

Hey @andy1li , here’s the link - [GitHub - Himanshu-7-Clou/extract-url](https://github.com/Himanshu-7-Clou/extract-url.git)

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 11, 2025, 6:16pm UTC](https://forum.codecrafters.io/t/extract-url-path/8502/6 "2025-04-11T18:16:41Z")

</div>

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

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/4/4d898ea49ab2cdb6a25939d1e4c2d63cb99cf089.png)

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

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/3/371ac206c219053edf368d8bced799ba0be2ca4b.png)

---

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [April 20, 2025, 9:01am UTC](https://forum.codecrafters.io/t/extract-url-path/8502/8 "2025-04-20T09:01:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [April 25, 2025, 9:02am UTC](https://forum.codecrafters.io/t/extract-url-path/8502/9 "2025-04-25T09:02:24Z")

</div>

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