aboutsummaryrefslogtreecommitdiff
path: root/request.go
diff options
context:
space:
mode:
authorAdnan Maolood <[email protected]>2021-02-28 22:16:38 -0500
committerAdnan Maolood <[email protected]>2021-02-28 22:16:38 -0500
commit768ec6c17b662b3a62173ce0a3527f221404c249 (patch)
tree8dbad6100519d6f25af206cdedf8f1ac9990618f /request.go
parentAdd message argument to TimeoutHandler (diff)
downloadgo-gemini-768ec6c17b662b3a62173ce0a3527f221404c249.tar.xz
go-gemini-768ec6c17b662b3a62173ce0a3527f221404c249.zip
Make Request implement io.WriterTo
Diffstat (limited to 'request.go')
-rw-r--r--request.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/request.go b/request.go
index b022a31..e539675 100644
--- a/request.go
+++ b/request.go
@@ -77,21 +77,26 @@ func ReadRequest(r io.Reader) (*Request, error) {
return &Request{URL: u}, nil
}
-// Write writes a Gemini request in wire format.
+// WriteTo writes r to w in the Gemini request format.
// This method consults the request URL only.
-func (r *Request) Write(w io.Writer) error {
+func (r *Request) WriteTo(w io.Writer) (int, error) {
bw := bufio.NewWriterSize(w, 1026)
url := r.URL.String()
if len(url) > 1024 {
- return ErrInvalidRequest
+ return 0, ErrInvalidRequest
}
- if _, err := bw.WriteString(url); err != nil {
- return err
+ var wrote int
+ n, err := bw.WriteString(url)
+ wrote += n
+ if err != nil {
+ return wrote, err
}
- if _, err := bw.Write(crlf); err != nil {
- return err
+ n, err = bw.Write(crlf)
+ wrote += n
+ if err != nil {
+ return wrote, err
}
- return bw.Flush()
+ return wrote, bw.Flush()
}
// Conn returns the network connection on which the request was received.