aboutsummaryrefslogtreecommitdiff
path: root/response.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-28 20:50:18 -0500
committerAdnan Maolood <[email protected]>2021-02-28 20:50:18 -0500
commit845f8e9bd1972807d02f0082893a197d3f241177 (patch)
tree0d84d8bb88f1fa1ff65bdd3a99a131a4cec7df3e /response.go
parentcertificate.Store: Check parent scopes in Lookup (diff)
downloadgo-gemini-845f8e9bd1972807d02f0082893a197d3f241177.tar.xz
go-gemini-845f8e9bd1972807d02f0082893a197d3f241177.zip
Reintroduce Response.Write method
Diffstat (limited to 'response.go')
-rw-r--r--response.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/response.go b/response.go
index 5c7d7b3..3735c14 100644
--- a/response.go
+++ b/response.go
@@ -3,6 +3,7 @@ package gemini
import (
"bufio"
"crypto/tls"
+ "fmt"
"io"
"net"
"strconv"
@@ -111,6 +112,24 @@ func (r *Response) TLS() *tls.ConnectionState {
return nil
}
+// Write writes r to w in the Gemini response format, including the
+// header and body.
+//
+// This method consults the Status, Meta, and Body fields of the response.
+// The Response Body is closed after it is sent.
+func (r *Response) Write(w io.Writer) error {
+ if _, err := fmt.Fprintf(w, "%02d %s\r\n", r.Status, r.Meta); err != nil {
+ return err
+ }
+ if r.Body != nil {
+ defer r.Body.Close()
+ if _, err := io.Copy(w, r.Body); err != nil {
+ return err
+ }
+ }
+ return nil
+}
+
// A ResponseWriter interface is used by a Gemini handler to construct
// a Gemini response.
//