Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Has re-added code for using value of "retry-after" header as waiting time if status_code = 429 #472

Merged
merged 3 commits into from Aug 4, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS.md
Expand Up @@ -71,6 +71,10 @@
* More forms of empty query are recognized as such. Eliminates a source of
spurious trailing `?` and `?=` in URLs produced by `modify_url()`.
(@jennybc, #452)

* If the server returns HTTP status code 429 and specifies a `retry-after`
value, that value will now be used instead of exponential backoff with
jitter, unless it's smaller than `pause_min`. (@nielsoledam, #472)

# httr 1.2.1

Expand Down
6 changes: 6 additions & 0 deletions R/retry.R
Expand Up @@ -9,6 +9,8 @@
#' randomly waits up to twice as long. (Technically it uses exponential
#' backoff with jitter, using the approach outlined in
#' \url{https://www.awsarchitectureblog.com/2015/03/backoff.html}.)
#' If the server returns status code 429 and specifies a \code{retry-after} value, that
#' value will be used instead, unless it's smaller than \code{pause_min}.
#'
#' @inheritParams VERB
#' @inheritParams GET
Expand Down Expand Up @@ -91,6 +93,10 @@ backoff_full_jitter <- function(i, resp, pause_base = 1, pause_cap = 60,
error_description <- ""
status <- status_code(resp)
}
if (status == 429) {
retry_after <- resp$headers[["retry-after"]]
if (!is.null(retry_after)) length <- max(pause_min, as.numeric(retry_after))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please put the condition code inside of {} (indented like the rest of the code)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this what you meant?

}
message(error_description, "Request failed [", status, "]. Retrying in ", round(length, 1), " seconds...")
}
Sys.sleep(length)
Expand Down