Skip to content

Commit

Permalink
Merge pull request #353 from aandryashin/master
Browse files Browse the repository at this point in the history
Add firstMatch capabilities.
  • Loading branch information
vania-pooh authored Feb 1, 2022
2 parents 35133a6 + 7283b99 commit 29e82c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions pprof.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build pprof
// +build pprof

package main
Expand Down
24 changes: 18 additions & 6 deletions proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"encoding/json"
"encoding/xml"
"fmt"
"github.com/abbot/go-http-auth"
"io"
"io/ioutil"
"log"
Expand All @@ -20,6 +19,7 @@ import (
"sync/atomic"
"time"

"github.com/abbot/go-http-auth"
. "github.com/aerokube/ggr/config"
"golang.org/x/net/websocket"
)
Expand Down Expand Up @@ -61,10 +61,12 @@ var keys = struct {
desiredCapabilities string
w3cCapabilities string
alwaysMatch string
firstMatch string
}{
desiredCapabilities: "desiredCapabilities",
w3cCapabilities: "capabilities",
alwaysMatch: "alwaysMatch",
firstMatch: "firstMatch",
}

var (
Expand Down Expand Up @@ -95,13 +97,23 @@ func (c caps) capabilities(fn func(m map[string]interface{}, w3c bool, extension
}
if w3cCapabilities, ok := c[keys.w3cCapabilities]; ok {
if m, ok := w3cCapabilities.(map[string]interface{}); ok {
var match map[string]interface{}
if alwaysMatch, ok := m[keys.alwaysMatch]; ok {
if m, ok := alwaysMatch.(map[string]interface{}); ok {
fn(m, true, false)
for k, v := range m { // Extension capabilities have ":" in key
if ec, ok := v.(map[string]interface{}); ok && strings.Contains(k, ":") {
fn(ec, true, true)
}
match = m
}
} else if firstMatch, ok := m[keys.firstMatch]; ok {
if m, ok := firstMatch.([]interface{}); ok && len(m) > 0 {
if m, ok := m[0].(map[string]interface{}); ok {
match = m
}
}
}
if match != nil {
fn(match, true, false)
for k, v := range m { // Extension capabilities have ":" in key
if ec, ok := v.(map[string]interface{}); ok && strings.Contains(k, ":") {
fn(ec, true, true)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions watch.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build watch
// +build watch

package main
Expand Down

0 comments on commit 29e82c6

Please sign in to comment.