Repository: paperless-ngx/paperless-ngx

Issue:
[BUG] Rest API responds with wrong URI prefix for next pagination
### Description

It seems the API replies with a fixed (or wrong) URI to http within the json response. 

### Steps to reproduce

Attempting to get a list of correspondents via rest API using CURL as such:

`curl -vvv --header 'authorization: Token MY_TOKEN' https://host:443/api//correspondents/`

will respond with the following JSON:

`{"count":28,"next":"http://host/api/correspondents/?page=2","previous": [..]`

for some reason, the URI provided in the "next" key defaults to http and strips the port.
This means any api sdk such as pypaperless will fail to get paginated results, if the paperless instance 
is not exposed via http, too.

In my case im accessing the instance via NGINX Reverse Proxy, which might play into this issue 
It think the json response should contain the correct host.

### Webserver logs

```bash
No logs.
```


### Browser logs

_No response_

### Paperless-ngx version

1.13.0

### Host OS

Debian 11

### Installation method

Bare metal

### Browser

_No response_

### Configuration changes

_No response_

### Other

_No response_


Discussion:
The pagination is a lightly customized [PageNumberPagination](https://www.django-rest-framework.org/api-guide/pagination/#pagenumberpagination).  So nothing in here I can find directly sets the next field.

If you try directly, without the proxy, is the response correct?
I just tried with an instance which sits behind Traefik and a local instance.  (and I used tags, but the pagination is the same).

Local instance kept the port, as expected.  Proxy instance kept the host as well.  

It did replace the HTTPS with HTTP, which seems counter to the example in their documentation.  I'd suggest going to the source: https://github.com/encode/django-rest-framework/issues.  I don't find any issue there currently that seems to fit.
I don't have the time this evening to investigate all the settings, but this looks relevant: https://stackoverflow.com/questions/42818940/django-rest-framework-pagination-links-do-not-use-https
Alright, it looks like setting [SECURE_PROXY_SSL_HEADER](https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-SECURE_PROXY_SSL_HEADER) will return HTTPS in the next.  It does come with some large warning boxes, but we can provide the option to set it for users who understand those warnings and want it.
I can confirm that setting the configuration does the job for at least the protocol.
In addition i guess  HTTP_X_FORWARDED_PORT might be required too.
```
grep SECURE_PROXY_SSL_HEADER src/paperless/settings.py 
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
PAPERLESS_CONFIGURATION_PATH=/home/paperless/current/paperless.conf python3 src/manage.py print_settings | grep SECURE_PROXY_SSL_HEADER
SECURE_PROXY_SSL_HEADER                  = ('HTTP_X_FORWARDED_PROTO', 'https')

```

now pagination response at least includes correct protocol in URI:

{"count":30,"next":"https://host/api/correspondents/?page=2","previous":null,"results




Resolving patch:
diff --git a/src/paperless/settings.py b/src/paperless/settings.py
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@ -431,6 +431,14 @@ def _parse_beat_schedule() -> Dict:
 # For use with trusted proxies
 TRUSTED_PROXIES = __get_list("PAPERLESS_TRUSTED_PROXIES")
 
+USE_X_FORWARDED_HOST = __get_boolean("PAPERLESS_USE_X_FORWARD_HOST", "false")
+USE_X_FORWARDED_PORT = __get_boolean("PAPERLESS_USE_X_FORWARD_PORT", "false")
+SECURE_PROXY_SSL_HEADER = (
+    tuple(json.loads(os.environ["PAPERLESS_PROXY_SSL_HEADER"]))
+    if "PAPERLESS_PROXY_SSL_HEADER" in os.environ
+    else None
+)
+
 # The secret key has a default that should be fine so long as you're hosting
 # Paperless on a closed network.  However, if you're putting this anywhere
 # public, you should change the key to something unique and verbose.


Test patch: