Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117858236
D260.1775317687.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None
D260.1775317687.diff
View Options
diff --git a/config/config.exs b/config/config.exs
--- a/config/config.exs
+++ b/config/config.exs
@@ -30,4 +30,9 @@
# import_config "#{Mix.env}.exs"
config :kolab_wopi,
+ host_info: [
+ endpoint_desc: "Kolab Systems, Zurich",
+ machine_name: to_string(Node.self()),
+ version: "kolab_wopi_v" <> to_string(Keyword.get(Mix.Project.get!().project(), :version)) #:application.get_key(:kolab_wopi, :description))
+ ],
chwala_base_url: "http://localhost/chwala/api/"
diff --git a/lib/kolab_wopi/api.ex b/lib/kolab_wopi/api.ex
--- a/lib/kolab_wopi/api.ex
+++ b/lib/kolab_wopi/api.ex
@@ -11,6 +11,7 @@
require Logger
plug Plug.Logger
+ plug :wopi_headers
plug :access_token_handler
plug :match
plug :dispatch
@@ -34,6 +35,19 @@
@doc """
+ Plug that adds the standard WOPI response headers
+
+ @see https://wopirest.readthedocs.io/en/latest/common_headers.html
+ """
+ def wopi_headers(conn, _opts) do
+ host_info = Application.get_env(:kolab_wopi, :host_info)
+ conn
+ |> put_resp_header("X-WOPI-HostEndpoint", Keyword.get(host_info, :endpoint_desc))
+ |> put_resp_header("X-WOPI-MachineName", Keyword.get(host_info, :machine_name))
+ |> put_resp_header("X-WOPI-ServerVersion", Keyword.get(host_info, :version))
+ end
+
+ @doc """
Plug that fetches query parameters and validates the access_token.
The access_token parameter is required in every WOPI request.
@@ -63,13 +77,20 @@
It supports Chwala status codes.
"""
- def send_status_resp(conn, code, reason \\ nil)
+ def send_status_resp(conn, code, reason \\ "Unknown error")
def send_status_resp(conn, 403, reason) do
# Chwala uses only 200, 403, 500, 501, 503
send_status_resp(conn, 401, reason)
end
+ def send_status_resp(conn, code, reason) when code >= 500 and code < 600 do
+ # TODO: log status reason?
+ conn
+ |> put_resp_header("X-WOPI-ServerError", reason)
+ |> send_resp(code, "")
+ end
+
def send_status_resp(conn, code, _reason) do
# TODO: log status reason?
send_resp(conn, code, "")
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Apr 4, 3:48 PM (13 h, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18803259
Default Alt Text
D260.1775317687.diff (2 KB)
Attached To
Mode
D260: WOPI-compliant headers
Attached
Detach File
Event Timeline