Adding cookies to my http client

S

Safas Khkjh

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!
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top