修改http返回

This commit is contained in:
duanhf2012
2020-04-11 10:03:03 +08:00
parent c7c1558cc3
commit ff8ec204f6
2 changed files with 21 additions and 8 deletions

View File

@@ -167,7 +167,6 @@ func (slf *HttpSession) DelHeader(key string) {
slf.r.Header.Del(key)
}
func (slf *HttpSession) WriteStatusCode(statusCode int){
slf.statusCode = statusCode
}
@@ -176,15 +175,18 @@ func (slf *HttpSession) Write(msg []byte) {
slf.msg = msg
}
func (slf *HttpSession) WriteJson(msgJson interface{}) error {
func (slf *HttpSession) WriteJsonDone(statusCode int,msgJson interface{}) error {
msg, err := json.Marshal(msgJson)
if err == nil {
slf.Write(msg)
}
slf.Done()
return err
}
func (slf *HttpSession) flush() {
slf.w.WriteHeader(slf.statusCode)
if slf.msg!=nil {
@@ -192,7 +194,7 @@ func (slf *HttpSession) flush() {
}
}
func (slf *HttpSession) done(){
func (slf *HttpSession) Done(){
slf.sessionDone <- slf
}
@@ -259,7 +261,7 @@ func (slf *HttpRouter) Router(session *HttpSession){
if slf.httpFiltrateList!=nil {
for _,fun := range slf.httpFiltrateList{
if fun(session) == false {
session.done()
//session.done()
return
}
}
@@ -278,7 +280,7 @@ func (slf *HttpRouter) Router(session *HttpSession){
}
v.httpHandle(session)
session.done()
//session.done()
return
}
@@ -286,13 +288,13 @@ func (slf *HttpRouter) Router(session *HttpSession){
idx := strings.Index(urlPath, k)
if idx != -1 {
session.fileData = v
session.done()
session.Done()
return
}
}
session.WriteStatusCode(http.StatusNotFound)
session.done()
session.Done()
}
func (slf *HttpService) SetHttpRouter(httpRouter IHttpRouter) {