I am implementing HTTP server which will be responsible for:
1. Receiving requests from a browser and forwarding it to another HTTP sever.
2. And reading response from HTTP server and forwarding it directly to the browser.
In this case i am taking care of modifying only host name in the received request while sending it to HTTP server over the socket using send()
socket API, I am using socket connection with HTTP server to forward the HTTP request received from browser.
I have following queries:
- Will HTTP request forwarding work with
recv()
andsend()
socket APIs. - If
recv()
returns0
then either server or browser has closed the socket?
But some times my application gets stuck in receive and does not return for 1-2 mins. - For receiving data on socket from the server do i need to wait till
recv()
returns 0 or do i need to check content length of the received data and then continue withrecv()
.
I am very new to HTTP. If any one has sample application for forwarding http requests then please provide, so that i can learn it better.