2016-06-10 17:01:17 -04:00
|
|
|
package blackhole_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/buf"
|
|
|
|
. "github.com/v2fly/v2ray-core/v5/proxy/blackhole"
|
2016-06-10 17:01:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestHTTPResponse(t *testing.T) {
|
2016-12-09 06:08:25 -05:00
|
|
|
buffer := buf.New()
|
2016-06-10 17:01:17 -04:00
|
|
|
|
|
|
|
httpResponse := new(HTTPResponse)
|
2016-12-09 07:17:34 -05:00
|
|
|
httpResponse.WriteTo(buf.NewWriter(buffer))
|
2016-06-10 17:01:17 -04:00
|
|
|
|
|
|
|
reader := bufio.NewReader(buffer)
|
|
|
|
response, err := http.ReadResponse(reader, nil)
|
2019-02-01 08:38:14 -05:00
|
|
|
common.Must(err)
|
2020-11-21 16:05:01 -05:00
|
|
|
defer response.Body.Close()
|
2020-10-11 07:22:46 -04:00
|
|
|
|
2019-02-01 08:38:14 -05:00
|
|
|
if response.StatusCode != 403 {
|
|
|
|
t.Error("expected status code 403, but got ", response.StatusCode)
|
|
|
|
}
|
2016-06-10 17:01:17 -04:00
|
|
|
}
|