From 2c258c65ec2bda02139347c1ba4ad4b6f0a2e2f8 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 30 Apr 2021 13:03:48 +0200 Subject: [PATCH 1/3] support tus.io standard --- docker/nginx/conf.d/client.conf | 15 +++++++++++++-- docker/nginx/conf.d/include/cors | 10 +++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index d0e8f4fa..4df2be9e 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -317,7 +317,6 @@ server { location /skynet/skyfile { include /etc/nginx/conf.d/include/cors; - include /etc/nginx/conf.d/include/sia-auth; limit_req zone=uploads_by_ip burst=100 nodelay; limit_req zone=uploads_by_ip_throttled; @@ -329,7 +328,6 @@ server { proxy_read_timeout 600; proxy_request_buffering off; # stream uploaded files through the proxy as it comes in proxy_set_header Expect $http_expect; - proxy_set_header User-Agent: Sia-Agent; # Extract 2 sets of 2 characters from $request_id and assign to $dir1, $dir2 # respectfully. The rest of the $request_id is going to be assigned to $dir3. @@ -379,6 +377,19 @@ server { } } + # endpoing implementing resumable file uploads open protocol https://tus.io + location /skynet/tus { + include /etc/nginx/conf.d/include/cors; + + client_max_body_size 1000M; # make sure to limit the size of upload to a sane value + proxy_read_timeout 600; + proxy_request_buffering off; # stream uploaded files through the proxy as it comes in + proxy_set_header Expect $http_expect; + + # proxy /skynet/tus requests to siad endpoint with all arguments + proxy_pass http://siad; + } + location ~ "^/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" { include /etc/nginx/conf.d/include/cors; include /etc/nginx/conf.d/include/proxy-buffer; diff --git a/docker/nginx/conf.d/include/cors b/docker/nginx/conf.d/include/cors index 7a969986..6399a91c 100644 --- a/docker/nginx/conf.d/include/cors +++ b/docker/nginx/conf.d/include/cors @@ -1,8 +1,8 @@ if ($request_method = 'OPTIONS') { more_set_headers 'Access-Control-Allow-Origin: $http_origin'; more_set_headers 'Access-Control-Allow-Credentials: true'; - more_set_headers 'Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, PUT, PATH, DELETE'; - more_set_headers 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-HTTP-Method-Override,upload-offset,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size'; + more_set_headers 'Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE'; + more_set_headers 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-HTTP-Method-Override,upload-offset,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,location'; more_set_headers 'Access-Control-Max-Age: 1728000'; more_set_headers 'Content-Type: text/plain; charset=utf-8'; more_set_headers 'Content-Length: 0'; @@ -11,6 +11,6 @@ if ($request_method = 'OPTIONS') { more_set_headers 'Access-Control-Allow-Origin: $http_origin'; more_set_headers 'Access-Control-Allow-Credentials: true'; -more_set_headers 'Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, PUT, PATH, DELETE'; -more_set_headers 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-HTTP-Method-Override,upload-offset,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size'; -more_set_headers 'Access-Control-Expose-Headers: Content-Length,Content-Range,Skynet-File-Metadata,Skynet-Skylink,Skynet-Portal-Api,upload-offset,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size'; +more_set_headers 'Access-Control-Allow-Methods: GET, POST, HEAD, OPTIONS, PUT, PATCH, DELETE'; +more_set_headers 'Access-Control-Allow-Headers: DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-HTTP-Method-Override,upload-offset,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,location'; +more_set_headers 'Access-Control-Expose-Headers: Content-Length,Content-Range,Skynet-File-Metadata,Skynet-Skylink,Skynet-Portal-Api,upload-offset,upload-length,tus-version,tus-resumable,tus-extension,tus-max-size,location'; From 07bd6ef883deace8721d3b313d00815399898398 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 30 Apr 2021 13:50:46 +0200 Subject: [PATCH 2/3] user agent --- docker/nginx/conf.d/client.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index 4df2be9e..bdbbc3a0 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -328,6 +328,7 @@ server { proxy_read_timeout 600; proxy_request_buffering off; # stream uploaded files through the proxy as it comes in proxy_set_header Expect $http_expect; + proxy_set_header User-Agent: Sia-Agent; # Extract 2 sets of 2 characters from $request_id and assign to $dir1, $dir2 # respectfully. The rest of the $request_id is going to be assigned to $dir3. From fb2193c3d023492f1560c7a4e8fa33a00e8da683 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Fri, 30 Apr 2021 13:59:50 +0200 Subject: [PATCH 3/3] restore sia-auth --- docker/nginx/conf.d/client.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/docker/nginx/conf.d/client.conf b/docker/nginx/conf.d/client.conf index bdbbc3a0..9f65212a 100644 --- a/docker/nginx/conf.d/client.conf +++ b/docker/nginx/conf.d/client.conf @@ -317,6 +317,7 @@ server { location /skynet/skyfile { include /etc/nginx/conf.d/include/cors; + include /etc/nginx/conf.d/include/sia-auth; limit_req zone=uploads_by_ip burst=100 nodelay; limit_req zone=uploads_by_ip_throttled;