You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by ha...@apache.org on 2006/01/04 18:04:20 UTC

svn commit: r365944 - in /webservices/axis/trunk/c/src/transport/axis3: HTTPTransport.cpp HTTPTransport.hpp

Author: hawkeye
Date: Wed Jan  4 09:04:14 2006
New Revision: 365944

URL: http://svn.apache.org/viewcvs?rev=365944&view=rev
Log: (empty)

Modified:
    webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp
    webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp

Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp?rev=365944&r1=365943&r2=365944&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.cpp Wed Jan  4 09:04:14 2006
@@ -398,13 +398,22 @@
 		m_strHeaderBytesToSend += "\r\n";
     }
 
-    // Set session cookie
-    if (m_bMaintainSession && (m_strSessionKey.size () > 0))
+    // Set cookies
+    if (m_bMaintainSession && (m_vCookies.size () > 0))
     {
 		m_strHeaderBytesToSend += "Cookie";
 		m_strHeaderBytesToSend += ": ";
-		m_strHeaderBytesToSend += m_strSessionKey;
-		m_strHeaderBytesToSend += "\r\n";
+
+        for (unsigned int var = 0; var < m_vCookies.size(); var++) 
+        {
+            m_strHeaderBytesToSend += m_vCookies[var].first;
+            m_strHeaderBytesToSend += "=";
+            m_strHeaderBytesToSend += m_vCookies[var].second;
+            m_strHeaderBytesToSend += ";";
+        }
+        // remove the last ';'
+        m_strHeaderBytesToSend = m_strHeaderBytesToSend.substr(0, m_strHeaderBytesToSend.length()-1);
+        m_strHeaderBytesToSend += "\r\n";
     }
 
     m_strHeaderBytesToSend += "\r\n";
@@ -1111,23 +1120,10 @@
 			}
 
 	    	// Look for cookies
-			if( m_bMaintainSession && !(m_strSessionKey.size() > 0))
+			if( m_bMaintainSession )
 		    {
 				if( key == "Set-Cookie")
-				{
-					m_strSessionKey = value;
-
-		    		// Spec syntax : Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
-		    		// This code assumes it to be : Set-Cookie: NAME=VALUE; Anything_else
-		    		// And discards stuff after first ';'
-		    		// This is the same assumption used in Axis Java
-					unsigned long ulKeyEndsAt = m_strSessionKey.find( ";");
-		    
-					if( ulKeyEndsAt != std::string::npos)
-				    {
-						m_strSessionKey = m_strSessionKey.substr( 0, ulKeyEndsAt);
-				    }
-				}
+                  addCookie(value);
 		    }
 
 	    	/* If Content-Type: Multipart/Related; boundary=<MIME_boundary>; type=text/xml;
@@ -1712,6 +1708,29 @@
 	}
 
 	return bTransportInProgress;
+}
+
+bool HTTPTransport::addCookie(const string name, const string value)
+{
+ m_vCookies.push_back( std::make_pair( name, value));
+ return true;
+}
+bool HTTPTransport::addCookie(const string nameValuePair)
+{
+    // Spec syntax : Set-Cookie: NAME=VALUE; expires=DATE; path=PATH; domain=DOMAIN_NAME; secure
+    // This code assumes it to be : Set-Cookie: NAME=VALUE; Anything_else
+    // And discards stuff after first ';'
+    // This is the same assumption used in Axis Java
+    unsigned long ulKeyEndsAt = nameValuePair.find( ";");
+           
+    string nameValue;
+    if( ulKeyEndsAt != std::string::npos)
+    {
+       nameValue = nameValuePair.substr( 0, ulKeyEndsAt);
+    }
+    // Now split the nameValue up
+    unsigned long nameEndsAt = nameValue.find("=");
+    return addCookie(nameValue.substr(0, nameEndsAt), nameValue.substr(nameEndsAt+1));
 }
 
 int HTTPTransport::peekChunkLength( std::string& strNextChunk)

Modified: webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp
URL: http://svn.apache.org/viewcvs/webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp?rev=365944&r1=365943&r2=365944&view=diff
==============================================================================
--- webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp (original)
+++ webservices/axis/trunk/c/src/transport/axis3/HTTPTransport.hpp Wed Jan  4 09:04:14 2006
@@ -17,9 +17,15 @@
 
 /*
  * @author Samisa Abeysinghe (sabeysinghe@virtusa.com)
+ * @author hawkeye (hawkinsj@uk.ibm.com) - improved cookie support
+ * 
+ * KNOWN LIMITATIONS: 
+ * Cookie support: 
+ * 1) Cookies are maintained over the life time of a connection only and are not persisted.
+ * 2) We ignore expires, path, domain, secure attributes
+ * 
  */
 
-
 #if !defined(_AXIS_AXIS_TRANSPORT_HPP)
 #define _AXIS_AXIS_TRANSPORT_HPP
 
@@ -116,7 +122,22 @@
 	int						getChunkSize();
 	bool					copyDataToParserBuffer( char * pcBuffer, int * piSize, int iBytesToCopy);
 	int						peekChunkLength( std::string& strNextChunk);
-
+    /**
+     * Adds a cookie to the http header. 
+     * 
+     * @param name name of the cookie
+     * @param value value of the cookie
+     * @return true if the cookie was added succesfully. False otherwise
+     */
+    bool                    addCookie(const string name, const string Value);
+    
+    /**
+     * Adds the name value pair to the cookie list
+     * @param nameValuepair in the format name=value
+     * @return true if the cookie was added succesfully false otherwise.
+     */
+    bool addCookie(const string nameValuePair);
+    
   /**
     * Keeps track of if we need to reopen connection.
     * Set true by setEndpointUri.
@@ -225,6 +246,11 @@
     * Session key sent by service 
     */
     std::string m_strSessionKey;
+
+  /**
+   * Cookies set and to be sent to the server.
+   */
+  std::vector < std::pair < std::string, std::string > >m_vCookies;
   
   /** 
     * Content-Type holder