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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
db69659f
Commit
db69659f
authored
Jan 26, 2018
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add HTTP::IO
parent
249e61ab
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
152 additions
and
1 deletion
+152
-1
app/uploaders/job_artifact_uploader.rb
app/uploaders/job_artifact_uploader.rb
+1
-1
lib/gitlab/ci/trace/http_io.rb
lib/gitlab/ci/trace/http_io.rb
+151
-0
No files found.
app/uploaders/job_artifact_uploader.rb
View file @
db69659f
...
...
@@ -18,7 +18,7 @@ class JobArtifactUploader < GitlabUploader
if
file_storage?
File
.
open
(
path
,
"rb"
)
else
raise
'Only File System is supported'
Gitlab
::
Ci
::
Trace
::
HTTP_IO
.
new
(
url
,
size
)
end
end
...
...
lib/gitlab/ci/trace/http_io.rb
0 → 100644
View file @
db69659f
require
'net/http'
##
#
# This class is compatible with IO class (https://ruby-doc.org/core-2.3.1/IO.html)
# source: https://gitlab.com/snippets/1685610
module
Gitlab
module
Ci
class
Trace
class
HTTP_IO
BUFFER_SIZE
=
128
*
1024
attr_reader
:uri
,
:size
attr_reader
:tell
attr_reader
:chunk
,
:chunk_range
def
initialize
(
url
,
size
)
@uri
=
URI
(
url
)
@size
=
size
@tell
=
0
end
def
close
end
def
binmode
end
def
path
true
end
def
seek
(
pos
,
where
)
new_pos
=
case
where
when
IO
::
SEEK_END
size
+
pos
when
IO
::
SEEK_SET
pos
when
IO
::
SEEK_CUR
tell
+
pos
else
-
1
end
raise
'new position is outside of file'
if
new_pos
<
0
||
new_pos
>
size
@tell
=
new_pos
end
def
eof?
tell
==
size
end
def
each_line
while
!
eof?
do
line
=
read_line
yield
(
line
)
end
end
def
read
out
=
""
loop
do
data
=
get_chunk
break
if
data
.
empty?
out
+=
data
@tell
+=
data
.
bytesize
end
out
end
def
readline
out
=
""
data
=
get_chunk
while
!
data
.
empty?
do
new_line
=
data
.
index
(
'\n'
)
if
!
new_line
.
nil?
out
=
data
[
0
..
new_line
]
@tell
+=
new_line
+
1
break
elsif
data
.
empty?
break
else
out
=
data
@tell
+=
data
.
bytesize
data
=
get_chunk
end
end
out
end
def
write
(
data
)
throw
NotImplementedException
end
def
truncate
(
offset
)
throw
NotImplementedException
end
def
flush
throw
NotImplementedException
end
def
present?
true
end
private
def
in_range?
@chunk_range
&
.
include?
(
tell
)
end
def
get_chunk
unless
in_range?
response
=
Net
::
HTTP
.
start
(
uri
.
hostname
,
uri
.
port
,
use_ssl:
uri
.
scheme
==
'https'
)
do
|
http
|
http
.
request
(
request
)
end
@chunk
=
response
.
body
.
force_encoding
(
Encoding
::
BINARY
)
@chunk_range
=
response
.
content_range
end
@chunk
[
chunk_offset
..
BUFFER_SIZE
]
end
def
request
Net
::
HTTP
::
Get
.
new
(
uri
).
tap
do
|
request
|
puts
"Requesting chunk:
#{
chunk_start
}
-
#{
chunk_end
}
"
request
.
set_range
(
chunk_start
,
BUFFER_SIZE
)
end
end
def
chunk_offset
tell
%
BUFFER_SIZE
end
def
chunk_start
(
tell
/
BUFFER_SIZE
)
*
BUFFER_SIZE
end
def
chunk_end
[
chunk_start
+
BUFFER_SIZE
,
size
].
min
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