You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2013/01/10 16:45:47 UTC

svn commit: r1431444 - in /tomcat/trunk/java/org/apache/catalina/connector: CoyoteAdapter.java Request.java

Author: remm
Date: Thu Jan 10 15:45:47 2013
New Revision: 1431444

URL: http://svn.apache.org/viewvc?rev=1431444&view=rev
Log:
- Add the ability to invoke the main service method as an API call, without having to fallback to bytes.
- Add some utility get/set (one of which got removed after deprecation but is not necessarily that useless).
- Both changes to make using the rewrite valve possible.

Modified:
    tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
    tomcat/trunk/java/org/apache/catalina/connector/Request.java

Modified: tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java?rev=1431444&r1=1431443&r2=1431444&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/CoyoteAdapter.java Thu Jan 10 15:45:47 2013
@@ -609,39 +609,53 @@ public class CoyoteAdapter implements Ad
         MessageBytes decodedURI = req.decodedURI();
         decodedURI.duplicate(req.requestURI());
 
-        // Parse the path parameters. This will:
-        //   - strip out the path parameters
-        //   - convert the decodedURI to bytes
-        parsePathParameters(req, request);
+        if (decodedURI.getType() == MessageBytes.T_BYTES) {
+            // Parse the path parameters. This will:
+            //   - strip out the path parameters
+            //   - convert the decodedURI to bytes
+            parsePathParameters(req, request);
 
-        // URI decoding
-        // %xx decoding of the URL
-        try {
-            req.getURLDecoder().convert(decodedURI, false);
-        } catch (IOException ioe) {
-            res.setStatus(400);
-            res.setMessage("Invalid URI: " + ioe.getMessage());
-            connector.getService().getContainer().logAccess(
-                    request, response, 0, true);
-            return false;
-        }
-        // Normalization
-        if (!normalize(req.decodedURI())) {
-            res.setStatus(400);
-            res.setMessage("Invalid URI");
-            connector.getService().getContainer().logAccess(
-                    request, response, 0, true);
-            return false;
-        }
-        // Character decoding
-        convertURI(decodedURI, request);
-        // Check that the URI is still normalized
-        if (!checkNormalize(req.decodedURI())) {
-            res.setStatus(400);
-            res.setMessage("Invalid URI character encoding");
-            connector.getService().getContainer().logAccess(
-                    request, response, 0, true);
-            return false;
+            // URI decoding
+            // %xx decoding of the URL
+            try {
+                req.getURLDecoder().convert(decodedURI, false);
+            } catch (IOException ioe) {
+                res.setStatus(400);
+                res.setMessage("Invalid URI: " + ioe.getMessage());
+                connector.getService().getContainer().logAccess(
+                        request, response, 0, true);
+                return false;
+            }
+            // Normalization
+            if (!normalize(req.decodedURI())) {
+                res.setStatus(400);
+                res.setMessage("Invalid URI");
+                connector.getService().getContainer().logAccess(
+                        request, response, 0, true);
+                return false;
+            }
+            // Character decoding
+            convertURI(decodedURI, request);
+            // Check that the URI is still normalized
+            if (!checkNormalize(req.decodedURI())) {
+                res.setStatus(400);
+                res.setMessage("Invalid URI character encoding");
+                connector.getService().getContainer().logAccess(
+                        request, response, 0, true);
+                return false;
+            }
+        } else {
+            // The URL is chars or String, and has been sent using an in-memory
+            // protocol handler, we have to assume the URL has been properly
+            // decoded already
+            decodedURI.toChars();
+            // Remove any path parameters
+            CharChunk uriCC = decodedURI.getCharChunk();
+            int semicolon = uriCC.indexOf(';');
+            if (semicolon > 0) {
+                decodedURI.setChars
+                    (uriCC.getBuffer(), uriCC.getStart(), semicolon);
+            }
         }
 
         // Set the remote principal

Modified: tomcat/trunk/java/org/apache/catalina/connector/Request.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Request.java?rev=1431444&r1=1431443&r2=1431444&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Request.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Request.java Thu Jan 10 15:45:47 2013
@@ -1002,6 +1002,14 @@ public class Request
 
 
     /**
+     * Set the content type for this Request.
+     */
+    public void setContentType(String contentType) {
+        coyoteRequest.setContentType(contentType);
+    }
+
+
+    /**
      * Return the servlet input stream for this Request.  The default
      * implementation returns a servlet input stream created by
      * <code>createInputStream()</code>.
@@ -1831,6 +1839,16 @@ public class Request
 
 
     /**
+     * Get the decoded request URI.
+     *
+     * @return the URL decoded request URI
+     */
+    public MessageBytes getDecodedRequestURIMB() {
+        return coyoteRequest.decodedURI();
+    }
+
+
+    /**
      * Set the Principal who has been authenticated for this Request.  This
      * value is also used to calculate the value to be returned by the
      * <code>getRemoteUser()</code> method.



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1431444 - in /tomcat/trunk/java/org/apache/catalina/connector: CoyoteAdapter.java Request.java

Posted by Konstantin Kolinko <kn...@gmail.com>.
2013/1/10 Mark Thomas <ma...@apache.org>:
> On 10/01/2013 15:45, remm@apache.org wrote:
>> Author: remm
>> Date: Thu Jan 10 15:45:47 2013
>> New Revision: 1431444
>>
>> URL: http://svn.apache.org/viewvc?rev=1431444&view=rev
>
> <snip/>
>
>> +            // The URL is chars or String, and has been sent using an in-memory
>> +            // protocol handler, we have to assume the URL has been properly
>> +            // decoded already
>> +            decodedURI.toChars();
>> +            // Remove any path parameters
>> +            CharChunk uriCC = decodedURI.getCharChunk();
>> +            int semicolon = uriCC.indexOf(';');
>> +            if (semicolon > 0) {
>> +                decodedURI.setChars
>> +                    (uriCC.getBuffer(), uriCC.getStart(), semicolon);
>> +            }
>
> The code is based on the assumption that path parameters will only ever
> appear at the end of the URL. While that is the typically case, it is
> not guaranteed to be the case.
>
> While I would prefer to see correct path parameter parsing, as a minimum
> there needs to be a something along the lines of a TODO comment at that
> point in the code to highlight the short-cut that is being taken.
>

About the updated comment:

> -            // Remove any path parameters
> +            // Remove all path parameters; any needed path parameter should be set
> +            // using the request object rather than passing it in the URL

If we do not expect path parameters to be passed here, I would better
throw new IllegalArgumentException() rather than silently changing the
data.

Best regards,
Konstantin Kolinko

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1431444 - in /tomcat/trunk/java/org/apache/catalina/connector: CoyoteAdapter.java Request.java

Posted by Mark Thomas <ma...@apache.org>.
On 10/01/2013 15:45, remm@apache.org wrote:
> Author: remm
> Date: Thu Jan 10 15:45:47 2013
> New Revision: 1431444
> 
> URL: http://svn.apache.org/viewvc?rev=1431444&view=rev

<snip/>

> +            // The URL is chars or String, and has been sent using an in-memory
> +            // protocol handler, we have to assume the URL has been properly
> +            // decoded already
> +            decodedURI.toChars();
> +            // Remove any path parameters
> +            CharChunk uriCC = decodedURI.getCharChunk();
> +            int semicolon = uriCC.indexOf(';');
> +            if (semicolon > 0) {
> +                decodedURI.setChars
> +                    (uriCC.getBuffer(), uriCC.getStart(), semicolon);
> +            }

The code is based on the assumption that path parameters will only ever
appear at the end of the URL. While that is the typically case, it is
not guaranteed to be the case.

While I would prefer to see correct path parameter parsing, as a minimum
there needs to be a something along the lines of a TODO comment at that
point in the code to highlight the short-cut that is being taken.

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org