@@ -17,6 +17,10 @@ func ParseLBMethod(method string) (string, error) {
17
17
method , err := validateHashLBMethod (method )
18
18
return method , err
19
19
}
20
+ if strings .HasPrefix (method , "random" ) {
21
+ method , err := validateRandomLBMethod (method )
22
+ return method , err
23
+ }
20
24
21
25
if method == "least_conn" || method == "ip_hash" {
22
26
return method , nil
@@ -45,6 +49,10 @@ func ParseLBMethodForPlus(method string) (string, error) {
45
49
method , err := validateHashLBMethod (method )
46
50
return method , err
47
51
}
52
+ if strings .HasPrefix (method , "random" ) {
53
+ method , err := validateRandomLBMethodForPlus (method )
54
+ return method , err
55
+ }
48
56
49
57
if _ , exists := nginxPlusLBValidInput [method ]; exists {
50
58
return method , nil
@@ -62,6 +70,29 @@ func validateHashLBMethod(method string) (string, error) {
62
70
return "" , fmt .Errorf ("Invalid load balancing method: %q" , method )
63
71
}
64
72
73
+ func validateRandomLBMethod (method string ) (string , error ) {
74
+ keyWords := strings .Split (method , " " )
75
+ if keyWords [0 ] == "random" {
76
+ if len (keyWords ) == 1 || len (keyWords ) == 2 && keyWords [1 ] == "two" ||
77
+ len (keyWords ) == 3 && keyWords [1 ] == "two" && keyWords [2 ] == "least_conn" {
78
+ return method , nil
79
+ }
80
+ }
81
+ return "" , fmt .Errorf ("Invalid load balancing method: %q" , method )
82
+ }
83
+
84
+ func validateRandomLBMethodForPlus (method string ) (string , error ) {
85
+ keyWords := strings .Split (method , " " )
86
+ if keyWords [0 ] == "random" {
87
+ if len (keyWords ) == 1 || len (keyWords ) == 2 && keyWords [1 ] == "two" ||
88
+ len (keyWords ) == 3 && keyWords [1 ] == "two" &&
89
+ (keyWords [2 ] == "least_conn" || keyWords [2 ] == "least_time=header" || keyWords [2 ] == "least_time=last_byte" ) {
90
+ return method , nil
91
+ }
92
+ }
93
+ return "" , fmt .Errorf ("Invalid load balancing method: %q" , method )
94
+ }
95
+
65
96
// http://nginx.org/en/docs/syntax.html
66
97
var validTimeSuffixes = []string {
67
98
"ms" ,
0 commit comments