mirror of https://github.com/q191201771/lal.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.0 KiB
Go
58 lines
1.0 KiB
Go
package httpflv
|
|
|
|
import (
|
|
"bufio"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
type Writer interface {
|
|
// TODO chef: return error
|
|
WriteTag(tag *Tag)
|
|
}
|
|
|
|
var httpFlvErr = errors.New("httpflv: fxxk")
|
|
|
|
var readBufSize = 16384
|
|
|
|
// return 1st line and other headers with kv format
|
|
func parseHTTPHeader(r *bufio.Reader) (n int, firstLine string, headers map[string]string, err error) {
|
|
headers = make(map[string]string)
|
|
|
|
var line []byte
|
|
var isPrefix bool
|
|
line, isPrefix, err = r.ReadLine()
|
|
if err != nil {
|
|
return
|
|
}
|
|
if len(line) == 0 || isPrefix {
|
|
err = httpFlvErr
|
|
return
|
|
}
|
|
firstLine = string(line)
|
|
n += len(line)
|
|
|
|
for {
|
|
line, isPrefix, err = r.ReadLine()
|
|
if len(line) == 0 { // 读到一个空的 \r\n 表示http头全部读取完毕了
|
|
break
|
|
}
|
|
if isPrefix {
|
|
err = httpFlvErr
|
|
return
|
|
}
|
|
if err != nil {
|
|
return
|
|
}
|
|
l := string(line)
|
|
n += len(l)
|
|
pos := strings.Index(l, ":")
|
|
if pos == -1 {
|
|
err = httpFlvErr
|
|
return
|
|
}
|
|
headers[strings.Trim(l[0:pos], " ")] = strings.Trim(l[pos+1:], " ")
|
|
}
|
|
return
|
|
}
|