MCPcopy Create free account
hub / github.com/dolanor/rip / AcceptEncoder

Function AcceptEncoder

encoding/encoding.go:80–96  ·  view source on GitHub ↗

AcceptEncoder creates an new encoder for w based on the acceptHeader, the edit mode and the codecs that are available.

(w http.ResponseWriter, acceptHeader string, edit EditMode, codecs Codecs)

Source from the content-addressed store, hash-verified

78// AcceptEncoder creates an new encoder for w based on the acceptHeader, the edit mode and
79// the codecs that are available.
80func AcceptEncoder(w http.ResponseWriter, acceptHeader string, edit EditMode, codecs Codecs) Encoder {
81 // TODO: add some hook to be able to tune this from the codec package
82 if acceptHeader == "text/html" && edit {
83 formCodec, ok := codecs.Codecs["application/x-www-form-urlencoded"]
84 if !ok {
85 return &noEncoder{missingEncoder: "application/x-www-form-urlencoded"}
86 }
87 return formCodec.NewEncoder(w)
88 }
89
90 encoder, ok := codecs.Codecs[acceptHeader]
91 if !ok {
92 return &noEncoder{missingEncoder: acceptHeader}
93 }
94
95 return encoder.NewEncoder(w)
96}
97
98type noEncoder struct {
99 missingEncoder string

Callers 6

updatePathIDFunction · 0.92
handleGetFunction · 0.92
handleListAllFunction · 0.92
handleCreateFunction · 0.92
HandleFunction · 0.92
writeErrorFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected