From b3f322c5fc19d68e297ae0a175770b232eae0bc1 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Sun, 24 Aug 2014 04:35:11 +0200 Subject: [PATCH 1/5] Fixes bug when status code is negative --- response_writer.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/response_writer.go b/response_writer.go index 2da8e336..91afe89b 100644 --- a/response_writer.go +++ b/response_writer.go @@ -27,7 +27,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!") From 4a24c47a69f56e8275ef330beca3c2925d270948 Mon Sep 17 00:00:00 2001 From: olebedev Date: Mon, 25 Aug 2014 15:58:43 +0400 Subject: [PATCH 2/5] Hijacker interface added --- response_writer.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/response_writer.go b/response_writer.go index 91afe89b..4a65daf4 100644 --- a/response_writer.go +++ b/response_writer.go @@ -1,7 +1,10 @@ package gin import ( + "bufio" + "errors" "log" + "net" "net/http" ) @@ -11,6 +14,7 @@ type ( Status() int Written() bool WriteHeaderNow() + Hijack() (net.Conn, *bufio.ReadWriter, error) } responseWriter struct { @@ -54,3 +58,12 @@ func (w *responseWriter) Status() int { func (w *responseWriter) Written() bool { return w.written } + +// allow connection hijacking +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() +} From 7a87c5cbd4946d9b3e5c57e96f4a5179f812fb9e Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Tue, 26 Aug 2014 17:50:07 +0200 Subject: [PATCH 3/5] Referencing the http.Hijacker interface --- response_writer.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/response_writer.go b/response_writer.go index 4a65daf4..0def5d07 100644 --- a/response_writer.go +++ b/response_writer.go @@ -11,10 +11,10 @@ import ( type ( ResponseWriter interface { http.ResponseWriter + http.Hijacker Status() int Written() bool WriteHeaderNow() - Hijack() (net.Conn, *bufio.ReadWriter, error) } responseWriter struct { @@ -59,7 +59,7 @@ func (w *responseWriter) Written() bool { return w.written } -// allow connection hijacking +// Implements the http.Hijacker interface func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { hijacker, ok := w.ResponseWriter.(http.Hijacker) if !ok { From 8f1bbc6b6a3faf0776cc8313a6432565bd6eb559 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Tue, 26 Aug 2014 17:52:58 +0200 Subject: [PATCH 4/5] gin.responseWriter implements http.Flusher and http.CloseNotifier --- response_writer.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/response_writer.go b/response_writer.go index 0def5d07..2a21e578 100644 --- a/response_writer.go +++ b/response_writer.go @@ -12,6 +12,9 @@ type ( ResponseWriter interface { http.ResponseWriter http.Hijacker + http.Flusher + http.CloseNotifier + Status() int Written() bool WriteHeaderNow() @@ -67,3 +70,16 @@ func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { } 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() + } +} From 8e5397bfa0277fe89bb27848d264402af56828b6 Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Fri, 29 Aug 2014 19:49:50 +0200 Subject: [PATCH 5/5] Adds in-code license --- auth.go | 4 ++++ auth_test.go | 4 ++++ binding/binding.go | 4 ++++ context.go | 4 ++++ context_test.go | 4 ++++ deprecated.go | 4 ++++ gin.go | 4 ++++ gin_test.go | 4 ++++ logger.go | 4 ++++ mode.go | 4 ++++ recovery.go | 4 ++++ recovery_test.go | 4 ++++ render/render.go | 4 ++++ response_writer.go | 4 ++++ utils.go | 4 ++++ 15 files changed, 60 insertions(+) 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 bb6cbde2..61a57b14 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 91afe89b..aaa2010c 100644 --- a/response_writer.go +++ b/response_writer.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/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 (