Rectangle 27 0

Rebuild request header from HTTP proxy server to Remote Server in C?


GET / HTTP/1.1
GET http://www.gmail.com/ HTTP/1.1

However, this may not be the only thing you need to do. An HTTP proxy is a fairly complex application, due to things like different protocol version numbers and connection options on the browser-proxy connection versus the proxy-server connection.

I am able to connect to the server, but the problem is that proxy server is not reading entire response from the server. Connection is being reset by remote server while proxy is receiving data. Is the problem in reading data with this code while((n = read(rfd, buff, MAXLINE)) > 0) { write(connfd, buff, MAXLINE); printf("%s",buff); bzero(buff,MAXLINE); }

I guess so, I can't see where your line breaks are in the comment. But you'll also want to act upon that Proxy-Connection header, as that is sent by the browser to the proxy and is not intended to be passed on to the server. Again, read RFC 2616 for full details.

RFC 2616 contains a considerable amount of information regarding the correct behaviour of HTTP proxy applications.

SO it should be something like this: GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, / Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) Accept-Encoding: gzip, deflate Proxy-Connection: Keep-Alive Host: www.gmail.com

The full URL is required when the browser sends the request to the proxy, so that the proxy can make the further connection to the real server. However, an HTTP request to the server must not contain the protocol and hostname parts on the GET line.

The fundamental transformation you need to do from a proxy request to an HTTP server request is to change the first line:

Note
Rectangle 27 0

Rebuild request header from HTTP proxy server to Remote Server in C?


GET / HTTP/1.1
GET http://www.gmail.com/ HTTP/1.1

However, this may not be the only thing you need to do. An HTTP proxy is a fairly complex application, due to things like different protocol version numbers and connection options on the browser-proxy connection versus the proxy-server connection.

I am able to connect to the server, but the problem is that proxy server is not reading entire response from the server. Connection is being reset by remote server while proxy is receiving data. Is the problem in reading data with this code while((n = read(rfd, buff, MAXLINE)) > 0) { write(connfd, buff, MAXLINE); printf("%s",buff); bzero(buff,MAXLINE); }

I guess so, I can't see where your line breaks are in the comment. But you'll also want to act upon that Proxy-Connection header, as that is sent by the browser to the proxy and is not intended to be passed on to the server. Again, read RFC 2616 for full details.

RFC 2616 contains a considerable amount of information regarding the correct behaviour of HTTP proxy applications.

SO it should be something like this: GET / HTTP/1.1 Accept: text/html, application/xhtml+xml, / Accept-Language: en-US User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0) Accept-Encoding: gzip, deflate Proxy-Connection: Keep-Alive Host: www.gmail.com

The full URL is required when the browser sends the request to the proxy, so that the proxy can make the further connection to the real server. However, an HTTP request to the server must not contain the protocol and hostname parts on the GET line.

The fundamental transformation you need to do from a proxy request to an HTTP server request is to change the first line:

Note