title: RXSwift: Modifying URLRequest if request fails in `retryWhen`
body: <p>I need to modify the headers of the request when the request fails but the request doesn't change when I modify the request in <code>retryWhen</code></p>
  
  <p>Here is my implementation:</p>
  
  <pre><code>func makeRequest(serviceRequest: URLRequest) {
      let maxRetry = 2
      var localRequest = serviceRequest
      request(request: localRequest).retryWhen { errors in
          return errors.enumerated().flatMap { (arg) -&gt; Observable&lt;Int64&gt; in
              localRequest.setValue("someValue", forHTTPHeaderField: "someKey")
  
              let (index, error) = arg
              return index &lt;= maxRetry ? Observable&lt;Int64&gt;.timer(DispatchTimeInterval.microseconds(4),
                                                                 scheduler: MainScheduler.instance) : Observable.error(error)
          }
      }.subscribe(onNext:{ result in
          print(result)
  
          }).disposed(by: disposeBag)
  }
  </code></pre>
  
  <p>If I <code>po localRequest</code> after set headers <code>someKey</code> it would show my changes but if I <code>po request</code> in the request function the request remains the same with no changes. Any of you knows what can I do to changes the request in the <code>retryWhen</code> ?</p>
  
  <p>I'll really appreciate your help.</p>