⚲
Project
General
Profile
Sign in
Register
Home
Projects
Help
Search
:
Ruby master
All Projects
Ruby
»
Ruby master
Overview
Activity
Roadmap
Issues
Repository
Like
Download (642 Bytes)
Feature #14275
ยป net-http-readbody.rb
normalperson (Eric Wong)
, 01/03/2018 01:52 AM
require
'net/http'
require
'digest/md5'
Thread
.
abort_on_exception
=
true
s
=
TCPServer
.
new
(
'127.0.0.1'
,
0
)
len
=
1024
*
1024
*
1024
*
1
th
=
Thread
.
new
do
c
=
s
.
accept
c
.
readpartial
(
16384
).
clear
c
.
write
(
"HTTP/1.0 200 OK
\r\n
Content-Length:
#{
len
}
\r\n\r\n
"
)
IO
.
copy_stream
(
'/dev/zero'
,
c
,
len
)
c
.
close
end
addr
=
s
.
addr
Net
::
HTTP
.
start
(
addr
[
3
],
addr
[
1
])
do
|
http
|
http
.
request_get
(
'/'
)
do
|
res
|
dig
=
Digest
::
MD5
.
new
res
.
read_body
{
|
buf
|
dig
.
update
(
buf
)
# memory use nearly increases 10x without String#clear,
# maybe GC could be more aggressive?
# buf.clear
}
puts
dig
.
hexdigest
end
end
(1-1/1)
Loading...