Skip to content
This repository was archived by the owner on Dec 17, 2024. It is now read-only.

Commit 29e82c6

Browse files
authored
Merge pull request #353 from aandryashin/master
Add firstMatch capabilities.
2 parents 35133a6 + 7283b99 commit 29e82c6

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

pprof.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build pprof
12
// +build pprof
23

34
package main

proxy.go

+18-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/json"
77
"encoding/xml"
88
"fmt"
9-
"github.com/abbot/go-http-auth"
109
"io"
1110
"io/ioutil"
1211
"log"
@@ -20,6 +19,7 @@ import (
2019
"sync/atomic"
2120
"time"
2221

22+
"github.com/abbot/go-http-auth"
2323
. "github.com/aerokube/ggr/config"
2424
"golang.org/x/net/websocket"
2525
)
@@ -61,10 +61,12 @@ var keys = struct {
6161
desiredCapabilities string
6262
w3cCapabilities string
6363
alwaysMatch string
64+
firstMatch string
6465
}{
6566
desiredCapabilities: "desiredCapabilities",
6667
w3cCapabilities: "capabilities",
6768
alwaysMatch: "alwaysMatch",
69+
firstMatch: "firstMatch",
6870
}
6971

7072
var (
@@ -95,13 +97,23 @@ func (c caps) capabilities(fn func(m map[string]interface{}, w3c bool, extension
9597
}
9698
if w3cCapabilities, ok := c[keys.w3cCapabilities]; ok {
9799
if m, ok := w3cCapabilities.(map[string]interface{}); ok {
100+
var match map[string]interface{}
98101
if alwaysMatch, ok := m[keys.alwaysMatch]; ok {
99102
if m, ok := alwaysMatch.(map[string]interface{}); ok {
100-
fn(m, true, false)
101-
for k, v := range m { // Extension capabilities have ":" in key
102-
if ec, ok := v.(map[string]interface{}); ok && strings.Contains(k, ":") {
103-
fn(ec, true, true)
104-
}
103+
match = m
104+
}
105+
} else if firstMatch, ok := m[keys.firstMatch]; ok {
106+
if m, ok := firstMatch.([]interface{}); ok && len(m) > 0 {
107+
if m, ok := m[0].(map[string]interface{}); ok {
108+
match = m
109+
}
110+
}
111+
}
112+
if match != nil {
113+
fn(match, true, false)
114+
for k, v := range m { // Extension capabilities have ":" in key
115+
if ec, ok := v.(map[string]interface{}); ok && strings.Contains(k, ":") {
116+
fn(ec, true, true)
105117
}
106118
}
107119
}

watch.go

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//go:build watch
12
// +build watch
23

34
package main

0 commit comments

Comments
 (0)