[MM-16473] Make plugins' ServerHTTP http.ResponseWriter hijackable (#14822)

* Make plugins' ServerHTTP http.ResponseWriter hijackable

* Rename brw to align with docs

* Fix error handling
Этот коммит содержится в:
Claudio Costa
2020-06-26 10:51:23 +02:00
коммит произвёл GitHub
родитель 0118db9d23
Коммит d0e035467c
5 изменённых файлов: 374 добавлений и 0 удалений

Просмотреть файл

@@ -0,0 +1,35 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
package main
import (
"net/http"
"github.com/mattermost/mattermost-server/v5/plugin"
)
type Plugin struct {
plugin.MattermostPlugin
}
func (p *Plugin) ServeHTTP(c *plugin.Context, w http.ResponseWriter, r *http.Request) {
hj, ok := w.(http.Hijacker)
if !ok {
w.WriteHeader(http.StatusInternalServerError)
return
}
conn, brw, err := hj.Hijack()
if conn == nil || brw == nil || err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
conn.Write([]byte("HTTP/1.1 200\n\nOK"))
conn.Close()
}
func main() {
plugin.ClientMain(&Plugin{})
}