Http Server: Stuck in "Extract URL Path". Working in my local

I’m stuck on Stage #(IH0).

I’ve tried .. using both PrintWrite and Buffered Reader to print the output and it is working fine in my local.

Here are my logs in local:

curl -v http://localhost:4221/mango
* Host localhost:4221 was resolved.
* IPv6: ::1
* IPv4: 127.0.0.1
*   Trying [::1]:4221...
* Connected to localhost (::1) port 4221
> GET /mango HTTP/1.1
> Host: localhost:4221
> User-Agent: curl/8.7.1
> Accept: */*
> 
* Request completely sent off
< HTTP/1.1 404 Not Found
< 
* no chunk, no close, no size. Assume close to signal end

* Closing connection

And here’s a snippet of my code:

System.out.println("Logs from your program will appear here!");

		// Uncomment this block to pass the first stage

		try {
			ServerSocket serverSocket = new ServerSocket(4221);

			// Since the tester restarts your program quite often, setting SO_REUSEADDR
			// ensures that we don't run into 'Address already in use' errors
			serverSocket.setReuseAddress(true);

			// Wait for connection from client.
			// serverSocket.accept();

			var clientSocket = serverSocket.accept();
			BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
//				BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
			PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);

			String requestLine = in.readLine();

			String[] requestParts = requestLine.split(" ");

			String pathParams = requestParts[1];

			String httpResponse;
			if (pathParams.equals("/") || pathParams.isBlank()) {
				httpResponse = "HTTP/1.1 200 OK\r\n\r\n";
			} else {
				httpResponse = "HTTP/1.1 404 Not Found\r\n\r\n";
			}

			out.println(httpResponse);
//				out.flush();
			clientSocket.close();

			System.out.println("Response Message has been sent back to the client");
		} catch (IOException e) {
			System.out.println("IOException: " + e.getMessage());
		}

It is showing Tests Failed and it is unable to pick the new code in the codecrafters UI.

[tester::#IH0] Running tests for Stage #IH0 (Extract URL path)
[tester::#IH0] $ ./your_program.sh
[your_program] Logs from your program will appear here!
[tester::#IH0] $ curl -v http://localhost:4221/mango
[your_program] Modified message has been sent to the client
[tester::#IH0] Expected status code 404, got 200
[tester::#IH0] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)

Github link: GitHub - Vaibhav-Somani/codecrafters-http-server-java: Learning 101

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

Hello @andy1li
Here it is: GitHub - Vaibhav-Somani/codecrafters-http-server-java: Learning 101

@Vaibhav-Somani, I ran your code on our tester and it worked fine. Could you try running it again and let me know if the issue persists?

Hello @andy1li It is not working. Looks like it is not even picking up the new code. It is showing tests failed in the UI with following logs. The log statement at the end has been updated from past few commits. I even modified the debug to be true in the yml file but even that is not working. Following are the failure logs:

[compile] [INFO] 
[compile] [INFO] --------------< io.codecrafters:codecrafters-http-server >--------------
[compile] [INFO] Building codecrafters-http-server 1.0
[compile] [INFO]   from pom.xml
[compile] [INFO] --------------------------------[ jar ]---------------------------------
[compile] [INFO] 
[compile] [INFO] --- resources:3.3.1:resources (default-resources) @ codecrafters-http-server ---
[compile] [INFO] skip non existing resourceDirectory /app/src/main/resources
[compile] [INFO] 
[compile] [INFO] --- compiler:3.13.0:compile (default-compile) @ codecrafters-http-server ---
[compile] [INFO] Recompiling the module because of changed source code.
[compile] [INFO] Compiling 1 source file with javac [debug target 23] to target/classes
[compile] [INFO] 
[compile] [INFO] --- resources:3.3.1:testResources (default-testResources) @ codecrafters-http-server ---
[compile] [INFO] skip non existing resourceDirectory /app/src/test/resources
[compile] [INFO] 
[compile] [INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ codecrafters-http-server ---
[compile] [INFO] No sources to compile
[compile] [INFO] 
[compile] [INFO] --- surefire:3.2.5:test (default-test) @ codecrafters-http-server ---
[compile] [INFO] No tests to run.
[compile] [INFO] 
[compile] [INFO] --- jar:3.4.1:jar (default-jar) @ codecrafters-http-server ---
[compile] [INFO] Building jar: /app/target/codecrafters-http-server-1.0.jar
[compile] [INFO] 
[compile] [INFO] --- assembly:3.7.1:single (make-assembly) @ codecrafters-http-server ---
[compile] [INFO] Building jar: /tmp/codecrafters-build-http-server-java/codecrafters-http-server.jar
[compile] [WARNING] Configuration option 'appendAssemblyId' is set to false.
[compile] Instead of attaching the assembly file: /tmp/codecrafters-build-http-server-java/codecrafters-http-server.jar, it will become the file for main project artifact.
[compile] NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic!
[compile] [WARNING] Replacing pre-existing project main-artifact file: /app/target/codecrafters-http-server-1.0.jar
[compile] with assembly file: /tmp/codecrafters-build-http-server-java/codecrafters-http-server.jar
[compile] [INFO] ------------------------------------------------------------------------
[compile] [INFO] BUILD SUCCESS
[compile] [INFO] ------------------------------------------------------------------------
[compile] [INFO] Total time:  2.739 s
[compile] [INFO] Finished at: 2025-05-16T18:10:49Z
[compile] [INFO] ------------------------------------------------------------------------
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#IH0] Running tests for Stage #IH0 (Extract URL path)
[tester::#IH0] $ ./your_program.sh
[your_program] Logs from your program will appear here!
[tester::#IH0] $ curl -v http://localhost:4221/mango
[your_program] Modified message has been sent to the client
[tester::#IH0] Expected status code 404, got 200
[tester::#IH0] Test failed (try setting 'debug: true' in your codecrafters.yml to see more details)```

@Vaibhav-Somani Do you by any chance have another account? We didn’t see any submissions in the last 19 hours under Vaibhav-Somani.

Mind sharing the username at the top right of the page so that I can take a closer look for you?

@andy1li My username is Vaibhav-Somani. I am committing code since past 12-14 hours. Not sure how it is not getting updated. Adding screenshots of my git commits.
Git commit link: Commits · Vaibhav-Somani/codecrafters-http-server-java · GitHub


That does seem quite unusual.

Could you run git remote -v and share the result?

@andy1li

Following are the results along with screenshot:

[redacted by Andy]

Edited by Andy:

Redacted since other people can push to it as well.

Sorry @andy1li
I did not understand the issue. Can you explain it in detail along with the solution?

@Vaibhav-Somani Looking into it now.

1 Like

Well, only the first two stages of the HTTP server challenge are free. You’ll need a membership to run tests against later stages:

1 Like

@andy1li
But I can still work on other challenges, right? My tests will show a failure in the UI. I should still be able to test them by running the server in local and hit the API.
Please correct me if my understanding is wrong.

But I can still work on other challenges, right?

Yep, feel free to explore our free challenges and the first two free stages in other challenges.

My tests will show a failure in the UI.

Sorry for the confusion. The error you’re seeing is from a previous submission (about 20 hours ago). Your recent pushes didn’t trigger a new submission since the current stage requires a membership.

Let me know if anything’s still unclear!

@andy1li
It is still unclear. I should be able to explore challenges that are not free and run them in my local, right? It will not show as passed in the UI, but I will be able to go through them and learn from them.
I hope my question is clear. Please let me know if you need any further clarifications.

I should be able to explore challenges that are not free and run them in my local, right? It will not show as passed in the UI, but I will be able to go through them and learn from them.

Yes, you can absolutely continue building locally.

Just note that without a membership, you won’t be able to run tests on our servers for the member-only stages.

1 Like

Understood. Thanks @andy1li
Please feel free to close the thread.

1 Like

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