mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-15 09:10:25 +08:00
缓存写入结束时检查Content-Length是否和实际内容长度一致
This commit is contained in:
@@ -13,6 +13,7 @@ var (
|
|||||||
ErrWritingUnavailable = errors.New("writing unavailable")
|
ErrWritingUnavailable = errors.New("writing unavailable")
|
||||||
ErrWritingQueueFull = errors.New("writing queue full")
|
ErrWritingQueueFull = errors.New("writing queue full")
|
||||||
ErrServerIsBusy = errors.New("server is busy")
|
ErrServerIsBusy = errors.New("server is busy")
|
||||||
|
ErrUnexpectedContentLength = errors.New("unexpected content length")
|
||||||
)
|
)
|
||||||
|
|
||||||
// CapacityError 容量错误
|
// CapacityError 容量错误
|
||||||
|
|||||||
@@ -136,6 +136,13 @@ func (this *FileWriter) Close() error {
|
|||||||
|
|
||||||
var path = this.rawWriter.Name()
|
var path = this.rawWriter.Name()
|
||||||
|
|
||||||
|
// check content length
|
||||||
|
if this.metaBodySize > 0 && this.bodySize != this.metaBodySize {
|
||||||
|
_ = this.rawWriter.Close()
|
||||||
|
_ = os.Remove(path)
|
||||||
|
return ErrUnexpectedContentLength
|
||||||
|
}
|
||||||
|
|
||||||
err := this.WriteHeaderLength(types.Int(this.headerSize))
|
err := this.WriteHeaderLength(types.Int(this.headerSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fsutils.WriteBegin()
|
fsutils.WriteBegin()
|
||||||
|
|||||||
@@ -121,6 +121,14 @@ func (this *MemoryWriter) Close() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check content length
|
||||||
|
if this.expectedBodySize > 0 && this.bodySize != this.expectedBodySize {
|
||||||
|
this.storage.locker.Lock()
|
||||||
|
delete(this.storage.valuesMap, this.hash)
|
||||||
|
this.storage.locker.Unlock()
|
||||||
|
return ErrUnexpectedContentLength
|
||||||
|
}
|
||||||
|
|
||||||
this.storage.locker.Lock()
|
this.storage.locker.Lock()
|
||||||
this.item.IsDone = true
|
this.item.IsDone = true
|
||||||
var err error
|
var err error
|
||||||
@@ -158,7 +166,6 @@ func (this *MemoryWriter) Discard() error {
|
|||||||
|
|
||||||
this.storage.locker.Lock()
|
this.storage.locker.Lock()
|
||||||
delete(this.storage.valuesMap, this.hash)
|
delete(this.storage.valuesMap, this.hash)
|
||||||
|
|
||||||
this.storage.locker.Unlock()
|
this.storage.locker.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user