File: encoder_selector.go

package info (click to toggle)
golang-github-gorilla-rpc 0.0~git20160927.22c016f-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 264 kB
  • sloc: makefile: 5
file content (43 lines) | stat: -rw-r--r-- 1,043 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2009 The Go Authors. All rights reserved.
// Copyright 2012 The Gorilla Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package rpc

import (
	"io"
	"net/http"
)

// Encoder interface contains the encoder for http response.
// Eg. gzip, flate compressions.
type Encoder interface {
	Encode(w http.ResponseWriter) io.Writer
}

type encoder struct {
}

func (_ *encoder) Encode(w http.ResponseWriter) io.Writer {
	return w
}

var DefaultEncoder = &encoder{}

// EncoderSelector interface provides a way to select encoder using the http
// request. Typically people can use this to check HEADER of the request and
// figure out client capabilities.
// Eg. "Accept-Encoding" tells about supported compressions.
type EncoderSelector interface {
	Select(r *http.Request) Encoder
}

type encoderSelector struct {
}

func (_ *encoderSelector) Select(_ *http.Request) Encoder {
	return DefaultEncoder
}

var DefaultEncoderSelector = &encoderSelector{}