fix: wrong cache header (#423)
Signed-off-by: santong <weipeng.swp@alibaba-inc.com>
This commit is contained in:
parent
a8f2b818d1
commit
158ea2ec4a
|
|
@ -19,6 +19,7 @@ package task
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"d7y.io/dragonfly/v2/cdnsystem/config"
|
||||
|
|
@ -46,14 +47,17 @@ func (tm *Manager) addOrUpdateTask(ctx context.Context, request *types.TaskRegis
|
|||
synclock.Lock(taskID, false)
|
||||
defer synclock.UnLock(taskID, false)
|
||||
if key, err := tm.taskURLUnReachableStore.Get(taskID); err == nil {
|
||||
if unReachableStartTime, ok := key.(time.Time); ok &&
|
||||
time.Since(unReachableStartTime) < tm.cfg.FailAccessInterval {
|
||||
return nil, errors.Wrapf(cdnerrors.ErrURLNotReachable{URL: request.URL}, "task hit unReachable cache and interval less than %d, "+
|
||||
"url: %s", tm.cfg.FailAccessInterval, request.URL)
|
||||
if unReachableStartTime, ok := key.(time.Time); ok && time.Since(unReachableStartTime) < tm.cfg.FailAccessInterval {
|
||||
existTask, err := tm.taskStore.Get(taskID)
|
||||
if err != nil || reflect.DeepEqual(request.Header, existTask.(*types.SeedTask).Header) {
|
||||
return nil, errors.Wrapf(cdnerrors.ErrURLNotReachable{URL: request.URL}, "task hit unReachable cache and interval less than %d, "+
|
||||
"url: %s", tm.cfg.FailAccessInterval, request.URL)
|
||||
}
|
||||
}
|
||||
tm.taskURLUnReachableStore.Delete(taskID)
|
||||
logger.Debugf("delete taskID:%s from url unReachable store", taskID)
|
||||
}
|
||||
|
||||
var task *types.SeedTask
|
||||
newTask := &types.SeedTask{
|
||||
TaskID: taskID,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"d7y.io/dragonfly/v2/cdnsystem/daemon/task"
|
||||
"d7y.io/dragonfly/v2/pkg/source"
|
||||
"d7y.io/dragonfly/v2/pkg/structure/maputils"
|
||||
"d7y.io/dragonfly/v2/pkg/util/stringutils"
|
||||
|
|
@ -86,7 +87,7 @@ func (client *httpSourceClient) GetContentLength(ctx context.Context, url string
|
|||
// todo Here if other status codes should be added to ErrURLNotReachable, if not, it will be downloaded frequently for 404 or 403
|
||||
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusPartialContent {
|
||||
// todo Whether this situation should be distinguished from the err situation, similar to proposing another error type to indicate that this error can interact with the URL, but the status code does not meet expectations
|
||||
return -1, fmt.Errorf("get http resource length failed, unexpected code: %d", resp.StatusCode)
|
||||
return task.IllegalSourceFileLen, fmt.Errorf("get http resource length failed, unexpected code: %d", resp.StatusCode)
|
||||
}
|
||||
return resp.ContentLength, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ type ResourceClient interface {
|
|||
|
||||
// GetContentLength get length of resource content
|
||||
// return -l if request fail
|
||||
// return -1 if response status is not StatusOK and StatusPartialContent
|
||||
// return task.IllegalSourceFileLen if response status is not StatusOK and StatusPartialContent
|
||||
GetContentLength(ctx context.Context, url string, header RequestHeader) (int64, error)
|
||||
|
||||
// IsSupportRange checks if resource supports breakpoint continuation
|
||||
|
|
|
|||
Loading…
Reference in New Issue