-
Notifications
You must be signed in to change notification settings - Fork 6
/
request_test.go
62 lines (44 loc) · 1.27 KB
/
request_test.go
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2016, Janoš Guljaš <janos@resenje.org>
// All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package web
import (
"net/http/httptest"
"testing"
)
func TestGetRequestIPs(t *testing.T) {
r := httptest.NewRequest("", "/", nil)
r.Header.Set("X-Real-Ip", "222.12.0.3")
r.Header.Set("X-Forwarded-For", "21.44.12.5, 67.55.9.9")
s := "192.0.2.1, 21.44.12.5, 67.55.9.9, 222.12.0.3"
ips := GetRequestIPs(r)
if ips != s {
t.Errorf("expected %s, got %s", s, ips)
}
}
func TestGetRequestEndpoint(t *testing.T) {
r := httptest.NewRequest("", "/", nil)
e := GetRequestEndpoint(r)
s := "http://example.com"
if e != s {
t.Errorf("expected %s, got %s", s, e)
}
}
func TestGetRequestEndpointHTTPS(t *testing.T) {
r := httptest.NewRequest("", "https://example.com:5555/test", nil)
e := GetRequestEndpoint(r)
s := "https://example.com:5555"
if e != s {
t.Errorf("expected %s, got %s", s, e)
}
}
func TestGetRequestEndpointXForwardedProto(t *testing.T) {
r := httptest.NewRequest("", "http://example.com:8000/test", nil)
r.Header.Add("X-Forwarded-Proto", "https")
e := GetRequestEndpoint(r)
s := "https://example.com:8000"
if e != s {
t.Errorf("expected %s, got %s", s, e)
}
}