Crystal: Closing HTTP GET block slow

Created on 17 Jul 2018  路  2Comments  路  Source: crystal-lang/crystal

Hello,

I think this is a crystal issue since it takes a long time befor the HTTP block is closed.

It takes some minutes between the printing of "Ended" and the printing of "Finished"

```require "http/client"

puts "Started"
HTTP::Client.get("https://watermark.silverchair.com/mend1909.pdf?token=AQECAHi208BE49Ooan9kkhW_Ercy7Dm3ZL_9Cf3qfKAc485ysgAAAakwggGlBgkqhkiG9w0BBwagggGWMIIBkgIBADCCAYsGCSqGSIb3DQEHATAeBglghkgBZQMEAS4wEQQMAjr8LZwe31Bm9AqZAgEQgIIBXN9SuLOXb6ap_Zf2km9Qq0G2U2fOYV9zD_0iTR1qpfsez56aEmeDC0cOUzkmIvAV1dRw_BrT4QLaHV0RRf1dGcBGGhyUGyySEY3AAGHDfosZp8bGqxX0P9zaSLR5NLfGeMebEp-HaCppusgsZoZOn1lsP2MZNh638CLArOuCx8PGbzM44tPtOQhfrIIt2A3XpPRIINkOyeCWMPrE3u86KQHUaEcrVQYgKq60K35ZdewE0CwWdbVVriM6D8pZJtK5bfnrtCvATwJ17KJdATQWRqJEYrQipgxMSPrWu8sSkljENw2K3M9CU-PEFRYb4P9HqbAs2DEz8nOmrC-TRNCil6Fjm9hVsW4KnS7kNoJs6TxVD5DUoE8AwWAe4VFSbDupFBKe90cIWiDFq97BTtX7qnIZnWqIg_DBA3NdNGsgg3GiBWs7v_xgi1sJxxF0pyM5RMX8J5KoYsM5uWEJmg") do |response|
puts "Start saving"
File.write("output/result.pdf", response.body_io)
puts "Ended"
end

puts "Finished"
```

bug stdlib

Most helpful comment

Since HTTP::Client requests are oneshots (we never reuse the connection) maybe we could add the connection: close header by default, at least for .get, .post, etc. The server would send the response then close it immediately, avoiding keepalive.

All 2 comments

It looks like you only leave the block when the connection is closed by the server.

When you use the "Connection: close" header in the in the request, the connection is immediately closed when the response is fully send and you can immediately leave the block.

Since HTTP::Client requests are oneshots (we never reuse the connection) maybe we could add the connection: close header by default, at least for .get, .post, etc. The server would send the response then close it immediately, avoiding keepalive.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lgphp picture lgphp  路  3Comments

oprypin picture oprypin  路  3Comments

lbguilherme picture lbguilherme  路  3Comments

ArthurZ picture ArthurZ  路  3Comments

Papierkorb picture Papierkorb  路  3Comments