summaryrefslogtreecommitdiffhomepage
path: root/util/httpio/options.go
diff options
context:
space:
mode:
authorJoe Tsai <joetsai@digital-static.net>2024-01-11 15:23:52 -0800
committerJoe Tsai <joetsai@digital-static.net>2024-01-11 15:30:43 -0800
commit2e20bd2ffe2098877ad44d5eed93a1820956d1e9 (patch)
tree7472ed2a5ca5442b870a03ea41d8fd4b835a4154 /util/httpio/options.go
parentb89c11336514d541ad25de564dcf0561c0b24e58 (diff)
downloadtailscale-dsnet/httpio.tar.xz
tailscale-dsnet/httpio.zip
util/httpio: prototype design for handling I/O in HTTPdsnet/httpio
Signed-off-by: Joe Tsai <joetsai@digital-static.net>
Diffstat (limited to 'util/httpio/options.go')
-rw-r--r--util/httpio/options.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/util/httpio/options.go b/util/httpio/options.go
new file mode 100644
index 000000000..cc6598765
--- /dev/null
+++ b/util/httpio/options.go
@@ -0,0 +1,44 @@
+// Copyright (c) Tailscale Inc & AUTHORS
+// SPDX-License-Identifier: BSD-3-Clause
+
+package httpio
+
+import (
+ "io"
+ "net/http"
+)
+
+// Option is an option to alter the behavior of [httpio] functionality.
+type Option interface{ option() }
+
+// WithClient specifies the [http.Client] to use in client-initiated requests.
+// It only affects [Do], [Get], [Post], [Put], and [Delete].
+// It has no effect on [Handler].
+func WithClient(c *http.Client) Option {
+ panic("not implemented")
+}
+
+// WithMarshaler specifies an marshaler to use for a particular "Content-Type".
+//
+// For client-side requests (e.g., [Do], [Get], [Post], [Put], and [Delete]),
+// the first specified encoder is used to specify the "Content-Type" and
+// to marshal the HTTP request body.
+//
+// For server-side responses (e.g., [Handler]), the first match between
+// the client-provided "Accept" header is used to select the encoder to use.
+// If no match is found, the first specified encoder is used regardless.
+//
+// If no encoder is specified, by default the "application/json" content type
+// is used with the [encoding/json] as the marshal implementation.
+func WithMarshaler(contentType string, marshal func(io.Writer, any) error) Option {
+ panic("not implemented")
+}
+
+// WithUnmarshaler specifies an unmarshaler to use for a particular "Content-Type".
+//
+// For both client-side responses and server-side requests,
+// the provided "Content-Type" header is used to select which decoder to use.
+// If no match is found, the first specified encoder is used regardless.
+func WithUnmarshaler(contentType string, unmarshal func(io.Reader, any) error) Option {
+ panic("not implemented")
+}