mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-03 15:00:26 +08:00
缓存写入结束时检查Content-Length是否和实际内容长度一致
This commit is contained in:
@@ -121,6 +121,14 @@ func (this *MemoryWriter) Close() error {
|
||||
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.item.IsDone = true
|
||||
var err error
|
||||
@@ -129,7 +137,7 @@ func (this *MemoryWriter) Close() error {
|
||||
this.storage.valuesMap[this.hash] = this.item
|
||||
|
||||
select {
|
||||
case this.storage.dirtyChan <- types.String(this.bodySize) + "@" +this.key :
|
||||
case this.storage.dirtyChan <- types.String(this.bodySize) + "@" + this.key:
|
||||
atomic.AddInt64(&this.storage.totalDirtySize, this.bodySize)
|
||||
default:
|
||||
// remove from values map
|
||||
@@ -158,7 +166,6 @@ func (this *MemoryWriter) Discard() error {
|
||||
|
||||
this.storage.locker.Lock()
|
||||
delete(this.storage.valuesMap, this.hash)
|
||||
|
||||
this.storage.locker.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user