Class: Grope::WebResourceLoadDelegate

Inherits:
NSObject
  • Object
show all
Defined in:
lib/grope/web_resource_load_delegate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

Returns the value of attribute cookie_storage.



3
4
5
# File 'lib/grope/web_resource_load_delegate.rb', line 3

def cookie_storage
  @cookie_storage
end

Instance Method Details

#webView_resource_didReceiveResponse_fromDataSource(webview, resource, response, data_source) ⇒ Object



24
25
26
# File 'lib/grope/web_resource_load_delegate.rb', line 24

def webView_resource_didReceiveResponse_fromDataSource(webview, resource, response, data_source)
  set_cookies(response)
end

#webView_resource_willSendRequest_redirectResponse_fromDataSource(webview, resource, request, redirect_response, data_source) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/grope/web_resource_load_delegate.rb', line 5

def webView_resource_willSendRequest_redirectResponse_fromDataSource(webview, resource, request, redirect_response, data_source)
  request.setHTTPShouldHandleCookies(false)

  if request.URL.to_s =~ /^http/
    if redirect_response
      set_cookies(redirect_response)
    end

    cookies = cookie_storage.cookies(URI(request.URL.to_s)).map {|wrapper| wrapper.cookie}
    if cookies.size > 0
      #warn "*** send cookie for %s ***\n%s" % [request.URL.to_s, cookies]
      cookie_fields = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies)
      request.setAllHTTPHeaderFields(cookie_fields)
    end
  end

  request
end