codecrafters-io / build-your-own-http-server Goto Github PK
View Code? Open in Web Editor NEWDefinition for the http-server challenge.
Home Page: https://app.codecrafters.io/courses/http-server/overview
License: MIT License
Definition for the http-server challenge.
Home Page: https://app.codecrafters.io/courses/http-server/overview
License: MIT License
(Using C++)
I tried to use std::format but it looks like you have an older compiler on here.
Thanks to @shawlynot for reporting this!
Feedback from one user:
I noticed a minor issue in the HTTP server challenge. The examples have a blank line between the start line and headers but the spec does not specify that: https://datatracker.ietf.org/doc/html/rfc9112#name-message-format
Also, there's the following statement in the spec:
A sender MUST NOT send whitespace between the start-line and the first header field.
Similar feedback from another user:
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.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.