Guest14 has quit [Quit: Ping timeout (120 seconds)]
TrufflePump has joined #ruby
<Ziyan>
I have a favour to ask. I am trying to convert a cURL request to use Net::HTTP. I am getting an error "EOFError: end of file reached". I have been looking at this for hours with no success. Looking at the documentation, I think I have done it right. I'd appreciate if one with experience working with Proxies with Net::HTTP/Faraday help me out. https://gist.github.com/ziyan-junaideen/4fe8e8937caada5d9e35a11884d7cb37
TrufflePump has quit [Ping timeout: 258 seconds]
<adam12>
Ziyan: Run net_http_example.rb directly and get a better stacktrace. The line numbers dont' match in the one you provide.
<adam12>
Ziyan: It could be a rack-mini_profiler issue too.
<adam12>
Since I think it monkeypatches net/http
Guest14 has joined #ruby
<Ziyan>
adam12 Thanks... an extension of last Friday's discussion...
<Ziyan>
I updated the Gist with the Ruby file and the stack trace
<Ziyan>
let me try run completely separately in a new gemset...
Guest14 has quit [Quit: Ping timeout (120 seconds)]
<adam12>
Ziyan: could try running with rdbg and configure post mortem
<adam12>
maybe you can go up stack and see if it indicates failure.
TrufflePump has joined #ruby
TrufflePump has quit [Ping timeout: 246 seconds]
bbenno has joined #ruby
work has quit [Quit: Connection closed for inactivity]
<havenwood>
Ziyan: Seems like `use_ssl` isn't working in yours? I dunno why on first glance, but couldn't reproduce redoing the request.
<havenwood>
Net::HTTP is not my cup of tea.
<Ziyan>
havenwood this issue happens the moment the proxy comes to the equation. Without the proxy stuff, it works fine.
<havenwood>
Ziyan: Does that ^ gist work for you with the proxy?
<havenwood>
Ziyan: Odd...
<Ziyan>
havenwood there is no error when there is no proxy involved... your code should work, i tried some thing very similar.
<Ziyan>
The issue happens when the proxy comes to picture
<Ziyan>
I was using the ruby-debug-ide on VSCode.
<Ziyan>
It turns out that the HTTP class connects to the proxy using TCP. Then it uses a BufferedIO instance to write some thing like "CONNECT eoftqqzi7ii7mmn.m.pipedream.net:443 HTTP/1.1\r\nHost: eoftqqzi7ii7mmn.m.pipedream.net:443\r\nProxy-Authorization: Basic VVN3OWhiUTFQUmh0NlF1M2FZR3pnZE5qOmYxZjRmY2RmLTFhN2ItNDdhZS1iMDU1LTNhOGRhNWYwNmQyMA==\r\n\r\n" to the socket.
<Ziyan>
HTTPResponse.read_new(plain_sock).value is where it fails
<Ziyan>
it is trying to read from the socket `sock.readline => end of file reached`
<Ziyan>
I wonder if its the proxy. But then how did the cURL work. I think there are some VPNS that give SOCKS proxies. I think I will look for some SOCKS proxies I can get my hands on and see if I can get the code to work.
jpn has joined #ruby
<Ziyan>
adam12 so I tried the debugger and walked the code. HTTP opens a socket and tries to write auth details to it and things like URI. The error happens because `sock.readline` is at end of file. I think I will try another SOCKS proxy to confirm its not this VGS proxy that is causing issue.
<adam12>
Ziyan: So I was wrong. I thought SOCKS == HTTP but that's not correct.
<havenwood>
Ziyan: I see what you're saying, gotcha. I was just looking at the cURL command only. >.>
<adam12>
Ziyan: Using the proxy is definitely the issue, and it's expecting a HTTP proxy. I tried with a SOCKS proxy and it won't work.
<adam12>
I can get it to work by installing a local copy of Squid
<adam12>
Ziyan: Try enabling verbose mode and maybe see if that helps.
<adam12>
http.set_debug_output $stderr
<adam12>
(after setting ca_file is a good spot)
<Ziyan>
adam12 I see. I am completely dumb about proxies. I slept through TCP lessons and lab work at uni. But I have worked with Squid. I wanted a name to try the code. But since you tried, I can leave it aside for now. Thanks.
<adam12>
Ziyan: Can you compare output to curl -vvv?
<adam12>
I'm curious about the Proxy-Authorization header.
<adam12>
You don't set a Content-Type header but I'm not sure that matters yet, at you're not that far.
gproto23 has quit [Ping timeout: 258 seconds]
onyx has joined #ruby
<Ziyan>
adam12 updated the gist again... i am going to update the Ruby file and see if he content type makes a difference
<adam12>
Ziyan: It's definitely strange.
<adam12>
My guess is it's on the proxies' end. Maybe it doesn't like your user agent or something.
<adam12>
Actually that's not a good guess, because I don't think it sent that header yet.
<Ziyan>
Content type header had no effect, as you said the failure happens before that as I see in the code.
<weaksauc_>
hmm could the windows style linebreaks be causing an issue?
RedNifre has quit [Quit: changing power source]
<Ziyan>
weaksauc_ suggest to replace the HTTP's \r\n with just \n ? Let me try 🤭
<Ziyan>
nope, \r\n => \n didn't work out
___nick___ has quit [Ping timeout: 260 seconds]
<weaksauc_>
worth a shot i guess
Neopolitan4 has joined #ruby
<Ziyan>
weaksauc_ absolutely
Neopolitan has quit [Ping timeout: 258 seconds]
Neopolitan4 is now known as Neopolitan
_ht has quit [Remote host closed the connection]
jpn has quit [Ping timeout: 260 seconds]
gschanuel has joined #ruby
<Ziyan>
adam12 weaksauc_ havenwood thanks for the help guys, its 2AM in Sri Lanka. I was updating the issue. I am going to check back tomorrow. Have a good day.
Common-Lisp has quit [Remote host closed the connection]