2015-12-06 18:21:15 +01:00
|
|
|
package blackhole
|
|
|
|
|
2016-06-10 22:26:39 +02:00
|
|
|
import (
|
2016-12-09 13:17:34 +01:00
|
|
|
"v2ray.com/core/common/buf"
|
2016-12-06 11:03:42 +01:00
|
|
|
"v2ray.com/core/common/serial"
|
2016-09-22 12:01:36 +02:00
|
|
|
)
|
2016-06-10 22:26:39 +02:00
|
|
|
|
|
|
|
const (
|
|
|
|
http403response = `HTTP/1.1 403 Forbidden
|
|
|
|
Connection: close
|
|
|
|
Cache-Control: max-age=3600, public
|
|
|
|
Content-Length: 0
|
2016-06-10 23:01:17 +02:00
|
|
|
|
|
|
|
|
2016-06-10 22:26:39 +02:00
|
|
|
`
|
|
|
|
)
|
|
|
|
|
2016-12-22 13:33:28 +01:00
|
|
|
// ResponseConfig is the configuration for blackhole responses.
|
2016-09-22 12:01:36 +02:00
|
|
|
type ResponseConfig interface {
|
2016-12-22 13:33:28 +01:00
|
|
|
// WriteTo writes predefined response to the give buffer.
|
2016-12-09 13:17:34 +01:00
|
|
|
WriteTo(buf.Writer)
|
2016-09-22 12:01:36 +02:00
|
|
|
}
|
|
|
|
|
2016-12-22 13:33:28 +01:00
|
|
|
// WriteTo implements ResponseConfig.WriteTo().
|
2016-12-09 13:17:34 +01:00
|
|
|
func (v *NoneResponse) WriteTo(buf.Writer) {}
|
2016-09-22 12:01:36 +02:00
|
|
|
|
2016-12-22 13:33:28 +01:00
|
|
|
// WriteTo implements ResponseConfig.WriteTo().
|
2016-12-09 13:17:34 +01:00
|
|
|
func (v *HTTPResponse) WriteTo(writer buf.Writer) {
|
2016-12-09 12:08:25 +01:00
|
|
|
b := buf.NewLocal(512)
|
|
|
|
b.AppendSupplier(serial.WriteString(http403response))
|
2017-04-16 13:17:35 +02:00
|
|
|
writer.Write(buf.NewMultiBufferValue(b))
|
2015-12-06 18:21:15 +01:00
|
|
|
}
|
2016-09-22 12:01:36 +02:00
|
|
|
|
2016-12-22 13:33:28 +01:00
|
|
|
// GetInternalResponse converts response settings from proto to internal data structure.
|
2016-11-27 21:39:09 +01:00
|
|
|
func (v *Config) GetInternalResponse() (ResponseConfig, error) {
|
|
|
|
if v.GetResponse() == nil {
|
2016-09-22 12:01:36 +02:00
|
|
|
return new(NoneResponse), nil
|
|
|
|
}
|
|
|
|
|
2016-11-27 21:39:09 +01:00
|
|
|
config, err := v.GetResponse().GetInstance()
|
2016-09-22 12:01:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-10-16 14:22:21 +02:00
|
|
|
return config.(ResponseConfig), nil
|
2016-09-22 12:01:36 +02:00
|
|
|
}
|