-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(middlewares): stateful writer does not write to injected respon…
…se writer
- Loading branch information
Showing
6 changed files
with
64 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
package stateful | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/miekg/dns" | ||
) | ||
|
||
// Writer wraps the dns writer in order to report | ||
// the dns response written and eventual error. | ||
// Writer is a stateful writer with the Response field | ||
// set when WriteMsg is called. Only the WriteMsg method | ||
// is implemented, calls to the other methods will panic. | ||
type Writer struct { | ||
dns.ResponseWriter | ||
Response *dns.Msg | ||
WriteErr error | ||
} | ||
|
||
// NewWriter creates a new stateful writer. | ||
func NewWriter() *Writer { | ||
return &Writer{} | ||
} | ||
|
||
// WriteMsg sets the Response field of the Writer | ||
// to the given response message and always returns | ||
// a nil error. | ||
func (w *Writer) WriteMsg(response *dns.Msg) error { | ||
w.Response = response | ||
w.WriteErr = w.ResponseWriter.WriteMsg(response) | ||
return w.WriteErr | ||
return nil | ||
} | ||
|
||
// LocalAddr will panic if called. | ||
func (w *Writer) LocalAddr() net.Addr { | ||
panic("not implemented") | ||
} | ||
|
||
// RemoteAddr will panic if called. | ||
func (w *Writer) RemoteAddr() net.Addr { | ||
panic("not implemented") | ||
} | ||
|
||
// Write will panic if called. | ||
func (w *Writer) Write([]byte) (int, error) { | ||
panic("not implemented") | ||
} | ||
|
||
// Close will panic if called. | ||
func (w *Writer) Close() error { | ||
panic("not implemented") | ||
} | ||
|
||
// TsigStatus will panic if called. | ||
func (w *Writer) TsigStatus() error { | ||
panic("not implemented") | ||
} | ||
|
||
// TsigTimersOnly will panic if called. | ||
func (w *Writer) TsigTimersOnly(bool) { | ||
panic("not implemented") | ||
} | ||
|
||
func NewWriter(w dns.ResponseWriter) *Writer { | ||
return &Writer{ | ||
ResponseWriter: w, | ||
} | ||
// Hijack will panic if called. | ||
func (w *Writer) Hijack() { | ||
panic("not implemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters