tl;dr Temp solution for Twitter gem https://gist.github.com/waynepan/5218264
Details:
Solved the mystery, but I’ve reached my limits of network knowledge so need some help here. SSL seems to be a red herring.
Faraday sends “Connection: close” header by default and Twitter echoes this.
Setup
url = "http://api.twitter.com/1.1/users/show.json?user_id=33978"
conn = Faraday.new(:url => url) do |faraday|
faraday.adapter :net_http
end
Normal Faraday request
1.9.3p194 :256 > conn.get
Faraday::Error::ConnectionFailed: end of file reached
and TCP stream:
GET /1.1/users/show.json?user_id=33978 HTTP/1.1
User-Agent: Faraday v0.8.6
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: /
Connection: close
Host: api.twitter.com
HTTP/1.1 400 Bad Request
content-type: application/json; charset=utf-8
date: Fri, 22 Mar 2013 01:03:27 UTC
server: tfe
set-cookie: guest_id=v1%3A136391420724649092; Domain=.twitter.com; Path=/; Expires=Sun, 22-Mar-2015 01:03:27 UTC
Transfer-Encoding: chunked
Content-Encoding: gzip
Connection: close
Now, leaving Connection header empty
conn.headers = { ‘Connection’ => “” }
conn.get
TCP Stream:
GET /1.1/users/show.json?user_id=33978 HTTP/1.1
Connection:
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: /
User-Agent: Ruby
Host: api.twitter.com
HTTP/1.1 400 Bad Request
content-type: application/json; charset=utf-8
date: Fri, 22 Mar 2013 01:13:57 UTC
server: tfe
set-cookie: guest_id=v1%3A136391483755534473; Domain=.twitter.com; Path=/; Expires=Sun, 22-Mar-2015 01:13:57 UTC
Transfer-Encoding: chunked
Content-Encoding: gzip
CURL even returns 18 error code (w/ Connection: close)
wp$ curl -v --compressed --header “Connection: close” http://api.twitter.com/1.1/users/show.json?user_id=33978
GET /1.1/users/show.json?user_id=33978 HTTP/1.1
User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
Host: api.twitter.com
Accept: /
Accept-Encoding: deflate, gzip
Connection: close
< HTTP/1.1 400 Bad Request
< content-type: application/json; charset=utf-8
< date: Fri, 22 Mar 2013 01:19:38 UTC
< server: tfe
< set-cookie: guest_id=v1%3A136391517818400799; Domain=.twitter.com; Path=/; Expires=Sun, 22-Mar-2015 01:19:38 UTC
< Transfer-Encoding: chunked
< Content-Encoding: gzip
< Connection: close
<
- transfer closed with outstanding read data remaining
- Closing connection #0
curl: (18) transfer closed with outstanding read data remaining
{“errors”:[{“message”:“Bad Authentication data”,“code”:215}]}
w/o any Connection header
wp$ curl -v --compressed http://api.twitter.com/1.1/users/show.json?user_id=33978
GET /1.1/users/show.json?user_id=33978 HTTP/1.1
User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8r zlib/1.2.5
Host: api.twitter.com
Accept: /
Accept-Encoding: deflate, gzip
< HTTP/1.1 400 Bad Request
< content-type: application/json; charset=utf-8
< date: Fri, 22 Mar 2013 01:20:45 UTC
< server: tfe
< set-cookie: guest_id=v1%3A136391524591891982; Domain=.twitter.com; Path=/; Expires=Sun, 22-Mar-2015 01:20:45 UTC
< Transfer-Encoding: chunked
< Content-Encoding: gzip
<
- Connection #0 to host api.twitter.com left intact
{“errors”:[{“message”:“Bad Authentication data”,“code”:215}]}* Closing connection #0
At this point, my knowledge of what’s the proper behavior for Connection: close is supposed to be. CURL reporting error 18 (transfer closed) is troubling though.