53 Commits

Author SHA1 Message Date
lanefu
c803e4b4e0 Pass scheme (#27)
* pass scheme to get_redirect function instead of checking request object

* remove schema debugging

* Revert "remove schema debugging"

This reverts commit cc81ed7a60.
2021-12-05 21:46:46 -05:00
lanefu
bc5b151252 Pass scheme (#25)
* pass scheme to get_redirect function instead of checking request object
* remove schema debugging
2021-12-04 21:28:02 -05:00
MichaIng
442e7f40d3 Add request scheme response reader to redirects (#23)
This is mainly for debugging: #22

Signed-off-by: MichaIng <micha@dietpi.com>
2021-12-04 20:06:30 -05:00
MichaIng
906d9862ee Add proto/scheme header test for /status entpoint (#20)
When the X-Forwarded-Proto request header is set, the /status endpoint is expected to send the related X-Request-Scheme response header.

Additionally this commit removes unused imports and two trailing spaces.
2021-09-17 16:07:51 -04:00
MichaIng
a4692e7e13 Minor code enhancements (#19)
Only the required methods from json and os modules are imported and the module prefix on method calls removed accordingly.

mirror_path and userdata_path variables are assigned only once if the related environment variable is present.

The userdata_path variable is only assigned in "dl_map" mode.

Signed-off-by: MichaIng <micha@dietpi.com>
2021-09-17 16:07:33 -04:00
lanefu
5577aaf332 Obtain request scheme via proxy header if present (#18)
and pass it via response header for testing and debugging purpose.

Signed-off-by: MichaIng <micha@dietpi.com>

Co-authored-by: MichaIng <micha@dietpi.com>
2021-09-12 15:36:06 -04:00
lanefu
2939b6ca40 close csv file after reading 2021-08-28 13:53:41 -04:00
lanefu
1a1bfc4a16 hotfix userdata path config 2021-08-28 13:31:08 -04:00
lanefu
bf8cb87d33 Append http:// if scheme is missing when dumping mirrors (#16) (#17)
as the armbian-config mirror selector currently requires this, while schemes can be missing since https://github.com/armbian/dl-router/pull/14.

Signed-off-by: MichaIng <micha@dietpi.com>

Co-authored-by: MichaIng <micha@dietpi.com>
2021-08-03 21:43:12 -04:00
MichaIng
0656d6ce04 Remove the URL schemes from mirrors (#15)
* Remove the URL schemes from mirrors

as of: https://github.com/armbian/dl-router/pull/14

Signed-off-by: MichaIng <micha@dietpi.com>

* Remove the URL schemes from mirrors

as of: https://github.com/armbian/dl-router/pull/14

But leave https://minio.k-space.ee untouched as it does a forced HTTPS redirect anyway. That way one additional redirect is prevented, if the client's original request is plain HTTP.

Signed-off-by: MichaIng <micha@dietpi.com>

* Fix syntax in scheme check

Signed-off-by: MichaIng <micha@dietpi.com>
2021-08-03 15:14:33 -04:00
MichaIng
b74ab30143 [AR-604] Preserve protocol from client request if not given in mirror list (#14)
* [AR-604] Preserve protocol from client request if not given in mirror list

Currently redirects are done based on a mirror list with hardcoded URL scheme/protocol. This causes issues when either the client does not support the target protocol (e.g. no HTTPS support) or if the client does not allow its HTTPS request to be downgraded to plain HTTP, either in general or due to respected HSTS information. The usually expected behaviour for redirects is to preserve the protocol of the client request and in case leave HTTPS upgrades to be done by the target server.

This commit aims to implement that behaviour in an optional non-breaking way:
- If the protocol is given in the mirror list, it is used like before. This allows to force a protocol by the router, in case the mirror is not assured to support what the client requests. It is better to let the client decide whether to accept the protocol change or not, instead of letting it doing a request which is doomed to fail.
- If the protocol is not given in the mirror list, it is derived from the client's request scheme. This means that the mirror list needs to be changed for this commit to have any effect.

Signed-off-by: MichaIng <micha@dietpi.com>

* [AR-604] Remove scheme from mirrors with support HTTP + HTTPS

With PR https://github.com/armbian/dl-router/pull/14 mirrors are allowed to be given without URL scheme/protocol in the list file, in which case the client's request protocol is preserved. All currently active mirrors have been tested to support both HTTP and HTTPS and having no forced HTTP => HTTPS redirect. Some mirrors respond with a HSTS header, when connecting via HTTPS, but this cannot break any client request, as obviously the client supports HTTPS when it received the HSTS header once.

The "minio.k-space.ee" mirror is the only one with a forced HTTP => HTTPS redirect, but it is currently not in use. If this mirrors gets re-enabled, to avoid doubled redirects, it makes sense to leave the scheme in place.

Signed-off-by: MichaIng <micha@dietpi.com>
2021-08-03 14:36:36 -04:00
lanefu
e1d242f2ef Merge pull request #13 from jeanrhum/master
read mirrors conf path from env variable
2021-03-17 15:47:17 -04:00
jeanrhum
26b1064f0c Update main.py
Use the environment variable ARMBIAN_MIRROR_CONF to select the mirrors used. Default is the local mirrors.yaml.
2021-03-15 16:04:59 +01:00
jeanrhum
93b110b557 Update main.py
conditionally load uwsgi modiule
2021-03-15 15:11:10 +01:00
Lane Jennison
7632a9d9f6 conditionally load uwsgi modiule 2021-03-15 09:58:36 -04:00
jeanrhum
96d55a9bdd Update main.py
Adding command line parameter to set a mirror config file: https://github.com/armbian/dl-router/issues/12
2021-03-12 18:50:43 +01:00
jeanrhum
31d30a82b3 Update mirror_list.py
Add a mirror path paramater to class Mirror
2021-03-12 18:48:51 +01:00
Lane Jennison
b4940a3da7 dont forget to close the mirror file 2021-03-10 22:19:40 -05:00
lanefu
26434398fe Code Quality Improvements by yaleman
Testing and more pythonic things
2020-12-29 19:37:53 -05:00
James Hodgkinson
283427ab43 whitespace 2020-12-29 21:49:22 +10:00
James Hodgkinson
4a503b6c72 re-introducted reloading 2020-12-29 21:48:21 +10:00
James Hodgkinson
6646589e6c more error checking, fixed a todo 2020-12-29 21:43:38 +10:00
lanefu
8a7b50fa8d Merge pull request #10 from armbian/add-geo
Add support for automatic geo based redirection
2020-12-19 23:09:45 -05:00
Lane Jennison
792cc3750b geoip info in readme 2020-12-19 23:04:45 -05:00
Lane Jennison
121b5f2b1f return none object instead of string 2020-12-19 22:38:38 -05:00