forked from rsfreitas/go-rtsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdescribe.go
61 lines (48 loc) · 1.27 KB
/
describe.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
50
51
52
53
54
55
56
57
58
59
60
61
//
// Description:
// Author: Rodrigo Freitas
// Created at: Sun Apr 28 09:59:01 -03 2019
//
package rtsp
import (
"fmt"
"net/http"
"github.com/rsfreitas/go-rtsp/internal/packet"
"github.com/rsfreitas/go-rtsp/internal/sdp"
)
type describeMethod struct {
Session *sdp.Session
}
func (d *describeMethod) Verify(p *packet.Packet, handler interface{}) error {
return nil
}
func (d *describeMethod) isAcceptable(p *packet.Packet) bool {
accept, ok := p.Request.Headers["Accept"]
if !ok {
// Assumes the default, which is 'application/sdp' and continue
return true
}
if accept[0] == "application/sdp" {
return true
}
return false
}
func (d *describeMethod) Handle(p *packet.Packet) {
if !d.isAcceptable(p) {
p.Response.StatusCode = http.StatusNotAcceptable
p.Response.StatusText = http.StatusText(http.StatusNotAcceptable)
return
}
// We send the SDP representation of options used when creating the
// server
p.Response.Body = d.Session.Bytes()
// var b []byte
// p.Response.Body = d.Session.AppendTo(b)
p.Response.StatusCode = http.StatusOK
p.Response.StatusText = http.StatusText(http.StatusOK)
p.Response.Headers.Add("Content-Length",
fmt.Sprintf("%d", len(string(p.Response.Body))))
}
func (d *describeMethod) Type() methodType {
return methodDescribe
}