void CConnection::SendHTML(UINT nResourceID) { CString strResponse; CString strBody = LoadRichHTML( nResourceID, strResponse ); if ( strResponse.IsEmpty() ) Write( _P("HTTP/1.1 200 OK\r\n") ); else Write( _T("HTTP/1.1 ") + strResponse ); if ( nResourceID == IDR_HTML_BUSY ) Write( _P("Retry-After: 30\r\n") ); Write( _P("Content-Type: text/html\r\n") ); CStringA strBodyUTF8 = UTF8Encode( strBody ); CString strLength; strLength.Format( _T("Content-Length: %i\r\n\r\n"), strBodyUTF8.GetLength() ); Write( strLength ); LogOutgoing(); Write( (LPCSTR)strBodyUTF8, strBodyUTF8.GetLength() ); }
void CHostBrowser::SendRequest() { if ( m_nProtocol != PROTOCOL_ED2K && m_nProtocol != PROTOCOL_DC ) { if ( ! IsValid() ) return; if ( m_bNewBrowse ) Write( _P("GET /gnutella/browse/v1 HTTP/1.1\r\n") ); else if ( Settings.Downloads.RequestHTTP11 ) Write( _P("GET / HTTP/1.1\r\n") ); else Write( _P("GET / HTTP/1.0\r\n") ); CString strHeader = Settings.SmartAgent(); if ( ! strHeader.IsEmpty() ) { Write( _P("User-Agent: ") ); Write( strHeader ); Write( _P("\r\n") ); } Write( _P("Accept: text/html, application/x-gnutella-packets, application/x-gnutella2\r\n") ); Write( _P("Accept-Encoding: deflate\r\n") ); // if ( ! m_sKey.IsEmpty() ) // ToDo: Proposed PrivateKey extension // Write( L"Authorization: :" + m_sKey + L"\r\n" ); Write( _P("Connection: close\r\n") ); strHeader.Format( L"Host: %s:%lu\r\n\r\n", (LPCTSTR)m_sAddress, htons( m_pHost.sin_port ) ); Write( strHeader ); LogOutgoing(); OnWrite(); m_nProtocol = PROTOCOL_ANY; } m_nState = hbsRequesting; m_bDeflate = FALSE; m_nLength = SIZE_UNKNOWN; m_bConnect = TRUE; m_mInput.pLimit = m_mOutput.pLimit = &Settings.Bandwidth.Downloads; theApp.Message( MSG_INFO, IDS_BROWSE_SENT_REQUEST, (LPCTSTR)m_sAddress ); }
BOOL CRemote::OnHeadersComplete() { if ( m_sHandshake.Find( L"GET /" ) != 0 ) { Close(); delete this; return FALSE; } m_sHandshake = m_sHandshake.Mid( 4 ).SpanExcluding( L" \t" ); CString strPath = m_sHandshake.SpanExcluding( L"?&" ); ToLower( strPath ); m_sRedirect.Empty(); m_sHeader.Empty(); m_sResponse.Empty(); m_pResponse.Clear(); PageSwitch( strPath ); if ( ! m_sRedirect.IsEmpty() ) { Write( _P("HTTP/1.1 302 Found\r\n") ); Write( _P("Content-Length: 0\r\n") ); if ( ! m_sHeader.IsEmpty() ) Write( m_sHeader ); Write( _P("Location: ") ); Write( m_sRedirect ); Write( _P("\r\n") ); } else if ( ! m_sResponse.IsEmpty() ) { CString strLength; Prepare(); Output( L"tail" ); int nBytes = WideCharToMultiByte( CP_UTF8, 0, m_sResponse, m_sResponse.GetLength(), NULL, 0, NULL, NULL ); strLength.Format( L"Content-Length: %i\r\n", nBytes ); Write( _P("HTTP/1.1 200 OK\r\n") ); Write( _P("Content-Type: text/html; charset=UTF-8\r\n") ); Write( strLength ); if ( ! m_sHeader.IsEmpty() ) Write( m_sHeader ); } else if ( m_pResponse.m_nLength > 0 ) { Write( _P("HTTP/1.1 200 OK\r\n") ); CString strLength; strLength.Format( L"Content-Length: %u\r\n", m_pResponse.m_nLength ); Write( strLength ); if ( ! m_sHeader.IsEmpty() ) Write( m_sHeader ); } else { Write( _P("HTTP/1.1 404 Not Found\r\n") ); Write( _P("Content-Length: 0\r\n") ); Write( _P("Content-Type: text/html\r\n") ); } LogOutgoing(); Write( _P("\r\n") ); if ( ! m_sResponse.IsEmpty() ) { Write( m_sResponse, CP_UTF8 ); m_sResponse.Empty(); } else if ( m_pResponse.m_nLength > 0 ) { Write( &m_pResponse ); } m_sHandshake.Empty(); ClearHeaders(); OnWrite(); return TRUE; }