-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubenricher-useragent.go
49 lines (40 loc) · 1.14 KB
/
subenricher-useragent.go
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"io"
"net/http"
ua "github.com/mileusna/useragent"
"github.com/telkomindonesia/httpmsg-enricher/ecs"
ecsx "github.com/telkomindonesia/httpmsg-enricher/ecs/custom"
)
var _ subEnricher = &uaEnricher{}
type uaEnricher struct{}
func (uaEnricher) requestBodyWriter() io.WriteCloser { return nopwc }
func (uaEnricher) processRequest(req *http.Request) (err error) { return }
func (uaEnricher) responseBodyWriter() io.WriteCloser { return nopwc }
func (uaEnricher) processResponse(res *http.Response) (err error) { return }
func (uaEnricher) Close() (err error) { return }
func (uaEnricher) enrich(doc *ecsx.Document, msg *httpRecordedMessage) (err error) {
req, err := msg.Request()
if err != nil {
return fmt.Errorf("error getting request: %w", err)
}
v := req.Header.Get("user-agent")
if v == "" {
return
}
uap := ua.Parse(v)
doc.UserAgent = &ecs.UserAgent{
Original: v,
Name: uap.Name,
Version: uap.Version,
Device: &ecs.UserAgentDevice{
Name: uap.Device,
},
OS: &ecs.OS{
Name: uap.OS,
Version: uap.OSVersion,
},
}
return
}