-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bugfix/gzip #35
base: master
Are you sure you want to change the base?
Bugfix/gzip #35
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic cleanup & consolidation in data_to_bytes_iterator()
and send_body_encoded()
. I've read through them and to me it does look like you've correctly captured the slightly different usages of this code nicely with a bunch of great simplifications along the way!
I don't have any way to really test this myself other than the unit tests run here in Actions - which fail but they fail in the same way as the master branch :-) so it's equivalent as far as that goes!
@@ -250,6 +205,8 @@ def _HEAD_GET(self, with_body=False): | |||
content_type = 'text/html;charset=utf-8' | |||
else: | |||
content_type = dc.get_prop(uri, "DAV:", "getcontenttype") | |||
if content_type == 'httpd/unix-directory': | |||
content_type = 'text/html;charset=utf-8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What inspired this change?
I'm not sure what the webdav spec suggests, however a google of webdav mime "httpd/unix-directory"
gets a lot of hits; it seems to be pretty common?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a WebDAV response, but a standard HTTP GET/HEAD response returning the list of files as a HTML. Serving the HTML file as httpd/unix-directory makes no sense. It breaks the webbrowser pointed at that URL, while WebDAV clients would nevertheless use the WebDAV method PROPFIND and not the GET/HEAD.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah ok, that makes sense. I didn't actually realise the server would serve "regular" http requests as well as webdav ones.
if os.path.isdir(path): | ||
for filename in self.index_files: | ||
new_path = os.path.join(path, filename) | ||
if os.path.isfile(new_path): | ||
path = new_path | ||
break | ||
else: | ||
msg = self._get_listing(path) | ||
return Resource(StringIO(msg), len(msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gather this index file handing is quite non-standard for webdav servers?
Does this mean that if it's enabled and you try to view a folder that's got an index style file in it, you get served that file rather than the directory listing?
by default is disabled
Looking at the code, is an end user expected to edit this python file to add filenames to index_files = ()
above?
Or have to create a wrapper script that imports this, injects the names, then start the server programatically?
For this to be included I think it'd need at least some docs, if not a command line argument to enable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-
WebDAV allows that behavior:
http://www.webdav.org/specs/rfc4918.html#rfc.section.9.4 -
I intended it to be extended via inheritance, like this:
class CustomFilesystemHandler(FilesystemHandler):
mimecheck = True
index_files = ("index.html",)
However I see it would be better if I write some docs for that feature.
log.debug("Don't use iterator") | ||
|
||
for buf in data: | ||
yield buf if isinstance(buf, six.binary_type) else str(buf).encode('utf-8') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be safer as:
yield buf if isinstance(buf, six.binary_type) else str(buf).encode('utf-8') | |
yield buf if isinstance(buf, six.binary_type) else bytes(buf, 'utf-8') |
Using str(buf)
could cause an undesired output if buf
happens to be something that doesn't implicitely convert to the str cleanly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just throw exception in such case? This should be str or bytes anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well I don't think it's an expected error, throwing an exception is ugly useful if you're going to catch and deal with it somewhere.
Without tracing the code through I could see it potentially being a bytearray, or a future change might want to change it to one...
This was more of a best practices suggestion, if you want to convert the object to a bytes it's better to convert in one step, rather than convert to str first and then to bytes.
httpd/unix-directory
makes no sense with a HTML listing of a directory.