Adding interplugin communication. (#12829)

* Adding interplugin communication.

* Naming changes and moving ResponseTransfer to own file.

* Fix.

* Tests and moving to buffering bytes.

* Switching API to passing plugin ID through path rather than a header.

* Review feedback.
Этот коммит содержится в:
Christopher Speller
2019-11-04 17:35:58 -08:00
коммит произвёл GitHub
родитель 501da809f3
Коммит 428454cee4
9 изменённых файлов: 351 добавлений и 19 удалений

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

@@ -10,6 +10,7 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"path/filepath"
"strings"
@@ -825,3 +826,29 @@ func (api *PluginAPI) DeleteBotIconImage(userId string) *model.AppError {
return api.app.DeleteBotIconImage(userId)
}
func (api *PluginAPI) PluginHTTP(request *http.Request) *http.Response {
split := strings.SplitN(request.URL.Path, "/", 3)
if len(split) != 3 {
return &http.Response{
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(bytes.NewBufferString("Not enough URL. Form of URL should be /<pluginid>/*")),
}
}
destinationPluginId := split[1]
newURL, err := url.Parse("/" + split[2])
request.URL = newURL
if destinationPluginId == "" || err != nil {
message := "No plugin specified. Form of URL should be /<pluginid>/*"
if err != nil {
message = "Form of URL should be /<pluginid>/* Error: " + err.Error()
}
return &http.Response{
StatusCode: http.StatusBadRequest,
Body: ioutil.NopCloser(bytes.NewBufferString(message)),
}
}
responseTransfer := &PluginResponseWriter{}
api.app.ServeInterPluginRequest(responseTransfer, request, api.id, destinationPluginId)
return responseTransfer.GenerateResponse()
}