Return-Path: Delivered-To: apmail-ws-axis-c-dev-archive@www.apache.org Received: (qmail 94109 invoked from network); 6 Sep 2005 06:57:39 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Sep 2005 06:57:39 -0000 Received: (qmail 52757 invoked by uid 500); 6 Sep 2005 06:57:35 -0000 Delivered-To: apmail-ws-axis-c-dev-archive@ws.apache.org Received: (qmail 52429 invoked by uid 500); 6 Sep 2005 06:57:34 -0000 Mailing-List: contact axis-c-dev-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: "Apache AXIS C Developers List" Reply-To: "Apache AXIS C Developers List" Delivered-To: mailing list axis-c-dev@ws.apache.org Received: (qmail 52400 invoked by uid 99); 6 Sep 2005 06:57:33 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=SPF_FAIL X-Spam-Check-By: apache.org Received: from [192.87.106.226] (HELO ajax.apache.org) (192.87.106.226) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Sep 2005 23:57:32 -0700 Received: from ajax.apache.org (ajax.apache.org [127.0.0.1]) by ajax.apache.org (Postfix) with ESMTP id 19EEE354 for ; Tue, 6 Sep 2005 08:57:31 +0200 (CEST) Message-ID: <1687380041.1125989851104.JavaMail.jira@ajax.apache.org> Date: Tue, 6 Sep 2005 08:57:31 +0200 (CEST) From: "Denis Linine (JIRA)" To: axis-c-dev@ws.apache.org Subject: [jira] Created: (AXISCPP-822) Possible improvements to the HTTPTransport::getHTTPHeaders() and the HTTPTransport::flushOutput() methods - HTTPTransport.cpp file Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Possible improvements to the HTTPTransport::getHTTPHeaders() and the HTTPTransport::flushOutput() methods - HTTPTransport.cpp file ----------------------------------------------------------------------------------------------------------------------------------- Key: AXISCPP-822 URL: http://issues.apache.org/jira/browse/AXISCPP-822 Project: Axis-C++ Type: Improvement Components: Transport (axis3) Versions: current (nightly) Reporter: Denis Linine Priority: Trivial Hello, HTTPTransport::flushOutput() could be written like this (some current code is commented out): AXIS_TRANSPORT_STATUS HTTPTransport::flushOutput() throw (AxisException, HTTPTransportException) { // In preperation for sending the message, calculate the size of the message // by using the string length method. // NB: This calculation may not necessarily be correct when dealing with SSL // messages as the length of the encoded message is not necessarily the // same as the length of the uncoded message. // char buff[8]; // theoretically, a 8-char-long buffer can be too small even for 32 bit systems char buff[24]; //sprintf( buff, "%d", m_strBytesToSend.length ()); //this->setTransportProperty ("Content-Length", buff); // two lines above can be replaced like this (ultoa should work faster than sprintf): setTransportProperty ("Content-Length", ultoa(m_strBytesToSend.length (), buff, 10)); // The header is now complete. The message header and message can now be // transmitted. // utf8Buf will leak if an exception is thrown, catching different types of exceptions just to rethrow them is excessive // try // { //#ifndef __OS400__ // *m_pActiveChannel << this->getHTTPHeaders (); // *m_pActiveChannel << this->m_strBytesToSend.c_str (); //#else // const char *buf = this->getHTTPHeaders (); // char *utf8Buf = toUTF8((char *)buf, strlen(buf)+1); // *m_pActiveChannel << utf8Buf; // free(utf8Buf); // buf = this->m_strBytesToSend.c_str(); // utf8Buf = toUTF8((char *)buf, strlen(buf)+1); // *m_pActiveChannel << utf8Buf; // free(utf8Buf); //#endif // } // catch( HTTPTransportException & e) // { // throw; // } // catch( AxisException & e) // { // throw; // } // catch(...) // { // throw; // } char *utf8Buf = NULL; try { #ifndef __OS400__ *m_pActiveChannel << getHTTPHeaders (); *m_pActiveChannel << m_strBytesToSend.c_str (); #else const char *buf = this->getHTTPHeaders (); utf8Buf = toUTF8((char *)buf, strlen(buf)+1); *m_pActiveChannel << utf8Buf; free(utf8Buf); utf8Buf = NULL; // 5 lines above could probably be rewritten like this: // getHTTPHeaders(); // utf8Buf = toUTF8(m_strHeaderBytesToSend.c_str(), m_strHeaderBytesToSend.length()+1); // eliminate strlen; is const_cast(m_strBytesToSend.c_str()) necessary (what type of the toUTF8 first parameter)? // free(utf8Buf); // utf8Buf = NULL; buf = m_strBytesToSend.c_str(); utf8Buf = toUTF8(m_strBytesToSend.c_str(), m_strBytesToSend.length()+1); // eliminate strlen; is const_cast(m_strBytesToSend.c_str()) necessary (what type of the toUTF8 first parameter)? *m_pActiveChannel << utf8Buf; free(utf8Buf); utf8Buf = NULL; #endif } catch(...) { free(utf8Buf); // might be one should empty strings? // m_strBytesToSend.clear(); // m_strHeaderBytesToSend.clear(); throw; } // m_strHeaderBytesToSend seem to be used only by this function. // Is it not possible to make them local variables for flushOutput() and pass // Empty the bytes to send string. //m_strBytesToSend = ""; //m_strHeaderBytesToSend = ""; m_strBytesToSend.clear(); // ? m_strHeaderBytesToSend.clear(); // ? return TRANSPORT_FINISHED; } The first lines of the HTTPTransport::getHTTPHeaders(): const char * HTTPTransport::getHTTPHeaders() { URL & url = m_pActiveChannel->getURLObject(); unsigned short uiPort = url.getPort(); char buff[8]; m_strHeaderBytesToSend = m_strHTTPMethod + " "; if (m_bUseProxy) m_strHeaderBytesToSend += std::string (url.getURL ()) + " "; else m_strHeaderBytesToSend += std::string (url.getResource ()) + " "; m_strHeaderBytesToSend += m_strHTTPProtocol + "\r\n"; if (m_bUseProxy) m_strHeaderBytesToSend += std::string ("Host: ") + m_strProxyHost; else m_strHeaderBytesToSend += std::string ("Host: ") + url.getHostName (); if (m_bUseProxy) uiPort = m_uiProxyPort; sprintf (buff, "%u", uiPort); m_strHeaderBytesToSend += ":"; m_strHeaderBytesToSend += buff; m_strHeaderBytesToSend += "\r\n"; could probably be rewritten this way (eliminate creation of temporary strings, eliminate excessive if/else): const char * HTTPTransport::getHTTPHeaders() { URL & url = m_pActiveChannel->getURLObject(); unsigned short uiPort; // char buff[8]; // theoretically, a 8-char-long buffer can be too small even for 32 bit systems char buff[32]; m_strHeaderBytesToSend = m_strHTTPMethod + " "; if (m_bUseProxy) { m_strHeaderBytesToSend += url.getURL (); m_strHeaderBytesToSend += " "; m_strHeaderBytesToSend += m_strHTTPProtocol; m_strHeaderBytesToSend += "\r\nHost: "; m_strHeaderBytesToSend += m_strProxyHost; uiPort = m_uiProxyPort; } else { m_strHeaderBytesToSend += url.getResource (); m_strHeaderBytesToSend += " "; m_strHeaderBytesToSend += m_strHTTPProtocol; m_strHeaderBytesToSend += "\r\nHost: "; m_strHeaderBytesToSend += url.getHostName (); uiPort = url.getPort(); } sprintf(buff, ":%u\r\n", uiPort); m_strHeaderBytesToSend += buff; Note please that this code was nether tested nor even compiled -- This message is automatically generated by JIRA. - If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa - For more information on JIRA, see: http://www.atlassian.com/software/jira