Method: HTTP::Request#redirect

Defined in:
lib/http/request.rb

#redirect(uri, verb = @verb) ⇒ Object

Returns new Request with updated uri



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/http/request.rb', line 107

def redirect(uri, verb = @verb)
  headers = self.headers.dup
  headers.delete(Headers::HOST)

  new_body = body.source
  if verb == :get
    # request bodies should not always be resubmitted when following a redirect
    # some servers will close the connection after receiving the request headers
    # which may cause Errno::ECONNRESET: Connection reset by peer
    # see https://github.com/httprb/http/issues/649
    # new_body = Request::Body.new(nil)
    new_body = nil
    # the CONTENT_TYPE header causes problems if set on a get request w/ an empty body
    # the server might assume that there should be content if it is set to multipart
    # rack raises EmptyContentError if this happens
    headers.delete(Headers::CONTENT_TYPE)
  end

  self.class.new(
    verb:           verb,
    uri:            @uri.join(uri),
    headers:        headers,
    proxy:          proxy,
    body:           new_body,
    version:        version,
    uri_normalizer: uri_normalizer
  )
end