| 788 | } |
| 789 | |
| 790 | Http::Response Http::downloadRequest( const Http::Request& request, IOStream& writeTo, |
| 791 | Time timeout ) { |
| 792 | // Solve the host IP only when the request starts. |
| 793 | if ( !mHostSolved ) { |
| 794 | if ( !mProxy.empty() ) { |
| 795 | mHost = IpAddress( mProxy.getHost() ); |
| 796 | } else { |
| 797 | mHost = IpAddress( mHostName ); |
| 798 | } |
| 799 | mHostSolved = true; |
| 800 | } |
| 801 | |
| 802 | if ( 0 == mHost.toInteger() ) { |
| 803 | return Response(); |
| 804 | } |
| 805 | |
| 806 | if ( NULL == mConnection ) { |
| 807 | HttpConnection* connection = eeNew( HttpConnection, () ); |
| 808 | TcpSocket* socket = NULL; |
| 809 | |
| 810 | // If the http client is proxied and the end host use SSL |
| 811 | // We need to create an HTTP Tunnel against the proxy server |
| 812 | if ( isProxied() && mIsSSL && SSLSocket::isSupported() ) { |
| 813 | socket = SSLSocket::New( mHostName, request.getValidateCertificate(), |
| 814 | request.getValidateHostname() ); |
| 815 | |
| 816 | connection->setSSL( true ); |
| 817 | } else { |
| 818 | bool isSSL = !isProxied() |
| 819 | ? mIsSSL |
| 820 | : ( SSLSocket::isSupported() && mProxy.getScheme() == "https" ); |
| 821 | |
| 822 | socket = isSSL ? SSLSocket::New( mHostName, request.getValidateCertificate(), |
| 823 | request.getValidateHostname() ) |
| 824 | : TcpSocket::New(); |
| 825 | |
| 826 | connection->setSSL( isSSL ); |
| 827 | } |
| 828 | |
| 829 | if ( timeout != Time::Zero ) { |
| 830 | socket->setReceiveTimeout( timeout ); |
| 831 | socket->setSendTimeout( timeout ); |
| 832 | } |
| 833 | |
| 834 | connection->setSocket( socket ); |
| 835 | |
| 836 | mConnection = connection; |
| 837 | } |
| 838 | |
| 839 | // First make sure that the request is valid -- add missing mandatory fields |
| 840 | Request toSend( prepareFields( request ) ); |
| 841 | |
| 842 | // Prepare the response |
| 843 | Response received; |
| 844 | |
| 845 | if ( request.isCancelled() ) { |
| 846 | onCancel( request ); |
| 847 | endConnection(); |
no test coverage detected