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

Add functor to deal with redirect #85

Open
Geramy opened this issue Mar 19, 2019 · 5 comments
Open

Add functor to deal with redirect #85

Geramy opened this issue Mar 19, 2019 · 5 comments
Assignees

Comments

@Geramy
Copy link

Geramy commented Mar 19, 2019

We can call SendRequest and GetReply, but we cannot use the RedirectException, because its not in the header, its in the Implementation .cpp file. It should be in the header so we can handle the exception and get the data. @jgaa

@Geramy
Copy link
Author

Geramy commented Mar 19, 2019

I propose putting it in error.h

struct RedirectException : public RestcCppException {
    RedirectException(const RedirectException&) = default;
    RedirectException(RedirectException &&) = default;

    RedirectException(int redirCode, std::string redirUrl)
    : code{redirCode}, url{std::move(redirUrl)}, RestcCppException("Redirect Exception") {}

    const int code;
    std::string url;
};

@Geramy
Copy link
Author

Geramy commented Mar 19, 2019

For some reason I still can't actually catch the exception, I just get SIGABRT.

@jgaa
Copy link
Owner

jgaa commented Mar 20, 2019

This is an internal exception where the client either retries the request with the redirect-url or gives up, based on the redirect settings.

At the time the server requests a redirect, the client have built up state for the request, and it tries to re-use as much state as possible for the redirected request.

Aborting the request and then building a new one would, under normal circumstances, waste resources. However, if you want to filter or inspect the redirect request before it's executed (or rejected), a predicate functor could accomplish that.

So what I need to know is what your target is? What do you want to do when the server sends a redirect request?

@Geramy
Copy link
Author

Geramy commented Mar 20, 2019

I would like to catch the redirect myself and figure out if I want to continue through the redirection or not. But I would also like to read the Location of the redirect and any other header information.

@jgaa jgaa changed the title RedirectException, Missing from the headers. Add functor to deal with redirect Mar 21, 2019
@jgaa jgaa self-assigned this Mar 21, 2019
@jgaa
Copy link
Owner

jgaa commented Mar 26, 2019

I have added a callback that can look at redirects in "staging" branch. I'll have to write some tests and document it before I can release it in the master branch.

The callback can be set in the Properties, and you can inspect and modify the redirect url. You can throw an exception to abort the redirect. You also have access to the server-reply with all the headers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants