-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: add sample for HTTP redirect. #21
base: main
Are you sure you want to change the base?
Conversation
/assign @leonm1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! A few small nits, but otherwise LGTM.
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <boost/url/parse.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add tags so the recipes are embeddable in docs? (see other samples)
Basically wrap both plugins in:
// [START serviceextensions_http_redirect]
// [END serviceextensions_http_redirect]
return Action::Continue | ||
}; | ||
let redirect = match url.path() { | ||
"/index.php" => base, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is reusing base needlessly fragile? I wonder what happens if :path ever includes domain. I also find it somewhat harder to read/understand. Maybe we can use dummy.com above, and example.com below in the 301?
// Create stream context. | ||
auto http_context = TestHttpContext(handle_); | ||
|
||
// Expect no-op if no path is specified. (Never expected.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically 3 different tests here (no headers, root path, redirect path), so let's split them up.
_ => None | ||
}; | ||
if let Some(redirect_url) = redirect { | ||
self.send_http_response(301, vec![("Location", redirect_url.as_str())], None); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I think we want to return Action::Pause here.
return FilterHeadersStatus::Continue; | ||
} | ||
if (url->path() == "/index.php") { | ||
sendLocalResponse(301, "", "", {{"Location", "http://www.example.com/"}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For extra clarity:
return FilterHeadersStatus::StopAllIterationAndWatermark;
Signed-off-by: Will Hayworth <[email protected]>
Replaces #1 (somehow my fork got diassociated).