mirror of
https://github.com/haiwen/seafile-server.git
synced 2025-09-21 11:08:49 +00:00
Parse Content-Range to get file size (#775)
Co-authored-by: Heran Yang <heran.yang@seafile.com>
This commit is contained in:
@@ -1681,6 +1681,9 @@ func parseUploadHeaders(r *http.Request) (*recvData, *appError) {
|
||||
if contentLen < 0 {
|
||||
contentLen = 0
|
||||
}
|
||||
if fsm.fsize > 0 {
|
||||
contentLen = fsm.fsize
|
||||
}
|
||||
}
|
||||
if err := checkQuotaByContentLength(r, repoID, contentLen); err != nil {
|
||||
return nil, err
|
||||
|
@@ -2572,8 +2572,20 @@ upload_headers_cb (evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)
|
||||
goto err;
|
||||
}
|
||||
|
||||
gint64 rstart = -1;
|
||||
gint64 rend = -1;
|
||||
gint64 fsize = -1;
|
||||
if (!parse_range_val (hdr, &rstart, &rend, &fsize)) {
|
||||
seaf_warning ("Invalid Seafile-Content-Range value.\n");
|
||||
err_msg = "Invalid Seafile-Content-Range";
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (method == htp_method_POST || method == htp_method_PUT) {
|
||||
gint64 content_len = get_content_length (req);
|
||||
if (fsize > 0) {
|
||||
content_len = fsize;
|
||||
}
|
||||
// Check whether the file to be uploaded would exceed the quota before receiving the body, in order to avoid unnecessarily receiving the body.
|
||||
// After receiving the body, the quota is checked again to handle cases where the Content-Length in the request header is missing, which could make the initial quota check inaccurate.
|
||||
if (seaf_quota_manager_check_quota_with_delta (seaf->quota_mgr,
|
||||
@@ -2612,15 +2624,6 @@ upload_headers_cb (evhtp_request_t *req, evhtp_headers_t *hdr, void *arg)
|
||||
pthread_mutex_unlock (&pg_lock);
|
||||
}
|
||||
|
||||
gint64 rstart = -1;
|
||||
gint64 rend = -1;
|
||||
gint64 fsize = -1;
|
||||
if (!parse_range_val (hdr, &rstart, &rend, &fsize)) {
|
||||
seaf_warning ("Invalid Seafile-Content-Range value.\n");
|
||||
err_msg = "Invalid Seafile-Content-Range";
|
||||
goto err;
|
||||
}
|
||||
|
||||
fsm = g_new0 (RecvFSM, 1);
|
||||
fsm->boundary = boundary;
|
||||
fsm->repo_id = repo_id;
|
||||
|
Reference in New Issue
Block a user