Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
Proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open-source
Proxy
Merge requests
!20
Resolve "Fix Downloading of files"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Fix Downloading of files"
20-fix-downloading-of-files
into
master
Overview
0
Commits
4
Pipelines
0
Changes
3
Merged
Dominik Hebeler
requested to merge
20-fix-downloading-of-files
into
master
4 years ago
Overview
0
Commits
4
Pipelines
0
Changes
3
Expand
Closes
#20 (closed)
Edited
4 years ago
by
Dominik Hebeler
0
0
Merge request reports
Viewing commit
e867b0c1
Prev
Next
Show latest version
3 files
+
33
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
3
Search (e.g. *.vue) (Ctrl+P)
e867b0c1
Merge branch 'master' into 20-fix-downloading-of-files
· e867b0c1
Dominik Hebeler
authored
4 years ago
app/Http/Controllers/ProxyController.php
+
31
−
0
Options
@@ -197,6 +197,37 @@ class ProxyController extends Controller
$httpcode
=
$answer
[
"http-code"
];
extract
(
parse_url
(
$targetUrl
));
$base
=
$scheme
.
"://"
.
$host
;
$headerArray
=
[];
foreach
(
$answer
[
"headers"
]
as
$index
=>
$value
)
{
if
(
strtolower
(
$index
)
===
"location"
)
{
$redLink
=
$value
;
if
(
strpos
(
$redLink
,
"/"
)
===
0
)
{
$parse
=
parse_url
(
$url
);
$redLink
=
$parse
[
"scheme"
]
.
"://"
.
$parse
[
"host"
]
.
$redLink
;
}
elseif
(
preg_match
(
"/^\w+\.\w+$/si"
,
$redLink
))
{
$parse
=
parse_url
(
$url
);
$redLink
=
$parse
[
"scheme"
]
.
"://"
.
$parse
[
"host"
]
.
"/"
.
$redLink
;
}
$key
=
md5
(
$request
->
ip
()
.
microtime
(
true
));
$headerArray
[
trim
(
$index
)]
=
$this
->
proxifyUrl
(
$redLink
,
null
,
$key
,
false
);
}
elseif
(
strtolower
(
$index
)
===
"content-disposition"
)
{
$headerArray
[
strtolower
(
trim
(
$index
))]
=
strtolower
(
trim
(
$value
));
}
else
{
$headerArray
[
trim
(
$index
)]
=
trim
(
$value
);
}
}
$answer
[
"headers"
]
=
$headerArray
;
# It might happen that a server doesn't give Information about file Type.
# Let's try to generate one in this case
if
(
!
isset
(
$answer
[
"headers"
][
"content-type"
]))
{
$finfo
=
new
finfo
(
FILEINFO_MIME
);
$answer
[
"headers"
][
"content-type"
]
=
$finfo
->
buffer
(
base64_decode
(
$answer
[
"body"
]));
}
# We will parse whether we have a parser for this document type.
# If not, we will not Proxy it:
$contentTypeHeader
=
$answer
[
"headers"
][
"content-type"
];
Loading