question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Switch URL protocol for resource links to HTTPS

See original GitHub issue

The 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:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
leonidpodrizcommented, Jun 17, 2021

@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: Screenshot 2021-06-17 at 17 28 12

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.

1reaction
leonidpodrizcommented, Jun 17, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found