Skip to content

Commit

Permalink
Merge pull request #97 from m-lab/sandbox-kinkade
Browse files Browse the repository at this point in the history
Sends raw query string from client as part of data to extension
  • Loading branch information
nkinkade authored Nov 11, 2020
2 parents 752bd1a + 2c9d982 commit 712d343
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 4 additions & 0 deletions extension/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type V1 struct {

// LastBoot is the most recent time when the booting machine reached stage1.
LastBoot time.Time `json:"last_boot"`

// The raw query string from the request to ePoxy. Extensions may use this
// to extract arbitrary data sent by the client.
RawQuery string `json:"raw_query"`
}

// Encode marshals a Request to JSON.
Expand Down
11 changes: 9 additions & 2 deletions extension/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ func TestRequest_Encode(t *testing.T) {
Hostname: "mlab4.lga0t.measurement-lab.org",
IPv4Address: "192.168.0.12",
LastBoot: time.Date(2018, 5, 1, 0, 0, 0, 0, time.UTC),
// json.Marshal escapes '&' with '\u0026', which is why the
// "want" value below has that value instead of an actual
// ampersand: https://golang.org/pkg/encoding/json/#Marshal
RawQuery: "p=somevalue&z=othervalue",
},
want: dedent.Dedent(`
{
"v1": {
"hostname": "mlab4.lga0t.measurement-lab.org",
"ipv4_address": "192.168.0.12",
"ipv6_address": "",
"last_boot": "2018-05-01T00:00:00Z"
"last_boot": "2018-05-01T00:00:00Z",
"raw_query": "p=somevalue\u0026z=othervalue"
}
}`),
},
Expand Down Expand Up @@ -75,13 +80,15 @@ func TestRequest_Decode(t *testing.T) {
"hostname": "mlab4.lga0t.measurement-lab.org",
"ipv4_address": "192.168.0.12",
"ipv6_address": "",
"last_boot": "2018-05-01T00:00:00Z"
"last_boot": "2018-05-01T00:00:00Z",
"raw_query": "p=somevalue\u0026z=othervalue"
}
}`))),
expected: &V1{
Hostname: "mlab4.lga0t.measurement-lab.org",
IPv4Address: "192.168.0.12",
LastBoot: time.Date(2018, 5, 1, 0, 0, 0, 0, time.UTC),
RawQuery: "p=somevalue&z=othervalue",
},
},
{
Expand Down
1 change: 1 addition & 0 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ func (env *Env) HandleExtension(rw http.ResponseWriter, req *http.Request) {
Hostname: host.Name,
IPv4Address: host.IPv4Addr,
LastBoot: host.LastSessionCreation,
RawQuery: req.URL.RawQuery,
},
}

Expand Down

0 comments on commit 712d343

Please sign in to comment.