[GitHub] tomcat issue #109: fix: file resource read dir inputStream

2018-05-18 Thread GodIsDevil
Github user GodIsDevil commented on the issue:

https://github.com/apache/tomcat/pull/109
  
In the old version of Tomcat (7.0, 8.0), you used URLConnection to read all 
files or directories. I do not quite understand why the high version of Tomcat 
can not read the directory through URLConnection (FileInputStream can only read 
the file can not read the directory).
`@Override
public InputStream getResourceAsStream(String name) {

if (log.isDebugEnabled())
log.debug("getResourceAsStream(" + name + ")");

checkStateForResourceLoading(name);

InputStream stream = null;

// (0) Check for a cached copy of this resource
stream = findLoadedResource(name);
if (stream != null) {
if (log.isDebugEnabled())
log.debug("  --> Returning stream from cache");
return (stream);
}

boolean delegateFirst = delegate || filter(name, false);

// (1) Delegate to parent if requested
if (delegateFirst) {
if (log.isDebugEnabled())
log.debug("  Delegating to parent classloader " + parent);
stream = parent.getResourceAsStream(name);
if (stream != null) {
// FIXME - cache???
if (log.isDebugEnabled())
log.debug("  --> Returning stream from parent");
return (stream);
}
}

// (2) Search local repositories
if (log.isDebugEnabled())
log.debug("  Searching local repositories");
URL url = findResource(name);
if (url != null) {
// FIXME - cache???
if (log.isDebugEnabled())
log.debug("  --> Returning stream from local");
stream = findLoadedResource(name);
try {
if (hasExternalRepositories && (stream == null))
stream = url.openStream();
} catch (IOException e) {
// Ignore
}
if (stream != null)
return (stream);
}

// (3) Delegate to parent unconditionally
if (!delegateFirst) {
if (log.isDebugEnabled())
log.debug("  Delegating to parent classloader 
unconditionally " + parent);
stream = parent.getResourceAsStream(name);
if (stream != null) {
// FIXME - cache???
if (log.isDebugEnabled())
log.debug("  --> Returning stream from parent");
return (stream);
}
}

// (4) Resource was not found
if (log.isDebugEnabled())
log.debug("  --> Resource not found, returning null");
return (null);

}
`


---

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



[GitHub] tomcat issue #109: fix: file resource read dir inputStream

2018-05-08 Thread markt-asf
Github user markt-asf commented on the issue:

https://github.com/apache/tomcat/pull/109
  
I came very close to fixing this but in the end I opted not to.

I covered the argument for making this change in my previous comment. The 
reasons against it are:
- it would be a potentially significant API change for 8.0.x, 8.5.x and 
9.0.x
- the behaviour isn't formally specified anywhere and has obvious problems 
with more unusual file names
- My instinct is that null is a better option here

This is probably another issue to take to the Servlet EG once it starts up 
at Eclipse for clarification.


---

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



[GitHub] tomcat issue #109: fix: file resource read dir inputStream

2018-05-08 Thread markt-asf
Github user markt-asf commented on the issue:

https://github.com/apache/tomcat/pull/109
  
The specification is not as explicit as it could be in this case. The spec 
text refers to the Javadoc. The Javadoc says "Returns the resource located at 
the named path as an InputStream object." without any details of how a 
directory object should be represented as an InputStream.

The Javadoc does include references to URL handlers and URLConnection 
objects so it is not unreasonable to assume that similar behaviour is expected.

One concern that I do have with replicating the URLConnection behaviour is 
that it is not designed for file names that include \n. The are passed on 
without escaping and \n is also used as the separator between file names. 
However, that usage is rare and it might be a limitation we have to live with. 
There are other APIs that can be used to get directory listings without 
ambiguity.

Rather than going via URLConnection, I'm leaning towards replicating the 
behaviour. I do want to check if the \n is always used or if it varies with 
platform.


---

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



[GitHub] tomcat issue #109: fix: file resource read dir inputStream

2018-05-07 Thread markt-asf
Github user markt-asf commented on the issue:

https://github.com/apache/tomcat/pull/109
  
I'm not convinced the proposed approach is the right one in this case.


---

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