From 264a53f6671e383673028290054593e1452c5e99 Mon Sep 17 00:00:00 2001 From: joestarzxh Date: Fri, 9 Jul 2021 15:09:12 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=E4=BD=BF=E7=94=A8=E5=AE=98=E6=96=B9=20ht?= =?UTF-8?q?tp.Header=20=E6=9B=BF=E6=8D=A2=E5=8E=9F=E6=9D=A5http=E7=9A=84?= =?UTF-8?q?=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/httpflv/client_pull_session.go | 3 ++- pkg/rtsp/client_command_session.go | 10 +++++----- pkg/rtsp/server_command_session.go | 20 ++++++++++---------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pkg/httpflv/client_pull_session.go b/pkg/httpflv/client_pull_session.go index 238a4ee..ab811cd 100644 --- a/pkg/httpflv/client_pull_session.go +++ b/pkg/httpflv/client_pull_session.go @@ -12,6 +12,7 @@ import ( "context" "fmt" "net" + "net/http" "time" "github.com/q191201771/lal/pkg/base" @@ -225,7 +226,7 @@ func (session *PullSession) writeHttpRequest() error { return err } -func (session *PullSession) readHttpRespHeader() (statusLine string, headers nazahttp.HttpHeaders, err error) { +func (session *PullSession) readHttpRespHeader() (statusLine string, headers http.Header, err error) { // TODO chef: timeout if statusLine, headers, err = nazahttp.ReadHttpHeader(session.conn); err != nil { return diff --git a/pkg/rtsp/client_command_session.go b/pkg/rtsp/client_command_session.go index 7c19060..64dcb89 100644 --- a/pkg/rtsp/client_command_session.go +++ b/pkg/rtsp/client_command_session.go @@ -341,7 +341,7 @@ func (session *ClientCommandSession) writeOptions() error { return err } - method := ctx.Headers.Value(HeaderPublic) + method := ctx.Headers.Get(HeaderPublic) if method== "" { return nil @@ -429,9 +429,9 @@ func (session *ClientCommandSession) writeOneSetup(setupUri string) error { return err } - session.sessionId = strings.Split(ctx.Headers.Value(HeaderSession), ";")[0] + session.sessionId = strings.Split(ctx.Headers.Get(HeaderSession), ";")[0] - rRtpPort, rRtcpPort, err := parseServerPort(ctx.Headers.Value(HeaderTransport)) + rRtpPort, rRtcpPort, err := parseServerPort(ctx.Headers.Get(HeaderTransport)) if err != nil { return err } @@ -481,7 +481,7 @@ func (session *ClientCommandSession) writeOneSetupTcp(setupUri string) error { return err } - session.sessionId = strings.Split(ctx.Headers.Value(HeaderSession), ";")[0] + session.sessionId = strings.Split(ctx.Headers.Get(HeaderSession), ";")[0] // TODO chef: 这里没有解析回传的channel id了,因为我假定了它和request中的是一致的 session.observer.OnSetupWithChannel(setupUri, rtpChannel, rtcpChannel) @@ -551,7 +551,7 @@ func (session *ClientCommandSession) writeCmdReadResp(method, uri string, header return } //目前只处理第一个 - session.auth.FeedWwwAuthenticate(ctx.Headers.Value(HeaderWwwAuthenticate), session.urlCtx.Username, session.urlCtx.Password) + session.auth.FeedWwwAuthenticate(ctx.Headers.Get(HeaderWwwAuthenticate), session.urlCtx.Username, session.urlCtx.Password) } err = ErrRtsp diff --git a/pkg/rtsp/server_command_session.go b/pkg/rtsp/server_command_session.go index d5c9394..8073cea 100644 --- a/pkg/rtsp/server_command_session.go +++ b/pkg/rtsp/server_command_session.go @@ -189,7 +189,7 @@ Loop: func (session *ServerCommandSession) handleOptions(requestCtx nazahttp.HttpReqMsgCtx) error { nazalog.Infof("[%s] < R OPTIONS", session.uniqueKey) - resp := PackResponseOptions(requestCtx.Headers.Value(HeaderCSeq)) + resp := PackResponseOptions(requestCtx.Headers.Get(HeaderCSeq)) _, err := session.conn.Write([]byte(resp)) return err } @@ -218,7 +218,7 @@ func (session *ServerCommandSession) handleAnnounce(requestCtx nazahttp.HttpReqM return ErrRtsp } - resp := PackResponseAnnounce(requestCtx.Headers.Value(HeaderCSeq)) + resp := PackResponseAnnounce(requestCtx.Headers.Get(HeaderCSeq)) _, err = session.conn.Write([]byte(resp)) return err } @@ -243,7 +243,7 @@ func (session *ServerCommandSession) handleDescribe(requestCtx nazahttp.HttpReqM sdpLogicCtx, _ := sdp.ParseSdp2LogicContext(rawSdp) session.subSession.InitWithSdp(rawSdp, sdpLogicCtx) - resp := PackResponseDescribe(requestCtx.Headers.Value(HeaderCSeq), string(rawSdp)) + resp := PackResponseDescribe(requestCtx.Headers.Get(HeaderCSeq), string(rawSdp)) _, err = session.conn.Write([]byte(resp)) return err } @@ -256,7 +256,7 @@ func (session *ServerCommandSession) handleSetup(requestCtx nazahttp.HttpReqMsgC host, _, _ := net.SplitHostPort(remoteAddr) // 是否为interleaved模式 - htv := requestCtx.Headers.Value(HeaderTransport) + htv := requestCtx.Headers.Get(HeaderTransport) if strings.Contains(htv, TransportFieldInterleaved) { rtpChannel, rtcpChannel, err := parseRtpRtcpChannel(htv) if err != nil { @@ -278,12 +278,12 @@ func (session *ServerCommandSession) handleSetup(requestCtx nazahttp.HttpReqMsgC return ErrRtsp } - resp := PackResponseSetup(requestCtx.Headers.Value(HeaderCSeq), htv) + resp := PackResponseSetup(requestCtx.Headers.Get(HeaderCSeq), htv) _, err = session.conn.Write([]byte(resp)) return err } - rRtpPort, rRtcpPort, err := parseClientPort(requestCtx.Headers.Value(HeaderTransport)) + rRtpPort, rRtcpPort, err := parseClientPort(requestCtx.Headers.Get(HeaderTransport)) if err != nil { nazalog.Errorf("[%s] parseClientPort failed. err=%+v", session.uniqueKey, err) return err @@ -313,14 +313,14 @@ func (session *ServerCommandSession) handleSetup(requestCtx nazahttp.HttpReqMsgC return ErrRtsp } - resp := PackResponseSetup(requestCtx.Headers.Value(HeaderCSeq), htv) + resp := PackResponseSetup(requestCtx.Headers.Get(HeaderCSeq), htv) _, err = session.conn.Write([]byte(resp)) return err } func (session *ServerCommandSession) handleRecord(requestCtx nazahttp.HttpReqMsgCtx) error { nazalog.Infof("[%s] < R RECORD", session.uniqueKey) - resp := PackResponseRecord(requestCtx.Headers.Value(HeaderCSeq)) + resp := PackResponseRecord(requestCtx.Headers.Get(HeaderCSeq)) _, err := session.conn.Write([]byte(resp)) return err } @@ -330,14 +330,14 @@ func (session *ServerCommandSession) handlePlay(requestCtx nazahttp.HttpReqMsgCt if ok := session.observer.OnNewRtspSubSessionPlay(session.subSession); !ok { return ErrRtsp } - resp := PackResponsePlay(requestCtx.Headers.Value(HeaderCSeq)) + resp := PackResponsePlay(requestCtx.Headers.Get(HeaderCSeq)) _, err := session.conn.Write([]byte(resp)) return err } func (session *ServerCommandSession) handleTeardown(requestCtx nazahttp.HttpReqMsgCtx) error { nazalog.Infof("[%s] < R TEARDOWN", session.uniqueKey) - resp := PackResponseTeardown(requestCtx.Headers.Value(HeaderCSeq)) + resp := PackResponseTeardown(requestCtx.Headers.Get(HeaderCSeq)) _, err := session.conn.Write([]byte(resp)) return err }