mirror of
https://git.sr.ht/~adnano/go-gemini
synced 2024-11-10 00:32:11 +01:00
Reintroduce Response.Write method
This commit is contained in:
parent
b4a4ece459
commit
469cf1dd86
19
response.go
19
response.go
@ -3,6 +3,7 @@ package gemini
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -111,6 +112,24 @@ func (r *Response) TLS() *tls.ConnectionState {
|
|||||||
return nil
|
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 ResponseWriter interface is used by a Gemini handler to construct
|
||||||
// a Gemini response.
|
// a Gemini response.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user