-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.go
More file actions
63 lines (53 loc) · 1.43 KB
/
request.go
File metadata and controls
63 lines (53 loc) · 1.43 KB
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
62
63
// Copyright 2017 sip authors. All rights reserved.
// Use of this source code is governed by a MIT-style license that can be
// found in the LICENSE file.
package sip
import (
"bytes"
)
type Request struct {
Method string
RUri string
SipVersion string
Headers map[string]string
Body string
}
func (req Request) Type() MessageType {
return TypeRequest
}
func (req Request) GetBody() string {
return req.Body
}
func (req Request) GetHeaders() map[string]string {
return req.Headers
}
func (req Request) GetFirstLine() string {
return req.Method + " " + req.RUri + " " + req.SipVersion
}
func (req Request) SetBody(b string) {
req.Body = b
}
func (req Request) AddHeader(name string, value string) {
req.Headers[name] = value
}
func (req Request) Serialize() []byte {
var serializedMessage bytes.Buffer
serializedMessage.WriteString(req.Method)
serializedMessage.WriteString(" ")
serializedMessage.WriteString(req.RUri)
serializedMessage.WriteString(" ")
serializedMessage.WriteString(req.SipVersion)
serializedMessage.WriteString("\r\n")
for name, value := range req.Headers {
serializedMessage.WriteString(name)
serializedMessage.WriteString(": ")
serializedMessage.WriteString(value)
serializedMessage.WriteString("\r\n")
}
serializedMessage.WriteString("\r\n")
if len(req.Body) > 0 {
serializedMessage.WriteString(req.Body)
serializedMessage.WriteString("\r\n")
}
return serializedMessage.Bytes()
}