1

I'm currently making an extra lightweight web server in C for people who try to hack my server, but I want to know the proper coding to use for output.

I'm making a simple test page that only shows "Error" in bold and "This is a hack-ed-server" as the main text.

I attempted to use minimal HTTP headers so the page can display better.

Currently the Opera browser processes the html below correctly, however, when I test it in CURL using no parameters nothing appears on screen. I instead expected the HTML code to appear.

When I use the -I parameter for CURL, the expected HTTP headers appear correctly.

char buf[10000]={"HTTP/1.1 200 OK\r\nContent-type: text/html\r\n\r\n<html><head><title>hacked</title></head><body><H1>Error</h1><p>This is a hack-ed-server</p></body></html>\n"};

In all tests, I used the same correct IP address and the correct port number and the server daemon containing the above code was constantly running.

I'm curious. Is there something wrong with CURL, or with Opera, or with my code? Am I formatting the return codes incorrectly for the HTTP headers?

Mike -- No longer here
  • 2,064
  • 1
  • 15
  • 37
  • This is weird. I changed `HTTP/1.1` to `HTTP/1.0` and tested it with CURL and the HTML output is displayed. I then proceed to test it with apache bench and got "connection reset by peer". I wonder why that is? – Mike -- No longer here Oct 05 '15 at 06:30

1 Answers1

0

... I then proceed to test it with apache bench and got "connection reset by peer"

You probably did not read the request from the client fully but simply dumped your response to the client and closed the connection. See also Perl: Connection reset with simple HTTP server.

Apart from that the single line of the code you've provided is not sufficient to answer your question, because it is relevant what you read from the client, what you send and when you close the TCP socket. The response by itself is fine but you should better add a content-length.

Community
  • 1
  • 1
Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172