Gitlab Community Edition Instance
Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
cdstar
cdstar
Commits
cecb0da8
Commit
cecb0da8
authored
Mar 18, 2021
by
mhellka
Browse files
Fix typo in TUS header
parent
c54d8871
Pipeline
#209685
passed with stages
in 6 minutes and 12 seconds
Changes
1
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
cdstar-plugins-pom/cdstar-tus/src/main/java/de/gwdg/cdstar/rest/ext/tus/TusBlueprint.java
View file @
cecb0da8
...
...
@@ -21,6 +21,13 @@ import de.gwdg.cdstar.web.common.model.ErrorResponse;
*/
@Blueprint
(
path
=
"/tus"
)
public
class
TusBlueprint
implements
RestBlueprint
{
private
static
final
String
TUS_UPLOAD_METADATA
=
"Upload-Metadata"
;
private
static
final
String
TUS_UPLOAD_EXPIRES
=
"Upload-Expires"
;
private
static
final
String
TUS_UPLOAD_LENGTH
=
"Upload-Length"
;
private
static
final
String
TUS_UPLOAD_OFFSET
=
"Upload-Offset"
;
private
static
final
String
TUS_EXTENSION
=
"Tus-Extension"
;
private
static
final
String
TUS_RESUMABLE
=
"Tus-Resumable"
;
private
static
final
String
TUS_EXTENSIONS
=
"creation,expiration,termination"
;
private
static
final
String
TUS_VERSION
=
"1.0.0"
;
private
final
TusService
chunkService
;
...
...
@@ -55,10 +62,10 @@ public class TusBlueprint implements RestBlueprint {
chunk
.
setMeta
(
meta
);
ctx
.
status
(
201
);
ctx
.
header
(
"Tus-Resumable"
,
TUS_VERSION
);
ctx
.
header
(
TUS_RESUMABLE
,
TUS_VERSION
);
ctx
.
header
(
"Location"
,
ctx
.
resolvePath
(
chunk
.
getName
(),
true
));
if
(
chunk
.
getExpireMillis
()
>
0
)
ctx
.
header
(
"Uplpad-Expires"
,
Date
.
from
(
Instant
.
ofEpochMilli
(
chunk
.
getExpireMillis
())));
ctx
.
header
(
TUS_UPLOAD_EXPIRES
,
Date
.
from
(
Instant
.
ofEpochMilli
(
chunk
.
getExpireMillis
())));
return
null
;
}
...
...
@@ -68,8 +75,8 @@ public class TusBlueprint implements RestBlueprint {
// Server MUST ignore the header.
ctx
.
status
(
204
);
ctx
.
header
(
"Tus-Resumable"
,
TUS_VERSION
);
ctx
.
header
(
"Tus-Extension"
,
TUS_EXTENSIONS
);
ctx
.
header
(
TUS_RESUMABLE
,
TUS_VERSION
);
ctx
.
header
(
TUS_EXTENSION
,
TUS_EXTENSIONS
);
return
null
;
}
...
...
@@ -81,13 +88,13 @@ public class TusBlueprint implements RestBlueprint {
chunk
.
expireIn
(
24
,
TimeUnit
.
HOURS
);
ctx
.
status
(
200
);
ctx
.
header
(
"Tus-Resumable"
,
TUS_VERSION
);
ctx
.
header
(
"Cache-Control"
,
"no-store"
);
ctx
.
header
(
"Upload-Offset"
,
chunk
.
getOffset
());
ctx
.
header
(
TUS_RESUMABLE
,
TUS_VERSION
);
ctx
.
header
(
TUS_UPLOAD_OFFSET
,
chunk
.
getOffset
());
if
(
chunk
.
getLength
()
>
-
1
)
ctx
.
header
(
"Upload-Length"
,
chunk
.
getLength
());
ctx
.
header
(
TUS_UPLOAD_LENGTH
,
chunk
.
getLength
());
if
(
chunk
.
getExpireMillis
()
>
0
)
ctx
.
header
(
"Uplpad-Expires"
,
Date
.
from
(
Instant
.
ofEpochMilli
(
chunk
.
getExpireMillis
())));
ctx
.
header
(
TUS_UPLOAD_EXPIRES
,
Date
.
from
(
Instant
.
ofEpochMilli
(
chunk
.
getExpireMillis
())));
return
null
;
}
...
...
@@ -102,7 +109,7 @@ public class TusBlueprint implements RestBlueprint {
chunkService
.
removeChunk
(
chunk
);
ctx
.
status
(
204
);
ctx
.
header
(
"Tus-Resumable"
,
TUS_VERSION
);
ctx
.
header
(
TUS_RESUMABLE
,
TUS_VERSION
);
return
null
;
}
...
...
@@ -112,11 +119,11 @@ public class TusBlueprint implements RestBlueprint {
final
TusFile
chunk
=
getChunk
(
ctx
.
getPathParam
(
"chunk"
));
ctx
.
status
(
204
);
ctx
.
header
(
"Tus-Resumable"
,
TUS_VERSION
);
ctx
.
header
(
TUS_RESUMABLE
,
TUS_VERSION
);
if
(
chunk
.
getLength
()
>
-
1
)
ctx
.
header
(
"Upload-Length"
,
chunk
.
getLength
());
ctx
.
header
(
TUS_UPLOAD_LENGTH
,
chunk
.
getLength
());
if
(
chunk
.
getExpireMillis
()
>
0
)
ctx
.
header
(
"Uplpad-Expires"
,
Date
.
from
(
Instant
.
ofEpochMilli
(
chunk
.
getExpireMillis
())));
ctx
.
header
(
TUS_UPLOAD_EXPIRES
,
Date
.
from
(
Instant
.
ofEpochMilli
(
chunk
.
getExpireMillis
())));
if
(!
Utils
.
equal
(
ctx
.
getHeader
(
"Content-Type"
),
"application/offset+octet-stream"
))
throw
new
ErrorResponse
(
406
,
"TusError"
,
"Content type MUST be 'application/offset+octet-stream'."
);
...
...
@@ -135,7 +142,7 @@ public class TusBlueprint implements RestBlueprint {
if
(
length
>
-
1
)
{
if
(
chunk
.
getLength
()
==
-
1
)
{
chunk
.
setLength
(
length
);
ctx
.
header
(
"Upload-Length"
,
chunk
.
getLength
());
ctx
.
header
(
TUS_UPLOAD_LENGTH
,
chunk
.
getLength
());
}
else
if
(
length
!=
chunk
.
getLength
())
{
chunk
.
unlock
();
throw
new
ErrorResponse
(
400
,
"TusError"
,
"Cannot change Upload-Length once it has a value."
);
...
...
@@ -150,12 +157,12 @@ public class TusBlueprint implements RestBlueprint {
.
then
(
r
->
{
Utils
.
closeQuietly
(
ch
);
chunk
.
unlock
();
ctx
.
header
(
"Upload-Offset"
,
chunk
.
getOffset
());
ctx
.
header
(
TUS_UPLOAD_OFFSET
,
chunk
.
getOffset
());
ctx
.
close
();
},
err
->
{
Utils
.
closeQuietly
(
ch
);
chunk
.
unlock
();
ctx
.
header
(
"Upload-Offset"
,
chunk
.
getOffset
());
ctx
.
header
(
TUS_UPLOAD_OFFSET
,
chunk
.
getOffset
());
ctx
.
abort
(
err
);
});
...
...
@@ -174,28 +181,32 @@ public class TusBlueprint implements RestBlueprint {
}
private
void
checkTusHeader
(
RestContext
ctx
)
{
if
(!
Utils
.
equal
(
ctx
.
getHeader
(
"Tus-Resumable"
),
TUS_VERSION
))
if
(!
Utils
.
equal
(
ctx
.
getHeader
(
TUS_RESUMABLE
),
TUS_VERSION
))
throw
new
ErrorResponse
(
400
,
"TusError"
,
"Tus-Resumable header missing or wrong version."
)
.
detail
(
"expected"
,
TUS_VERSION
);
}
private
long
getUploadLength
(
RestContext
ctx
)
{
String
lengthHeader
=
ctx
.
getHeader
(
TUS_UPLOAD_LENGTH
);
if
(
lengthHeader
==
null
)
return
-
1
;
try
{
return
Long
.
parseUnsignedLong
(
ctx
.
getHeader
(
"Upload-Length"
));
return
Long
.
parseUnsignedLong
(
ctx
.
getHeader
(
TUS_UPLOAD_LENGTH
));
}
catch
(
final
NumberFormatException
e
)
{
return
-
1
;
throw
new
ErrorResponse
(
400
,
"TusError"
,
"Upload-Length header present, but invalid."
)
;
}
}
private
long
getUploadOffset
(
RestContext
ctx
)
{
try
{
return
Long
.
parseUnsignedLong
(
ctx
.
getHeader
(
"Upload-Offset"
));
return
Long
.
parseUnsignedLong
(
ctx
.
getHeader
(
TUS_UPLOAD_OFFSET
));
}
catch
(
final
NumberFormatException
e
)
{
throw
new
ErrorResponse
(
400
,
"TusError"
,
"Upload-Offset header missing or invalid."
);
}
}
private
String
getUploadMetadata
(
RestContext
ctx
)
{
return
ctx
.
getHeader
(
"Upload-Metadata"
);
return
ctx
.
getHeader
(
TUS_UPLOAD_METADATA
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment