Jump to content
xisto Community
Sign in to follow this  
beeseven

How Do Web Server Programs Work?

Recommended Posts

Things like Apache. Do they just wait for people to try to connect to a computer and then send back information about what's on the computer? What other kinds of things do they send (like headers)? Could you make a really simple one that just waited for socket connections and sent back text files?

Edited by beeseven (see edit history)

Share this post


Link to post
Share on other sites

Things like Apache. Do they just wait for people to try to connect to a computer and then send back information about what's on the computer? What other kinds of things do they send (like headers)? Could you make a really simple one that just waited for socket connections and sent back text files?

 

I cant go into details as i dont know myself but the basic proccess of a web server is something like

 

receives http(or ftp etc..)request from a browser for a certain file > locates the file > sends the file to the client

 

GET / HTTP/1.1[CRLF]

Host: https://www.google.de/?gfe_rd=cr&ei=BwkjVKfAD8uH8QfckIGgCQ&gws_rd=ssl[CRLF]

Connection: close[CRLF]

Accept-Encoding: gzip[CRLF]

Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5[CRLF]

Accept-Language: en-us,en;q=0.5[CRLF]

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7[CRLF]

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 Web-Sniffer/1.0.24[CRLF]

Referer: http://web-sniffer.net/[CRLF]

[CRLF]

thats what a request to Google.com looks like. The get line contains the protocol and request type (i think anyway!) and also the file to be sent, which in this case is the index page but i were to try to get a page called page.htm the get line would read something like GET /page.htm HTTP/1.1. I believe the accept lines tells which types of files and connections are accepted by the client. They are the most important ones i think. Once the web server receives this information it sees that it needs to send a file across a HTTP connection (http://https://www.google.de/?gfe_rd=cr&ei=BwkjVKfAD8uH8QfckIGgCQ&gws_rd=ssl) and it knows what file types the browser will accept. And as default the web server sends the index page as no page is actually specified.

 

t6hats my basic understanding of the process anyway :lol: maybe someone else would have a more detailed explanation.

 

 

To write your own web server basically you would need to accept the above requests, identify which files is to be sent and then presumably use a winsock or other connection to send the data to the client.

Edited by shadowx (see edit history)

Share this post


Link to post
Share on other sites

I wrote a very simple web server once. This is how it worked. I used Visual Basic to write it, but I can't find the source. This is how it worked. Firstly it listened for connections. When it received a connection, it processed it.

GET / HTTP/1.1[CRLF]Host: https://www.google.de/?gfe_rd=cr&ei=BwkjVKfAD8uH8QfckIGgCQ&gws_rd=ssl[CRLF]
Connection: close[CRLF]
Accept-Encoding: gzip[CRLF]
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5[CRLF]
Accept-Language: en-us,en;q=0.5[CRLF]
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7[CRLF]
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0 Web-Sniffer/1.0.24[CRLF]
Referer: http://web-sniffer.net/[CRLF]
[CRLF]


The users browser sends something very similar to this for every page or file it needs to download. Since my webserver was simple, it searched for the GET in the beginning, and if it didn't find it, it just sent "Command not understood." back to the client and then closed the connection and started listening for other requests again. If it did find the GET it searched for the file on my computer, and if it was found it opened it and sent it back to the computer that requested it and then closed the connection. If it wasn't found it sent back "404 File Not Found" and then closed the connection. If I can find the source to it I'll post it. If you're going to write a small webserver like this, feel free to PM me and I can help you out a little bit. You just gotta remember to always start listening again, otherwise your webserver won't work. It took me a while to figure that one out :lol:.

Share this post


Link to post
Share on other sites

So my suspicion was partially confirmed, but it looks a little more complicated than I thought. I think I'll try making a simple one but I don't really know how I'd make it secure, so unless someone wants to help there I doubt I'll use it for anything besides random testing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.