Skip to content

Commit 361c8a7

Browse files
committed
WriteHeader should be called before Write not after.
The header should be written before the first write. Fixes http: superfluous response.WriteHeader call from code.gitea.io/gitea/modules/context.(*Response).WriteHeader (response.go:67) Signed-off-by: Andrew Thornton <[email protected]>
1 parent 9545c34 commit 361c8a7

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

modules/context/response.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ func (r *Response) Write(bs []byte) (int, error) {
4343
}
4444
r.beforeExecuted = true
4545
}
46+
if r.status == 0 {
47+
r.WriteHeader(200)
48+
}
4649
size, err := r.ResponseWriter.Write(bs)
4750
r.written += size
4851
if err != nil {
4952
return size, err
5053
}
51-
if r.status == 0 {
52-
r.WriteHeader(200)
53-
}
5454
return size, nil
5555
}
5656

routers/repo/attachment.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func DeleteAttachment(ctx *context.Context) {
9292

9393
// GetAttachment serve attachements
9494
func GetAttachment(ctx *context.Context) {
95+
log.Info("GetAttachment(%s)", ctx.Params(":uuid"))
9596
attach, err := models.GetAttachmentByUUID(ctx.Params(":uuid"))
9697
if err != nil {
9798
if models.IsErrAttachmentNotExist(err) {
@@ -156,4 +157,6 @@ func GetAttachment(ctx *context.Context) {
156157
ctx.ServerError("ServeData", err)
157158
return
158159
}
160+
log.Info("GetAttachment(%s) Done", ctx.Params(":uuid"))
161+
159162
}

routers/repo/download.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func ServeData(ctx *context.Context, name string, size int64, reader io.Reader)
3232
if n >= 0 {
3333
buf = buf[:n]
3434
}
35+
log.Info("ServeData(%s)", name)
3536

3637
ctx.Resp.Header().Set("Cache-Control", "public,max-age=86400")
3738

@@ -71,10 +72,14 @@ func ServeData(ctx *context.Context, name string, size int64, reader io.Reader)
7172
}
7273
}
7374

75+
log.Info("ServeData(%s) Header done", name)
76+
7477
_, err = ctx.Resp.Write(buf)
7578
if err != nil {
7679
return err
7780
}
81+
log.Info("ServeData(%s) buffer done", name)
82+
7883
_, err = io.Copy(ctx.Resp, reader)
7984
return err
8085
}

0 commit comments

Comments
 (0)