Restforce, a Streaming API, and an innapropriate hostname 😱

If you've ever tried to use the Restforce gem to connect to their Streaming API in a Ruby project lately, you've probably run into an error.

CookieJar::InvalidCookieError: Domain is inappropriate based on request URI hostname

There is some discussion about the cause of this error over at GitHub restforce/restforce/issues/120. What we do know is that this is caused by Salesforce, and there won't by a fix within the cookiejar gem.

To work around this issue we can create a module that implements a method with the same signature but skips the actual validation if the cookie is from "". Include the snippet below into a file that is loaded by your application to override the method raising the error.

You can test if Salesforce updated their cookie to conform to the RFC mentioned in the cookiejar gem, comment out the last line in the snippet and run your test.