Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-tus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
libvmod-tus
Commits
658a0eee
Unverified
Commit
658a0eee
authored
Oct 18, 2021
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move response status into a struct
parent
448109bc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
39 deletions
+44
-39
tus_request.c
src/tus_request.c
+31
-31
tus_response.c
src/tus_response.c
+7
-7
tus_response.h
src/tus_response.h
+6
-1
No files found.
src/tus_request.c
View file @
658a0eee
...
...
@@ -251,7 +251,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
struct
tus_concat
*
c
;
VCL_BLOB
hash
;
AZ
(
r
->
status
);
AZ
(
r
->
s
.
s
tatus
);
AZ
(
r
->
fcore
);
if
(
http_GetHdr
(
ctx
->
http_req
,
hdr_method
,
&
p
))
{
...
...
@@ -264,18 +264,18 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
(
void
)
http_GetHdr
(
ctx
->
http_req
,
hdr_origin
,
&
r
->
origin
);
if
(
m
==
_INVALID
)
{
r
->
status
=
405
;
r
->
s
.
s
tatus
=
405
;
return
(
0
);
}
if
(
m
==
OPTIONS
)
{
r
->
status
=
204
+
(
s_OPTIONS
*
s_MULT
);
r
->
s
.
s
tatus
=
204
+
(
s_OPTIONS
*
s_MULT
);
return
(
0
);
}
if
(
m
!=
GET
&&
(
!
http_GetHdr
(
ctx
->
http_req
,
hdr_resum
,
&
p
)
||
strcmp
(
p
,
"1.0.0"
)
!=
0
))
{
r
->
status
=
412
;
r
->
s
.
s
tatus
=
412
;
return
(
0
);
}
...
...
@@ -286,21 +286,21 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
type
=
TUS_FINAL
;
concat
+=
6
;
}
else
{
r
->
status
=
400
;
r
->
s
.
s
tatus
=
400
;
return
(
0
);
}
}
if
(
m
==
POST
&&
type
==
TUS_FINAL
)
{
if
(
tus_file_final_concat
(
tussrv
,
&
embryo
,
concat
)
==
NULL
)
{
r
->
status
=
400
;
r
->
s
.
s
tatus
=
400
;
return
(
0
);
}
hash
=
tus_concat_hash
(
ctx
,
embryo
.
srv
,
embryo
.
concat
);
if
(
hash
!=
NULL
)
{
id
=
tus_hex
(
ctx
,
hash
);
if
(
id
==
NULL
)
{
r
->
status
=
503
;
r
->
s
.
s
tatus
=
503
;
return
(
0
);
}
}
...
...
@@ -310,7 +310,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
tus_metadata_validate
(
metadata
,
NULL
)
==
0
)
{
VSLb
(
ctx
->
vsl
,
SLT_Error
,
"%s: bad metadata format"
,
tus_server_name
(
tussrv
));
r
->
status
=
400
;
r
->
s
.
s
tatus
=
400
;
return
(
0
);
}
...
...
@@ -330,7 +330,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
if
(
lock
==
EBUSY
)
{
AZ
(
r
->
fcore
);
r
->
status
=
423
;
r
->
s
.
s
tatus
=
423
;
return
(
0
);
}
...
...
@@ -352,45 +352,45 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
tus_file_final_abort
(
&
embryo
);
}
else
{
tus_file_final_birth
(
&
r
->
fcore
,
&
embryo
);
r
->
status
=
r
->
fcore
?
201
:
500
;
r
->
s
.
s
tatus
=
r
->
fcore
?
201
:
500
;
}
}
if
(
m
==
DELETE
)
{
if
(
r
->
fcore
==
NULL
)
{
r
->
status
=
404
;
r
->
s
.
s
tatus
=
404
;
return
(
0
);
}
tus_file_del
(
&
r
->
fcore
);
AZ
(
r
->
fcore
);
r
->
status
=
204
;
r
->
s
.
s
tatus
=
204
;
}
if
(
m
==
GET
)
{
if
(
r
->
fcore
==
NULL
)
{
r
->
status
=
404
;
r
->
s
.
s
tatus
=
404
;
return
(
0
);
}
AN
(
r
->
fcore
);
AN
(
fdisk
);
if
(
fdisk
->
location_length
>
0
)
{
r
->
status
=
301
;
/* done file */
r
->
s
.
s
tatus
=
301
;
/* done file */
}
else
{
tus_file_unlock
(
&
r
->
fcore
);
AZ
(
r
->
fcore
);
r
->
status
=
400
;
r
->
s
.
s
tatus
=
400
;
}
return
(
0
);
}
if
(
m
==
HEAD
)
{
r
->
status
=
r
->
fcore
?
200
:
404
;
r
->
s
.
s
tatus
=
r
->
fcore
?
200
:
404
;
return
(
0
);
}
if
(
r
->
fcore
==
NULL
)
{
r
->
status
=
(
m
==
POST
)
?
409
:
404
;
r
->
s
.
s
tatus
=
(
m
==
POST
)
?
409
:
404
;
return
(
0
);
}
...
...
@@ -408,7 +408,7 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
if
(
http_GetHdr
(
ctx
->
http_req
,
hdr_len
,
&
p
))
{
if
(
type
==
TUS_FINAL
)
{
r
->
status
=
400
;
r
->
s
.
s
tatus
=
400
;
return
(
0
);
}
...
...
@@ -418,11 +418,11 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
}
if
(
http_GetHdr
(
ctx
->
http_req
,
hdr_defer
,
&
p
))
{
if
(
len
!=
UINTMAX_MAX
||
type
==
TUS_FINAL
)
{
r
->
status
=
400
;
r
->
s
.
s
tatus
=
400
;
return
(
0
);
}
if
(
strcmp
(
p
,
"1"
)
!=
0
)
{
r
->
status
=
409
;
// or 400 ?
r
->
s
.
s
tatus
=
409
;
// or 400 ?
return
(
0
);
}
}
...
...
@@ -431,14 +431,14 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
if
(
fdisk
->
upload_length
==
-
1
)
fdisk
->
upload_length
=
len
;
else
if
(
len
!=
fdisk
->
upload_length
)
{
r
->
status
=
409
;
// or 400 ?
r
->
s
.
s
tatus
=
409
;
// or 400 ?
return
(
0
);
}
}
if
(
type
==
TUS_FINAL
)
{
if
(
m
!=
POST
)
{
r
->
status
=
403
;
r
->
s
.
s
tatus
=
403
;
tus_file_unlock
(
&
r
->
fcore
);
AZ
(
r
->
fcore
);
return
(
0
);
...
...
@@ -451,14 +451,14 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
switch
(
m
)
{
case
PATCH
:
{
if
(
!
ct_ok
)
{
r
->
status
=
415
;
r
->
s
.
s
tatus
=
415
;
return
(
0
);
}
if
(
off
!=
fdisk
->
upload_offset
)
{
r
->
status
=
409
;
r
->
s
.
s
tatus
=
409
;
return
(
0
);
}
r
->
status
=
tus_body_to_file
(
ctx
,
r
->
fcore
);
r
->
s
.
s
tatus
=
tus_body_to_file
(
ctx
,
r
->
fcore
);
break
;
}
case
POST
:
{
...
...
@@ -470,26 +470,26 @@ tus_request(VRT_CTX, struct VPFX(tus_server) *tussrv,
cl
=
1
;
if
(
cl
&&
!
ct_ok
)
{
r
->
status
=
415
;
r
->
s
.
s
tatus
=
415
;
return
(
0
);
}
AZ
(
fdisk
->
upload_offset
);
if
(
cl
==
0
)
{
r
->
status
=
201
;
r
->
s
.
s
tatus
=
201
;
break
;
}
r
->
status
=
tus_body_to_file
(
ctx
,
r
->
fcore
);
if
(
r
->
status
!=
204
)
r
->
s
.
s
tatus
=
tus_body_to_file
(
ctx
,
r
->
fcore
);
if
(
r
->
s
.
s
tatus
!=
204
)
break
;
r
->
status
=
201
;
r
->
s
.
s
tatus
=
201
;
break
;
}
default:
INCOMPL
();
}
if
(
r
->
status
==
413
)
{
if
(
r
->
s
.
s
tatus
==
413
)
{
tus_file_del
(
&
r
->
fcore
);
AZ
(
r
->
fcore
);
return
(
0
);
...
...
src/tus_response.c
View file @
658a0eee
...
...
@@ -130,16 +130,16 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
loc
=
fdisk
->
location
;
}
http_ForceHeader
(
r
,
resp
->
status
==
301
?
hdr_loc
:
hdr_cloc
,
resp
->
s
.
s
tatus
==
301
?
hdr_loc
:
hdr_cloc
,
loc
);
}
if
(
resp
->
status
==
301
)
{
VRT_l_resp_status
(
ctx
,
resp
->
status
);
if
(
resp
->
s
.
s
tatus
==
301
)
{
VRT_l_resp_status
(
ctx
,
resp
->
s
.
s
tatus
);
return
;
}
VRT_l_resp_status
(
ctx
,
resp
->
status
);
if
(
resp
->
status
==
405
)
{
VRT_l_resp_status
(
ctx
,
resp
->
s
.
s
tatus
);
if
(
resp
->
s
.
s
tatus
==
405
)
{
http_ForceHeader
(
r
,
hdr_allow
,
allow
);
return
;
}
...
...
@@ -156,7 +156,7 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
}
if
(
resp
->
origin
!=
NULL
&&
*
resp
->
origin
!=
'\0'
)
tus_cors
(
r
,
resp
->
status
,
resp
->
origin
);
tus_cors
(
r
,
resp
->
s
.
s
tatus
,
resp
->
origin
);
http_PrintfHeader
(
r
,
"Tus-Max-Size: %ju"
,
tus_upload_length
(
tussrv
,
fcore
));
...
...
@@ -178,7 +178,7 @@ tus_response(VRT_CTX, const struct VPFX(tus_server) *tussrv,
http_ForceHeader
(
r
,
hdr_meta
,
fdisk
->
metadata
);
VTIM_format
(
fdisk
->
upload_expires
,
t
);
http_ForceHeader
(
r
,
hdr_exp
,
t
);
if
(
resp
->
status
==
201
)
{
if
(
resp
->
s
.
s
tatus
==
201
)
{
AN
(
resp
->
schemeauth
);
http_PrintfHeader
(
r
,
"Location: %s%s"
,
resp
->
schemeauth
,
fdisk
->
url_path
);
...
...
src/tus_response.h
View file @
658a0eee
...
...
@@ -26,10 +26,15 @@
* SUCH DAMAGE.
*/
struct
tus_status
{
unsigned
status
;
const
char
*
reason
;
};
struct
tus_response
{
unsigned
magic
;
#define VMOD_TUS_RESPONSE_MAGIC 0x1054e570
unsigned
statu
s
;
struct
tus_status
s
;
const
char
*
schemeauth
;
// from tussrv
const
char
*
origin
;
// CORS
// if set, mtx is helt
...
...
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