Coder Social home page Coder Social logo

codecrafters-io / build-your-own-http-server Goto Github PK

View Code? Open in Web Editor NEW
15.0 15.0 10.0 209 KB

Definition for the http-server challenge.

Home Page: https://app.codecrafters.io/courses/http-server/overview

License: MIT License

Go 3.74% Shell 16.42% Python 2.71% Rust 4.28% Dockerfile 22.01% JavaScript 2.51% Haskell 8.71% Java 5.45% C 12.43% CMake 1.50% C++ 12.29% C# 2.31% Ruby 3.16% TypeScript 2.49%

build-your-own-http-server's People

Contributors

libmartinito avatar nixypanda avatar rohitpaulk avatar ryan-gang avatar urielsalis avatar vic-ma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

build-your-own-http-server's Issues

Include program args in logs

We don't seem to be including the args passed to the program in logs. Let's include this as an info logs, formatted as a shell command like we do in the Redis challenge:

Screenshot 2024-03-06 at 11 35 25

Here are what the current logs looks like:

Screenshot 2024-03-06 at 11 40 59

Flakiness with stage 2

Looks like a certain submission failed tests the stage 2, but passed after re-running with debug mode.

Here's the code:

use std::{
    io::Write,
    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 response = format!("HTTP/1.1 200 OK\r\n\r\n");
                stream.write_all(response.as_bytes()).unwrap();
            }
            Err(_) => println!("OOF"),
        }
    }
}

Here's the error when it fails:

[stage-2] Running tests for Stage #2: Respond with 200
[stage-2] Running program
[stage-2] You can use the following curl command to test this locally
[stage-2] $ curl -v -X GET http://localhost:4221/
[stage-2] Sending request (status line): GET / HTTP/1.1
[stage-2] Sending request: (Messages with >>> prefix are part of this log)
[stage-2] >>> GET / HTTP/1.1
[stage-2] >>> Host: localhost:4221
[stage-2] >>> User-Agent: Go-http-client/1.1
[stage-2] >>> Accept-Encoding: gzip
[stage-2] >>> 
[stage-2] >>> 
[stage-2] Failed to dump rsponse: 'read tcp 127.0.0.1:35934->127.0.0.1:4221: read: connection reset by peer'
[stage-2] Test failed
[stage-2] Terminating program
[stage-2] Program terminated successfully

And here are the logs when it passes (with zero code changes):

[stage-2] Running tests for Stage #2: Respond with 200
[stage-2] Running program
[stage-2] You can use the following curl command to test this locally
[stage-2] $ curl -v -X GET http://localhost:4221/
[stage-2] Sending request (status line): GET / HTTP/1.1
[stage-2] Sending request: (Messages with >>> prefix are part of this log)
[stage-2] >>> GET / HTTP/1.1
[stage-2] >>> Host: localhost:4221
[stage-2] >>> User-Agent: Go-http-client/1.1
[stage-2] >>> Accept-Encoding: gzip
[stage-2] >>> 
[stage-2] >>> 
[stage-2] Received response: (Messages with >>> prefix are part of this log)
[stage-2] >>> HTTP/1.1 200 OK
[stage-2] >>> Connection: close
[stage-2] >>> 
[stage-2] >>> 
[stage-2] Test passed.
[stage-2] Terminating program
[stage-2] Program terminated successfully

This is very easy to replicate - happens pretty often, so isn't an edge case that is improbable. Since this is an early stage, we should see what we can do to make this more predictable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.