diff --git a/auth.go b/auth.go index 0a51295b..248f97d8 100644 --- a/auth.go +++ b/auth.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/auth_test.go b/auth_test.go index cc70bc08..d60c587b 100644 --- a/auth_test.go +++ b/auth_test.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/binding/binding.go b/binding/binding.go index 3670fd97..81ac3fa5 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package binding import ( diff --git a/context.go b/context.go index 8fed41de..294d1cce 100644 --- a/context.go +++ b/context.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/context_test.go b/context_test.go index 3b3302e8..6df824cb 100644 --- a/context_test.go +++ b/context_test.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/deprecated.go b/deprecated.go index 91d08239..eb248dde 100644 --- a/deprecated.go +++ b/deprecated.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/gin.go b/gin.go index 0f4753e2..45b3807a 100644 --- a/gin.go +++ b/gin.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/gin_test.go b/gin_test.go index 7425cc21..33979438 100644 --- a/gin_test.go +++ b/gin_test.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/logger.go b/logger.go index 8cbc24be..56602c04 100644 --- a/logger.go +++ b/logger.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/mode.go b/mode.go index 85f133b9..166c09c0 100644 --- a/mode.go +++ b/mode.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/recovery.go b/recovery.go index 47165227..a8d537e4 100644 --- a/recovery.go +++ b/recovery.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/recovery_test.go b/recovery_test.go index 9d3d0880..756c7c2a 100644 --- a/recovery_test.go +++ b/recovery_test.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( diff --git a/render/render.go b/render/render.go index bc982a30..699b4e96 100644 --- a/render/render.go +++ b/render/render.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package render import ( diff --git a/response_writer.go b/response_writer.go index 2da8e336..3ce84142 100644 --- a/response_writer.go +++ b/response_writer.go @@ -1,13 +1,24 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import ( + "bufio" + "errors" "log" + "net" "net/http" ) type ( ResponseWriter interface { http.ResponseWriter + http.Hijacker + http.Flusher + http.CloseNotifier + Status() int Written() bool WriteHeaderNow() @@ -27,7 +38,7 @@ func (w *responseWriter) reset(writer http.ResponseWriter) { } func (w *responseWriter) WriteHeader(code int) { - if code != 0 { + if code > 0 { w.status = code if w.written { log.Println("[GIN] WARNING. Headers were already written!") @@ -54,3 +65,25 @@ func (w *responseWriter) Status() int { func (w *responseWriter) Written() bool { return w.written } + +// Implements the http.Hijacker interface +func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + hijacker, ok := w.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface") + } + return hijacker.Hijack() +} + +// Implements the http.CloseNotify interface +func (w *responseWriter) CloseNotify() <-chan bool { + return w.ResponseWriter.(http.CloseNotifier).CloseNotify() +} + +// Implements the http.Flush interface +func (w *responseWriter) Flush() { + flusher, ok := w.ResponseWriter.(http.Flusher) + if ok { + flusher.Flush() + } +} diff --git a/utils.go b/utils.go index 6417efd9..f58097a4 100644 --- a/utils.go +++ b/utils.go @@ -1,3 +1,7 @@ +// Copyright 2014 Manu Martinez-Almeida. All rights reserved. +// Use of this source code is governed by a MIT style +// license that can be found in the LICENSE file. + package gin import (