Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
illwieckz opened this issue Aug 16, 2019 · 5 comments

Comments

@illwieckz
Copy link
Member

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
Copy link
Member Author

illwieckz commented Aug 16, 2019

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;
	}
}

@slipher
Copy link
Contributor

slipher commented Aug 16, 2019

Minor correction: updater uses aria2 rather than curl.

@illwieckz
Copy link
Member Author

illwieckz commented Aug 16, 2019

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

@illwieckz illwieckz changed the title updater, curl and redirects (add support to the later) add support for http redirect Aug 16, 2019
illwieckz added a commit to illwieckz/unvanquished-updater that referenced this issue Aug 17, 2019
server already rewrites content to fix urls and does more than just
rewriting protocol, it also takes care of www prefix,
see Unvanquished#41 (comment)
for some information about how it was done server side
@illwieckz
Copy link
Member Author

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

@illwieckz
Copy link
Member Author

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

@illwieckz illwieckz changed the title add support for http redirect Qt feature we use to download blog posts and blog images does not support HTTP redirect Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants