36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/yup/state.rb', line 36
def make_request(req)
begin
@http_method, @request_url, , body = req
= Hash[*.to_a.flatten.map(&:to_s)]
["Host"] = @forward_to
["Connection"] = "Close"
req = "#{@http_method.upcase} #{@request_url} HTTP/1.1\r\n"
.each do |k, v|
req << "#{k}: #{v}\r\n"
end
req << "\r\n"
req << body if !body.empty?
raw_response = send_data(req.to_s, @forward_to)
response_body = ""
http = Http::Parser.new()
http.on_body = proc do |chunk|
response_body << chunk
end
http << raw_response
if http.status_code && http.status_code / 100 == 2
log_response(raw_response, response_body, http)
@logger.info "Success"
else
log_response(raw_response, response_body, http)
if Yup.retry_unless_2xx
@logger.info "Fail: got status code #{http.status_code}; will retry after #{Yup.resend_delay} seconds"
@state.pushback(Yajl::Encoder.encode([@http_method.downcase, @request_url, , body]))
sleep Yup.resend_delay
else
@logger.info "Fail; will not retry"
end
end
rescue Exception, Timeout::Error => e
log_response(raw_response, response_body, http)
@logger.info "Error: #{e.class}: #{e.message}; will retry after #{Yup.resend_delay} seconds"
@state.pushback(Yajl::Encoder.encode([@http_method.downcase, @request_url, , body]))
sleep Yup.resend_delay
end
end
|