From 7710fd79fb37290dd257325af640a87de049b87c Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 31 Jan 2017 16:58:31 +0100 Subject: [PATCH 1/3] Correct parsing Upload-Concat for final uplaods Addresses https://github.com/tus/tus-resumable-upload-protocol/issues/123 --- concat_test.go | 11 +++++++---- post_test.go | 2 +- unrouted_handler.go | 11 +++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/concat_test.go b/concat_test.go index 8cfd138..e223c42 100644 --- a/concat_test.go +++ b/concat_test.go @@ -118,6 +118,9 @@ func TestConcat(t *testing.T) { Method: "POST", ReqHeader: map[string]string{ "Tus-Resumable": "1.0.0", + // A space between `final;` and the first URL should be allowed due to + // compatibility reasons, even if the specification does not define + // it. Therefore this character is included in this test case. "Upload-Concat": "final; http://tus.io/files/a /files/b/", }, Code: http.StatusCreated, @@ -153,7 +156,7 @@ func TestConcat(t *testing.T) { }, Code: http.StatusOK, ResHeader: map[string]string{ - "Upload-Concat": "final; http://tus.io/files/a http://tus.io/files/b", + "Upload-Concat": "final;http://tus.io/files/a http://tus.io/files/b", "Upload-Length": "10", "Upload-Offset": "10", }, @@ -178,7 +181,7 @@ func TestConcat(t *testing.T) { Method: "POST", ReqHeader: map[string]string{ "Tus-Resumable": "1.0.0", - "Upload-Concat": "final; http://tus.io/files/c", + "Upload-Concat": "final;http://tus.io/files/c", }, Code: http.StatusBadRequest, }).Run(handler, t) @@ -200,7 +203,7 @@ func TestConcat(t *testing.T) { Method: "POST", ReqHeader: map[string]string{ "Tus-Resumable": "1.0.0", - "Upload-Concat": "final; /files/huge", + "Upload-Concat": "final;/files/huge", }, Code: http.StatusRequestEntityTooLarge, }).Run(handler, t) @@ -240,7 +243,7 @@ func TestConcat(t *testing.T) { URL: "", ReqHeader: map[string]string{ "Tus-Resumable": "1.0.0", - "Upload-Concat": "final; ", + "Upload-Concat": "final;", }, Code: http.StatusBadRequest, }).Run(handler, t) diff --git a/post_test.go b/post_test.go index 901f5fb..605ad7c 100644 --- a/post_test.go +++ b/post_test.go @@ -294,7 +294,7 @@ func TestPost(t *testing.T) { "Tus-Resumable": "1.0.0", "Upload-Length": "300", "Content-Type": "application/offset+octet-stream", - "Upload-Concat": "final; http://tus.io/files/a http://tus.io/files/b", + "Upload-Concat": "final;http://tus.io/files/a http://tus.io/files/b", }, ReqBody: strings.NewReader("hello"), Code: http.StatusForbidden, diff --git a/unrouted_handler.go b/unrouted_handler.go index 74bc6e9..7886ef2 100644 --- a/unrouted_handler.go +++ b/unrouted_handler.go @@ -341,8 +341,11 @@ func (handler *UnroutedHandler) HeadFile(w http.ResponseWriter, r *http.Request) if info.IsFinal { v := "final;" for _, uploadID := range info.PartialUploads { - v += " " + handler.absFileURL(r, uploadID) + v += handler.absFileURL(r, uploadID) + " " } + // Remove trailing space + v = v[:len(v)-1] + w.Header().Set("Upload-Concat", v) } @@ -782,7 +785,7 @@ func serializeMeta(meta map[string]string) string { // Parse the Upload-Concat header, e.g. // Upload-Concat: partial -// Upload-Concat: final; http://tus.io/files/a /files/b/ +// Upload-Concat: final;http://tus.io/files/a /files/b/ func parseConcat(header string) (isPartial bool, isFinal bool, partialUploads []string, err error) { if len(header) == 0 { return @@ -793,8 +796,8 @@ func parseConcat(header string) (isPartial bool, isFinal bool, partialUploads [] return } - l := len("final; ") - if strings.HasPrefix(header, "final; ") && len(header) > l { + l := len("final;") + if strings.HasPrefix(header, "final;") && len(header) > l { isFinal = true list := strings.Split(header[l:], " ") From d016e089180c74c3954a6294137efda560de1cb5 Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Wed, 1 Feb 2017 10:29:52 +0100 Subject: [PATCH 2/3] Remove unused dependencies (#103) Using unattended-upgrades --- .infra/group_vars/all/_frey.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.infra/group_vars/all/_frey.yml b/.infra/group_vars/all/_frey.yml index fb94b97..2556281 100644 --- a/.infra/group_vars/all/_frey.yml +++ b/.infra/group_vars/all/_frey.yml @@ -8,7 +8,7 @@ apt_upgrade: false apt_dpkg_configure: true apt_install_state: present apt_clean: true -apt_autoremove: true +apt_autoremove: false # ansistrano roles ansistrano_shared_paths: @@ -29,3 +29,6 @@ hostname: "{{ fqdn.split('.')[0] }}" nodejs_yarn: false nodejs_npm_global_packages: - name: yarn + +# unattended-upgrades +unattended_remove_unused_dependencies: true From 63014c78ccd73c00394b6ce01edf502ab6409a5a Mon Sep 17 00:00:00 2001 From: Mischa ter Smitten Date: Wed, 1 Feb 2017 10:46:36 +0100 Subject: [PATCH 3/3] Cleanup Frey file (#104) --- .infra/Freyfile.hcl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/.infra/Freyfile.hcl b/.infra/Freyfile.hcl index e71eba9..91221cb 100644 --- a/.infra/Freyfile.hcl +++ b/.infra/Freyfile.hcl @@ -111,7 +111,22 @@ install { name = "Install tusd" roles { role = "{{{init.paths.roles_dir}}}/apt/1.4.0" - apt_install = ["apg", "build-essential", "curl", "git-core", "htop", "iotop", "libpcre3", "logtail", "mlocate", "mtr", "psmisc", "telnet", "vim", "wget"] + apt_install = [ + "apg", + "build-essential", + "curl", + "git-core", + "htop", + "iotop", + "libpcre3", + "logtail", + "mlocate", + "mtr", + "psmisc", + "telnet", + "vim", + "wget" + ] } roles { role = "{{{init.paths.roles_dir}}}/unattended-upgrades/1.3.1" @@ -167,7 +182,6 @@ setup { } roles { role = "{{{init.paths.roles_dir}}}/fqdn/1.2.1" - fqdn = "{{lookup('env', 'FREY_DOMAIN')}}" } tasks { file = "path=/mnt/tusd-data state=directory owner=www-data group=ubuntu mode=ug+rwX,o= recurse=yes"