2015-12-06 12:21:15 -05:00
|
|
|
package blackhole
|
|
|
|
|
2016-06-10 16:26:39 -04:00
|
|
|
import (
|
2016-09-22 06:01:36 -04:00
|
|
|
"github.com/golang/protobuf/ptypes"
|
|
|
|
"github.com/golang/protobuf/ptypes/any"
|
2016-12-09 07:17:34 -05:00
|
|
|
|
|
|
|
"v2ray.com/core/common/buf"
|
2016-12-06 05:03:42 -05:00
|
|
|
"v2ray.com/core/common/serial"
|
2016-09-22 06:01:36 -04:00
|
|
|
)
|
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
|
2016-12-09 07:17:34 -05:00
|
|
|
WriteTo(buf.Writer)
|
2016-09-22 06:01:36 -04:00
|
|
|
}
|
|
|
|
|
2016-12-09 07:17:34 -05:00
|
|
|
func (v *NoneResponse) WriteTo(buf.Writer) {}
|
2016-09-22 06:01:36 -04:00
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *NoneResponse) AsAny() *any.Any {
|
|
|
|
r, _ := ptypes.MarshalAny(v)
|
2016-09-22 06:01:36 -04:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2016-12-09 07:17:34 -05:00
|
|
|
func (v *HTTPResponse) WriteTo(writer buf.Writer) {
|
2016-12-09 06:08:25 -05:00
|
|
|
b := buf.NewLocal(512)
|
|
|
|
b.AppendSupplier(serial.WriteString(http403response))
|
2016-12-06 05:03:42 -05:00
|
|
|
writer.Write(b)
|
2015-12-06 12:21:15 -05:00
|
|
|
}
|
2016-09-22 06:01:36 -04:00
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *HTTPResponse) AsAny() *any.Any {
|
|
|
|
r, _ := ptypes.MarshalAny(v)
|
2016-09-22 06:01:36 -04:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
func (v *Config) GetInternalResponse() (ResponseConfig, error) {
|
|
|
|
if v.GetResponse() == nil {
|
2016-09-22 06:01:36 -04:00
|
|
|
return new(NoneResponse), nil
|
|
|
|
}
|
|
|
|
|
2016-11-27 15:39:09 -05:00
|
|
|
config, err := v.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
|
|
|
}
|