Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
a3d8a7e6
Commit
a3d8a7e6
authored
Jun 29, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow blob to be redirected
parent
fbdf9008
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
34 additions
and
3 deletions
+34
-3
lib/container_registry/client.rb
lib/container_registry/client.rb
+34
-3
No files found.
lib/container_registry/client.rb
View file @
a3d8a7e6
...
@@ -7,6 +7,13 @@ module ContainerRegistry
...
@@ -7,6 +7,13 @@ module ContainerRegistry
MANIFEST_VERSION
=
'application/vnd.docker.distribution.manifest.v2+json'
MANIFEST_VERSION
=
'application/vnd.docker.distribution.manifest.v2+json'
# Taken from: FaradayMiddleware::FollowRedirects
REDIRECT_CODES
=
Set
.
new
[
301
,
302
,
303
,
307
]
# Regex that matches characters that need to be escaped in URLs, sans
# the "%" character which we assume already represents an escaped sequence.
URI_UNSAFE
=
/[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]%]/
def
initialize
(
base_uri
,
options
=
{})
def
initialize
(
base_uri
,
options
=
{})
@base_uri
=
base_uri
@base_uri
=
base_uri
@faraday
=
Faraday
.
new
(
@base_uri
)
do
|
conn
|
@faraday
=
Faraday
.
new
(
@base_uri
)
do
|
conn
|
...
@@ -34,7 +41,7 @@ module ContainerRegistry
...
@@ -34,7 +41,7 @@ module ContainerRegistry
def
blob
(
name
,
digest
,
type
=
nil
)
def
blob
(
name
,
digest
,
type
=
nil
)
headers
=
{}
headers
=
{}
headers
[
'Accept'
]
=
type
if
type
headers
[
'Accept'
]
=
type
if
type
response_body
@faraday
.
get
(
"/v2/
#{
name
}
/blobs/
#{
digest
}
"
,
nil
,
headers
)
response_body
@faraday
.
get
(
"/v2/
#{
name
}
/blobs/
#{
digest
}
"
,
nil
,
headers
)
,
allow_redirect:
true
end
end
def
delete_blob
(
name
,
digest
)
def
delete_blob
(
name
,
digest
)
...
@@ -61,8 +68,32 @@ module ContainerRegistry
...
@@ -61,8 +68,32 @@ module ContainerRegistry
conn
.
adapter
:net_http
conn
.
adapter
:net_http
end
end
def
response_body
(
response
)
def
response_body
(
response
,
allow_redirect:
false
)
response
.
body
if
response
.
success?
if
allow_redirect
&&
REDIRECT_CODES
.
include?
(
response
.
status
)
response
=
redirect_response
(
response
.
env
[
'url'
],
response
.
headers
[
'location'
])
end
response
.
body
if
response
&&
response
.
success?
end
def
redirect_response
(
url
,
location
)
return
unless
location
url
+=
safe_escape
(
location
)
# We use HTTParty due to fact that @faraday contains internal authorization token
HTTParty
.
get
(
url
)
end
# Taken from: FaradayMiddleware::FollowRedirects
# Internal: escapes unsafe characters from an URL which might be a path
# component only or a fully qualified URI so that it can be joined onto an
# URI:HTTP using the `+` operator. Doesn't escape "%" characters so to not
# risk double-escaping.
def
safe_escape
(
uri
)
uri
.
to_s
.
gsub
(
URI_UNSAFE
)
{
|
match
|
'%'
+
match
.
unpack
(
'H2'
*
match
.
bytesize
).
join
(
'%'
).
upcase
}
end
end
end
end
end
end
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