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

fix: fixes redirects #7136

Merged
merged 2 commits into from
Jul 26, 2022
Merged

fix: fixes redirects #7136

merged 2 commits into from
Jul 26, 2022

Conversation

stephanegigandet
Copy link
Contributor

The recent refactor of init() -> init_request() broke the way we did redirects (e.g. when someone make a request for https://fr-fr.openfoodfacts.org/categorie/cafe , we redirect to https://fr.openfoodfacts.org/categorie/cafes )

In fact previously it only worked for requests proceessed by display.pl (so everything except URLs starting by /cgi/)

This fixes it and ensure the request is terminated as soon as we have determined that we should redirect to a different url.

Copy link
Member

@alexgarel alexgarel left a comment

Choose a reason for hiding this comment

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

I approve, but I think you forgot to export the function !

@@ -435,6 +435,33 @@ sub process_template($template_filename, $template_data_ref, $result_content_ref
}


=head2 redirect($status_code, $redirect_url)
Copy link
Member

Choose a reason for hiding this comment

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

to @yuktea : typically a function that, when we will split is part of "http utils" more than display.

@@ -435,6 +435,33 @@ sub process_template($template_filename, $template_data_ref, $result_content_ref
}


=head2 redirect($status_code, $redirect_url)
Copy link
Member

Choose a reason for hiding this comment

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

didn't you forget to add it to export ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, I'll add it. I just noticed I was also exporting init which has been renamed to init_request


$r->headers_out->set(Location => $redirect_url);
$r->status($status_code);
# note: under mod_perl, exit() will end the request without terminating the Apache mod_perl process
Copy link
Member

Choose a reason for hiding this comment

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

thanks for the comment :-)

lib/ProductOpener/Display.pm Show resolved Hide resolved
@@ -472,7 +499,7 @@ sub init_request() {
$bodyabout = '';
$admin = 0;

my $r = shift;
my $r = Apache2::RequestUtil->request();
Copy link
Member

Choose a reason for hiding this comment

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

you can remove the code below:

	if (not defined $r) {
		$r = Apache2::RequestUtil->request();
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks

@sonarcloud
Copy link

sonarcloud bot commented Jul 26, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@stephanegigandet stephanegigandet merged commit ad78f9e into main Jul 26, 2022
@stephanegigandet stephanegigandet deleted the fix-redirects branch July 26, 2022 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants