unwire / handsoap

Handsoap is a library for creating SOAP clients in Ruby
http://github.com/unwire/handsoap
225 stars 58 forks source link

[patch] Add cookie support to Curb connections #4

Closed rud closed 15 years ago

rud commented 15 years ago

Some services require a session-cookie to be maintained between requests, for instance [1].

I've created a small change to the Curb connector to support this. Please pull from: http://github.com/rud/handsoap/tree/reuse-curb-instance

[1] https://www.e-conomic.com/secure/api1/EconomicWebService.asmx

rud commented 15 years ago

Btw, to enable cookie support for the curb driver, add the following to your initializer after applying the patch:

Handsoap.http_driver = :curb Handsoap::Http.drivers[:curb].http_client.enable_cookies = true

rud commented 15 years ago

The relevant feature-adding commit is this: http://github.com/rud/handsoap/commit/acaa5f5ec94147a752cde5d001ccebb9b6c516c3

troelskn commented 15 years ago

Since the refactoring to enable async http, this patch can't be applied directly. I've integrated it manually instead. Notice that I made some changes; I do not like to let the driver maintain state by default, as this could lead to some very hard-to-track-down bugs. To use it, you'll have to override the method http_driver_instance in your service class. Eg.:

class MyService < Handsoap::Service
  def http_driver_instance
    unless @driver_instance
      @driver_instance = Handsoap::Http.drivers[Handsoap.http_driver].new
      @driver_instance.enable_cookies = true
    end
    @driver_instance
  end
end

Currently, only the curb driver implements support for enable_cookies, although I assume the other drivers have similar capabilities (or it could be implemented in the abstraction layer)

rud commented 15 years ago

I suspected you had a reason for creating new instances for each request, even though it clashed with my use-case.

Your suggested service-change is clean and explicit - I'll be integrating it in my service shortly.

Thank you for the quick feedback and integration! :)