From b0c5448547c7bf25b1838061e7ced6738f7c4867 Mon Sep 17 00:00:00 2001 From: Anderson Freitas Date: Wed, 17 Jul 2024 14:50:38 -0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20Pagination=20returns=20the=20HTT?= =?UTF-8?q?P=20protocol=20in=20a=20production=20environment,=20but=20it=20?= =?UTF-8?q?should=20return=20the=20HTTPS=20protocol.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pagination returns the HTTP protocol in a production environment, but it should return the HTTPS protocol. --- rest_framework/pagination.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rest_framework/pagination.py b/rest_framework/pagination.py index a543ceeb5..0239482f8 100644 --- a/rest_framework/pagination.py +++ b/rest_framework/pagination.py @@ -275,9 +275,16 @@ class PageNumberPagination(BasePagination): def get_next_link(self): if not self.page.has_next(): return None - url = self.request.build_absolute_uri() + + current_protocol = self.request.scheme + current_host = self.request.get_host() + current_path = self.request.path page_number = self.page.next_page_number() - return replace_query_param(url, self.page_query_param, page_number) + param = self.page_query_param + + url = f'{current_protocol}://{current_host}{current_path}?{param}={page_number}' + + return url def get_previous_link(self): if not self.page.has_previous():