-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsts_rickroll.go
More file actions
35 lines (26 loc) · 763 Bytes
/
sts_rickroll.go
File metadata and controls
35 lines (26 loc) · 763 Bytes
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
package sts_rickroll
import (
"bytes"
"fmt"
"github.com/pkg/errors"
"io/ioutil"
"net/http"
"regexp"
)
type StsRickroll struct{}
var stsRickrollRegexp = regexp.MustCompile(`<UserId>([^<]+)</UserId>`)
func (s *StsRickroll) OnRequest(req *http.Request) {}
func (s *StsRickroll) OnResponse(resp *http.Response) error {
if resp.Request.Host != "sts.amazonaws.com" {
return nil
}
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return errors.WithStack(err)
}
defer resp.Body.Close()
body = stsRickrollRegexp.ReplaceAll(body, []byte(`<UserId>Never gonna give you up, never gonna let you down.</UserId>`))
resp.Header.Set("Content-Length", fmt.Sprintf("%d", len(body)))
resp.Body = ioutil.NopCloser(bytes.NewReader(body))
return nil
}