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
Pleroma
pleroma
Commits
8e825471
Verified
Commit
8e825471
authored
Dec 12, 2017
by
href
Browse files
fix content-type and fallback to image/jpeg
parent
9093b2cf
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/media_proxy/controller.ex
View file @
8e825471
...
...
@@ -33,10 +33,11 @@ defp proxy_request(link) do
options
=
[
:insecure
,
{
:follow_redirect
,
true
}]
with
\
{
:ok
,
200
,
headers
,
client
}
<-
:hackney
.
request
(
:get
,
link
,
headers
,
""
,
options
),
{
:ok
,
body
}
<-
proxy_request_body
(
client
)
headers
=
Enum
.
into
(
headers
,
Map
.
new
),
{
:ok
,
body
}
<-
proxy_request_body
(
client
),
content_type
<-
proxy_request_content_type
(
headers
,
body
)
do
headers
=
Enum
.
into
(
headers
,
Map
.
new
)
{
:ok
,
headers
[
"Content-Type"
],
body
}
{
:ok
,
content_type
,
body
}
else
{
:ok
,
status
,
_
,
_
}
->
Logger
.
warn
"MediaProxy: request failed, status
#{
status
}
, link:
#{
link
}
"
...
...
@@ -73,5 +74,10 @@ defp proxy_request_body(client, _) do
{
:error
,
:body_too_large
}
end
# TODO: the body is passed here as well because some hosts do not provide a content-type.
# At some point we may want to use magic numbers to discover the content-type and reply a proper one.
defp
proxy_request_content_type
(
headers
,
_body
)
do
headers
[
"Content-Type"
]
||
headers
[
"content-type"
]
||
"image/jpeg"
end
end
Write
Preview
Supports
Markdown
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