# File lib/protocols/httpclient.rb, line 92
 92:   def send_request args
 93:     args[:verb] ||= args[:method] # Support :method as an alternative to :verb.
 94:     args[:verb] ||= :get # IS THIS A GOOD IDEA, to default to GET if nothing was specified?
 95: 
 96:     verb = args[:verb].to_s.upcase
 97:     unless ["GET", "POST", "PUT", "DELETE", "HEAD"].include?(verb)
 98:       set_deferred_status :failed, {:status => 0} # TODO, not signalling the error type
 99:       return # NOTE THE EARLY RETURN, we're not sending any data.
100:     end
101: 
102:     request = args[:request] || "/"
103:     unless request[0,1] == "/"
104:       request = "/" + request
105:     end
106: 
107:     qs = args[:query_string] || ""
108:     if qs.length > 0 and qs[0,1] != '?'
109:       qs = "?" + qs
110:     end
111: 
112:     # Allow an override for the host header if it's not the connect-string.
113:     host = args[:host_header] || args[:host] || "_"
114:     # For now, ALWAYS tuck in the port string, although we may want to omit it if it's the default.
115:     port = args[:port]
116: 
117:     # POST items.
118:     postcontenttype = args[:contenttype] || "application/octet-stream"
119:     postcontent = args[:content] || ""
120:     raise "oversized content in HTTP POST" if postcontent.length > MaxPostContentLength
121: 
122:     # ESSENTIAL for the request's line-endings to be CRLF, not LF. Some servers misbehave otherwise.
123:     # TODO: We ASSUME the caller wants to send a 1.1 request. May not be a good assumption.
124:     req = [
125:       "#{verb} #{request}#{qs} HTTP/1.1",
126:       "Host: #{host}:#{port}",
127:       "User-agent: Ruby EventMachine",
128:     ]
129: 
130:     if verb == "POST" || verb == "PUT"
131:       req << "Content-type: #{postcontenttype}"
132:       req << "Content-length: #{postcontent.length}"
133:     end
134: 
135:     # TODO, this cookie handler assumes it's getting a single, semicolon-delimited string.
136:     # Eventually we will want to deal intelligently with arrays and hashes.
137:     if args[:cookie]
138:       req << "Cookie: #{args[:cookie]}"
139:     end
140: 
141:     req << ""
142:     reqstring = req.map {|l| "#{l}\r\n"}.join
143:     send_data reqstring
144: 
145:     if verb == "POST" || verb == "PUT"
146:       send_data postcontent
147:     end
148:   end