updater icon indicating copy to clipboard operation
updater copied to clipboard

Qt feature we use to download blog posts and blog images does not support HTTP redirect

Open illwieckz opened this issue 5 years ago • 5 comments

currently updater does not handle http redirect, it may be convenient to support them so we can update url in the future without using teapots.

illwieckz avatar Aug 16 '19 01:08 illwieckz

For reference, this is the (current) nginx code I wrote to keep alive the updater after the removal of www and the switch to https because redirects are not handled (and https is not supported on all os, see #37). Note that this code also contains code to keep engine happy since it does not support redirect neither https yet.

# Redirect http://www.unvanquished.net to https://unvanquished.net
# unless it may be fetched by updater v0.0.5 (json, images…)
# also rewrite json on the fly in this case
server {
	listen	80;
	listen	[::]:80;

	server_name www.unvanquished.net;

	access_log /var/log/nginx/www.unvanquished.net.access.log;
	error_log /var/log/nginx/www.unvanquished.net.error.log;

	# letsencrypt
	location /.well-known/acme-challenge {
		root /path/to/unvanquished.net;
	}

	# images fetched by updater v0.0.5
	location /wp-content/uploads/ {
		access_log off;

		proxy_pass https://localhost:443;
		proxy_set_header Host unvanquished.net;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}

	# latest articles json fetched by updater v0.0.5
	# http://www.unvanquished.net/?json=get_recent_posts
	location / {
		access_log off;

		# updater does not support redirect
		# but we now redirect http to https
		# and www.unvanquished.net
		# to unvanquished.net
		# by default, so we have to serve
		# this content with a teapot 🍵
		if ($arg_json = get_recent_posts) {
			return 418;
		}

		rewrite ^(.*)$ https://unvanquished.net$1 permanent;
	}

	# return 200 OK code from teapot
	error_page 418 =200 @teapot;

	location @teapot {
		# serve content with teapot
		proxy_pass https://localhost:443;
		proxy_set_header Host unvanquished.net;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

		# rewrite json on the fly
		# to translate https to http
		# and add missing www
		sub_filter_types application/json;
		sub_filter "https:\/\/unvanquished.net\/wp-content\/uploads\/" "http:\/\/www.unvanquished.net\/wp-content\/uploads\/";
		sub_filter "https:\/\/www.unvanquished.net\/wp-content\/uploads\/" "http:\/\/www.unvanquished.net\/wp-content\/uploads\/";
		sub_filter_once off;
	}
}
# Redirect http://dl.unvanquished.net to https://dl.unvanquished.net
# unless it may be fetched by updater v0.0.5 (json) or engine (pkg/)
server {
	listen	80;
	listen	[::]:80;

	server_name dl.unvanquished.net;

	access_log /var/log/nginx/dl.unvanquished.net.access.log;
	error_log /var/log/nginx/dl.unvanquished.net.error.log;

	root /path/to/dl.unvanquished.net;

	# letsencrypt
	location /.well-known/acme-challenge {
	}

	# updater
	location /versions.json {
	}

	# in-game download does not support https
	# by adding the trailing / to the location we redirect /pkg to https but serve /pkg/* as http
	# game never list the directory, we can redirect users to https
	location /pkg/ {
		try_files $uri $uri/ index.php;
		autoindex on;
	}

	location / {
		access_log off;
		rewrite ^(.*)$ https://dl.unvanquished.net$1 permanent;
	}
}

illwieckz avatar Aug 16 '19 01:08 illwieckz

Minor correction: updater uses aria2 rather than curl.

slipher avatar Aug 16 '19 13:08 slipher

Hmm, right, that probably does not change so much, does aria2 support HTTP redirect?

illwieckz avatar Aug 16 '19 18:08 illwieckz

Aria2 is used for the torrent part, it's possible the news part use some Qt builtin.

illwieckz avatar Aug 17 '19 01:08 illwieckz

Aria2 supports redirect, that's Qt (blog post and images downloading) that does not support HTTP redirect.

illwieckz avatar Jan 05 '21 01:01 illwieckz