Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Jean-Francois Dockes
upmpdcli
Commits
c71b32e2
Commit
c71b32e2
authored
Jan 13, 2021
by
Jean-Francois Dockes
Browse files
Allow streaming binary non-utf8 paths
parent
1b4f8e5b
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/mediaserver/cdplugins/uprcl/bottle.py
View file @
c71b32e2
...
@@ -2866,9 +2866,12 @@ def static_file(filename, root,
...
@@ -2866,9 +2866,12 @@ def static_file(filename, root,
check or continue partial downloads) are also handled automatically.
check or continue partial downloads) are also handled automatically.
"""
"""
if
type
(
filename
)
==
type
(
''
):
root
=
os
.
path
.
join
(
os
.
path
.
abspath
(
root
),
''
)
root
=
os
.
path
.
join
(
os
.
path
.
abspath
(
root
),
''
)
filename
=
os
.
path
.
abspath
(
os
.
path
.
join
(
root
,
filename
.
strip
(
'/
\\
'
)))
filename
=
os
.
path
.
abspath
(
os
.
path
.
join
(
root
,
filename
.
strip
(
'/
\\
'
)))
else
:
root
=
os
.
path
.
join
(
os
.
path
.
abspath
(
root
),
b
''
)
filename
=
os
.
path
.
abspath
(
os
.
path
.
join
(
root
,
filename
.
strip
(
b
'/
\\
'
)))
headers
=
dict
()
headers
=
dict
()
if
not
filename
.
startswith
(
root
):
if
not
filename
.
startswith
(
root
):
...
...
src/mediaserver/cdplugins/uprcl/uprclhttp.py
View file @
c71b32e2
...
@@ -85,18 +85,31 @@ class Streamer(object):
...
@@ -85,18 +85,31 @@ class Streamer(object):
bottle
.
response
.
set_header
(
"Content-type"
,
ctype
)
bottle
.
response
.
set_header
(
"Content-type"
,
ctype
)
bottle
.
response
.
set_header
(
"Content-Length"
,
size
)
bottle
.
response
.
set_header
(
"Content-Length"
,
size
)
return
f
return
f
# Binary paths: transmitted as follows (See bottle._handle())
# binarypath->binarypath.decode('latin1')->urlquote()->NETWORK->
# urlunquote()->encode('latin1').decode('utf-8', 'ignore')
# If there are non utf-8 characters in the path, the result is
# missing them, and file access fails. However, we get the
# binary result from urlunquote)_ in the 'bottle.raw_path'
# request environment variable, and try to use it if the
# normal path is not accessible.
fullpath
=
os
.
path
.
join
(
self
.
root
,
filepath
)
fullpath
=
os
.
path
.
join
(
self
.
root
,
filepath
)
root
=
'/'
if
not
os
.
path
.
exists
(
fullpath
):
if
not
os
.
path
.
exists
(
fullpath
):
uplog
(
"uprcl: no such file: %s"
%
fullpath
)
fullpath
=
bottle
.
request
.
environ
.
get
(
'bottle.raw_path'
)
return
bottle
.
HTTPResponse
(
status
=
404
)
fullpath
=
fullpath
.
encode
(
'latin1'
)
root
=
b
'/'
if
not
os
.
path
.
exists
(
fullpath
):
uplog
(
"uprcl: no such file: %s"
%
fullpath
)
return
bottle
.
HTTPResponse
(
status
=
404
)
uplog
(
"Streaming: %s "
%
fullpath
)
uplog
(
"Streaming: %s "
%
fullpath
)
mutf
=
mutagen
.
File
(
fullpath
)
mutf
=
mutagen
.
File
(
fullpath
)
if
mutf
:
if
mutf
:
return
bottle
.
static_file
(
f
ile
path
,
root
=
self
.
root
,
return
bottle
.
static_file
(
f
ull
path
,
root
=
root
,
mimetype
=
mutf
.
mime
[
0
])
mimetype
=
mutf
.
mime
[
0
])
else
:
else
:
return
bottle
.
static_file
(
f
ile
path
,
root
=
self
.
root
)
return
bottle
.
static_file
(
f
ull
path
,
root
=
root
)
# Bottle handle both the streaming and control requests.
# Bottle handle both the streaming and control requests.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment