Switch URL protocol for resource links to HTTPS
See original GitHub issueThe parent project has an issue filed to make the resource links the same protocol as the request.
Change URL protocol in response data based on whether the request was made over HTTPS: https://github.com/phalt/swapi/issues/66
Since the swapi.dev server uses HTTPS (it even redirects HTTP to HTTPS) and the world has pretty much switched over to HTTPS, it probably makes sense to just do a simple straight switch to HTTPS. There’s little value in making the response intelligent based on the protocol of the request.
Currently the next
field in responses uses the HTTP protocol:
GET https://swapi.dev/api/vehicles/?format=json
{
"count": 39,
"next": "http://swapi.dev/api/vehicles/?page=2&format=json",
"previous": null,
"results": [
{
"name": "Sand Crawler",
"model": "Digger Crawler",
"manufacturer": "Corellia Mining Corporation",
"cost_in_credits": "150000",
"length": "36.8 ",
"max_atmosphering_speed": "30",
Following the next
link can result in errors like:
Fetch API cannot load http://swapi.dev/api/vehicles/?page=2&format=json due to access control
This problem would be resolved by using HTTPS in the next
field:
"next": "https://swapi.dev/api/vehicles/?page=2&format=json",
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Using Protocol Relative URLs to Switch between HTTP and ...
A relative URL contains the 'offset' URL that needs to be applied to the page's absolute URL in order to find a resource....
Read more >The Complete Guide To Switching From HTTP To HTTPS
The protocol transfers information between the browser and the server in clear text, allowing the network, through which the information passes, ...
Read more >Enabling HTTPS on your servers - web.dev
Steps covered in this article · Enable HTTPS on your servers · Make intrasite URLs relative · Redirect HTTP to HTTPS ...
Read more >How to switch to HTTPS without losing your traffic - SE Ranking
First, let's define what relative and absolute URLs are. An absolute URL contains the entire address of a page including the connection protocol...
Read more >How to Convert HTTP to HTTPS: A Quick Guide (Infographic)
3. Double-Check Internal Linking is Switched to HTTPS. Before going live with the conversion, ensure every website link (internal) has the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@Juriy Well, you’re right. But after
HTTPS=on
Django will stay on plain HTTP and reverse proxy will works correct.Proofs from local testing:
This environment variable is uses only to build absolute URLs. I had search where HTTPS variable is using and not found more places despite this: https://github.com/django/django/blob/b626c289ccf9cc487f97d91c2a45cac096d9d0c7/django/http/request.py#L135
Django has a few more ways to make it return HTTPS URLs, but this way is the easiest and impact only one function (see above), not the whole application.
Hello, @Juriy. I am really glad to see your activity on this project. 😃
To make Django use HTTPS instead of HTTP, set
HTTPS=on
in environment variables.