github.com/haalcala/mattermost-server-change-repo@v0.0.0-20210713015153-16753fbeee5f/app/plugin_api_tests/manual.test_http_hijack_plugin/main.go (about) 1 // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. 2 // See LICENSE.txt for license information. 3 4 package main 5 6 import ( 7 "net/http" 8 9 "github.com/mattermost/mattermost-server/v5/plugin" 10 ) 11 12 type Plugin struct { 13 plugin.MattermostPlugin 14 } 15 16 func (p *Plugin) ServeHTTP(_ *plugin.Context, w http.ResponseWriter, _ *http.Request) { 17 hj, ok := w.(http.Hijacker) 18 if !ok { 19 w.WriteHeader(http.StatusInternalServerError) 20 return 21 } 22 23 conn, brw, err := hj.Hijack() 24 if conn == nil || brw == nil || err != nil { 25 w.WriteHeader(http.StatusInternalServerError) 26 return 27 } 28 29 conn.Write([]byte("HTTP/1.1 200\n\nOK")) 30 conn.Close() 31 } 32 33 func main() { 34 plugin.ClientMain(&Plugin{}) 35 }