1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-12 15:14:05 -04:00
v2fly/proxy/blackhole/config.go

53 lines
1012 B
Go
Raw Normal View History

2015-12-06 12:21:15 -05:00
package blackhole
2016-06-10 16:26:39 -04:00
import (
2016-08-20 14:55:45 -04:00
"v2ray.com/core/common/alloc"
v2io "v2ray.com/core/common/io"
2016-06-10 16:26:39 -04:00
2016-09-22 06:01:36 -04:00
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/any"
)
2016-06-10 16:26:39 -04:00
const (
http403response = `HTTP/1.1 403 Forbidden
Connection: close
Cache-Control: max-age=3600, public
Content-Length: 0
2016-06-10 17:01:17 -04:00
2016-06-10 16:26:39 -04:00
`
)
2016-09-22 06:01:36 -04:00
type ResponseConfig interface {
AsAny() *any.Any
WriteTo(v2io.Writer)
}
func (this *NoneResponse) WriteTo(v2io.Writer) {}
func (this *NoneResponse) AsAny() *any.Any {
r, _ := ptypes.MarshalAny(this)
return r
}
2016-06-10 16:26:39 -04:00
func (this *HTTPResponse) WriteTo(writer v2io.Writer) {
writer.Write(alloc.NewLocalBuffer(512).Clear().AppendString(http403response))
2015-12-06 12:21:15 -05:00
}
2016-09-22 06:01:36 -04:00
func (this *HTTPResponse) AsAny() *any.Any {
r, _ := ptypes.MarshalAny(this)
return r
}
2016-10-16 08:22:21 -04:00
func (this *Config) GetInternalResponse() (ResponseConfig, error) {
if this.GetResponse() == nil {
2016-09-22 06:01:36 -04:00
return new(NoneResponse), nil
}
2016-10-16 08:22:21 -04:00
config, err := this.GetResponse().GetInstance()
2016-09-22 06:01:36 -04:00
if err != nil {
return nil, err
}
2016-10-16 08:22:21 -04:00
return config.(ResponseConfig), nil
2016-09-22 06:01:36 -04:00
}