Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Add redirect support for ASIO client - #373

Closed
Will Sackfield (8W9aG) wants to merge 1 commit into
microsoft:masterfrom
8W9aG:add-redirect-support
Closed

Add redirect support for ASIO client#373
Will Sackfield (8W9aG) wants to merge 1 commit into
microsoft:masterfrom
8W9aG:add-redirect-support

Conversation

@8W9aG

Copy link
Copy Markdown
  • Add a checking task that determines whether to
    launch a new request with the redirection
  • Adheres to RFC-2068 10.3 by not allowing more than
    5 redirects
  • Does not allow redirect loops

Let me know if this approach is sound, if so then I will make tests.

* Add a checking task that determines whether to
launch a new request with the redirection
* Adheres to RFC-2068 10.3 by not allowing more than
5 redirects
* Does not allow redirect loops
@8W9aG

Copy link
Copy Markdown
Author

Steve Gates (@stgates) would it be possible to give this a little looksee?

@mobileben

Copy link
Copy Markdown
Contributor

Just curious on this. What happens for any exceptions generated? I've found that when using the .then, exceptions can't be caught. I haven't overly looked at the code for pplx. What I've had to do in my stuff is wrap the call in std::async in order to prevent a SIGTRAP. For example, a simple network error, if you don't do this, will crash the client due to an uncaught exception.

}

pplx::task<http_response> asio_client::maybe_redirect(http_response response, http_request request, std::vector<uri> redirected_uris) {
static const status_code found_status_code = 302;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This constant is already defined here: web::http::status_codes::Found

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldnt we also react to:

  • 301 Moved Permanently
  • 307 Temporary Redirect
  • 308 Permanent Redirect

@garethsb Gareth Sylvester-Bradley (garethsb) Feb 13, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes (with the rules for only redirecting GET and HEAD taken into account). Also, the PR code comments refer to RFC 2068, which has been obsoleted twice-over, with RFC 7231 section 6.4 being the most recent spec I believe. This spec also removes the arbitrary maximum redirect count of 5 and explicitly recommends identifying cycles.

@garethsb

Copy link
Copy Markdown
Contributor

If this were to be added, it would be good to add to http_client_config a common setting that would enable/disable this behaviour in both ASIO and WinHttp implementations (for the latter, see #171)

@garethsb

Gareth Sylvester-Bradley (garethsb) commented Feb 13, 2020

Copy link
Copy Markdown
Contributor

Specifically, config support could be made common for:

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants