Browse Source

api: always encode timestamps wth RFC3339 (#1093)

this fixes "lastRequest" in /v1/hlsmuxers/list that was encoded in a
wrong format
pull/1128/head
aler9 4 years ago
parent
commit
960cfb9f99
  1. 5
      internal/core/api_test.go
  2. 8
      internal/core/hls_muxer.go
  3. 2
      internal/core/hls_server.go

5
internal/core/api_test.go

@ -469,6 +469,7 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -469,6 +469,7 @@ func TestAPIProtocolSpecificList(t *testing.T) {
case "hls":
var out struct {
Items map[string]struct {
Created string `json:"created"`
LastRequest string `json:"lastRequest"`
} `json:"items"`
}
@ -480,7 +481,9 @@ func TestAPIProtocolSpecificList(t *testing.T) { @@ -480,7 +481,9 @@ func TestAPIProtocolSpecificList(t *testing.T) {
firstID = k
}
require.NotEqual(t, "", out.Items[firstID].LastRequest)
s := fmt.Sprintf("^%d-", time.Now().Year())
require.Regexp(t, s, out.Items[firstID].Created)
require.Regexp(t, s, out.Items[firstID].LastRequest)
}
})
}

8
internal/core/hls_muxer.go

@ -177,7 +177,7 @@ func newHLSMuxer( @@ -177,7 +177,7 @@ func newHLSMuxer(
ctxCancel: ctxCancel,
created: time.Now(),
lastRequestTime: func() *int64 {
v := time.Now().Unix()
v := time.Now().UnixNano()
return &v
}(),
chRequest: make(chan *hlsMuxerRequest),
@ -244,7 +244,7 @@ func (m *hlsMuxer) run() { @@ -244,7 +244,7 @@ func (m *hlsMuxer) run() {
case req := <-m.chAPIHLSMuxersList:
req.data.Items[m.name] = hlsServerAPIMuxersListItem{
Created: m.created,
LastRequest: time.Unix(atomic.LoadInt64(m.lastRequestTime), 0).String(),
LastRequest: time.Unix(0, atomic.LoadInt64(m.lastRequestTime)),
}
close(req.res)
@ -408,7 +408,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{}) @@ -408,7 +408,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
for {
select {
case <-closeCheckTicker.C:
t := time.Unix(atomic.LoadInt64(m.lastRequestTime), 0)
t := time.Unix(0, atomic.LoadInt64(m.lastRequestTime))
if m.remoteAddr != "" && time.Since(t) >= closeAfterInactivity {
m.ringBuffer.Close()
<-writerDone
@ -427,7 +427,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{}) @@ -427,7 +427,7 @@ func (m *hlsMuxer) runInner(innerCtx context.Context, innerReady chan struct{})
}
func (m *hlsMuxer) handleRequest(req *hlsMuxerRequest) func() *hls.MuxerFileResponse {
atomic.StoreInt64(m.lastRequestTime, time.Now().Unix())
atomic.StoreInt64(m.lastRequestTime, time.Now().UnixNano())
err := m.authenticate(req.ctx)
if err != nil {

2
internal/core/hls_server.go

@ -29,7 +29,7 @@ func (nilWriter) Write(p []byte) (int, error) { @@ -29,7 +29,7 @@ func (nilWriter) Write(p []byte) (int, error) {
type hlsServerAPIMuxersListItem struct {
Created time.Time `json:"created"`
LastRequest string `json:"lastRequest"`
LastRequest time.Time `json:"lastRequest"`
}
type hlsServerAPIMuxersListData struct {

Loading…
Cancel
Save