Adding cookies to my http client

Discussion in 'Ruby' started by Safas Khkjh, Jul 12, 2010.

  1. Safas Khkjh

    Safas Khkjh Guest

    Hi,
    The following is a modified version of the http client found in the
    o'reilly ruby cookbook.

    Does any one know how I can add custom cookies to this?


    class HTTP
    # Makes an HTTP reuqest and returns the HTTPRespnse object.
    # Args: :proxy_host, :proxy_port, :action :)get, :post, etc.),
    # :data (for :post action), :max_redirects.

    def HTTP.fetch(uri, args={}.freeze, &before_fetching)
    # Process the arguments with default values
    uri = URI.parse(URI.encode(uri)) unless uri.is_a? URI
    proxy_host = args[:proxy_host]
    proxy_port = args[:proxy_port] || 80
    action = args[:action] || :get
    data = args[:data]
    max_redirects = args[:max_redirects] || 10
    cookies = args[:cookies] || ''

    # Set http headers
    headers = {'Cookie' => cookies}

    # Use proxy class to create the request object
    proxy_class = Proxy(proxy_host, proxy_port)
    request = proxy_class.new(uri.host, uri.port)

    # Organise the query
    if action == 'get'
    query = uri.path.to_s + "?" + uri.query.to_s
    else
    query = uri.path.to_s + '/'
    end

    response = request.send(action, query, data)


    return response

    end


    Thank you in advance!
    --
    Posted via http://www.ruby-forum.com/.
     
    Safas Khkjh, Jul 12, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,503
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,541
    Fredrik Lindner
    Nov 6, 2003
  3. _Who
    Replies:
    7
    Views:
    2,686
  4. Bruno Antunes

    net/http - adding an HTTP method

    Bruno Antunes, Apr 3, 2009, in forum: Ruby
    Replies:
    1
    Views:
    124
    Eric Hodel
    Apr 3, 2009
  5. Mario Ruiz

    adding cookies net/http

    Mario Ruiz, Mar 8, 2011, in forum: Ruby
    Replies:
    1
    Views:
    215
    7stud --
    Mar 8, 2011
Loading...

Share This Page