Commits

Anonymous committed 7ea1760

Added cherrypy.request.remotePort; the TCP port from which the client's
connection originates. Added this attribute to the book also.

  • Participants
  • Parent commits be31227

Comments (0)

Files changed (5)

cherrypy/_cphttpserver.py

         
         cherrypy.request.multithread = cherrypy.config.get("server.threadPool") > 1
         cherrypy.request.multiprocess = False
-        cherrypy.server.request(self.client_address[0],
+        cherrypy.server.request(self.client_address,
                                 self.address_string(),
                                 self.raw_requestline,
                                 self._headerlist(),

cherrypy/_cphttptools.py

                  rfile, scheme="http"):
         """Populate a new Request object.
         
-        clientAddress and remoteHost should be IP address strings.
+        clientAddress should be a tuple of client IP address, client Port
+        remoteHost should be string of the client's IP address.
         requestLine should be of the form "GET /path HTTP/1.0".
         headers should be a list of (name, value) tuples.
         rfile should be a file-like object containing the HTTP request
         self.requestHeaders = headers
         
         # Prepare cherrypy.request variables
-        cherrypy.request.remoteAddr = clientAddress
+        cherrypy.request.remoteAddr = clientAddress[0]
+        cherrypy.request.remotePort = clientAddress[1]
         cherrypy.request.remoteHost = remoteHost
         cherrypy.request.paramList = [] # Only used for Xml-Rpc
         cherrypy.request.headerMap = {}

cherrypy/_cpwsgi.py

                                   or environ.get('REMOTE_USER') or None)
         cherrypy.request.multithread = environ['wsgi.multithread']
         cherrypy.request.multiprocess = environ['wsgi.multiprocess']
-        cherrypy.server.request(environ.get('REMOTE_ADDR', ''),
+        clientAddr = (
+            environ.get('REMOTE_ADDR', ''),
+            int(environ.get('REMOTE_PORT', -1))
+        )
+        cherrypy.server.request(clientAddr,
                                 environ.get('REMOTE_ADDR', ''),
                                 requestLine(environ),
                                 translate_headers(environ),

cherrypy/server.py

 def request(clientAddress, remoteHost, requestLine, headers, rfile, scheme="http"):
     """request(clientAddress, remoteHost, requestLine, headers, rfile, scheme="http")
     
-    clientAddress: the IP address of the client
+    clientAddress: the (IP address, port) of the client
     remoteHost: the IP address of the client
     requestLine: "<HTTP method> <url?qs> HTTP/<version>",
             e.g. "GET /main?abc=123 HTTP/1.1"

docs/book/xml/apireference.xml

          xmlns:xi="http://www.w3.org/2001/XInclude"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
          xml:id="apireference">
-  <title>API reference</title>
-  <section id="cherrypy">
-    <title>cherrypy</title>
-    <itemizedlist>
-      <listitem>
-        <section>
-          <title>cherrypy.threadData</title>
-          <para>This attribute holds attributes that map to this thread only.</para>
-        </section>
-      </listitem>
-    </itemizedlist>
+  <title>API reference</title>
+  <section id="cherrypy">
+    <title>cherrypy</title>
+    <itemizedlist>
+      <listitem>
+        <section>
+          <title>cherrypy.threadData</title>
+          <para>This attribute holds attributes that map to this thread only.</para>
+        </section>
+      </listitem>
+    </itemizedlist>
   </section>
   <section id="cherrypyrequest">
     <title>cherrypy.request</title>
       <listitem>
         <section>
           <title>cherrypy.request.remoteAddr</title>
-          <para>This attribute is a string containing the IP address of the client.</para>
+          <para>This attribute is a string containing the IP address of the
+          client. It will be an empty string if it is not available.</para>
+        </section>
+      </listitem>
+      <listitem>
+        <section>
+          <title>cherrypy.request.remotePort</title>
+          <para>This attribute is an int containing the TCP port number of
+          the client. It will be -1 if it is not available.</para>
         </section>
       </listitem>
       <listitem>