@@ -14,7 +14,7 @@ defmodule Unlock.Controller do
1414
1515 use Phoenix.Controller , formats: [ html: "View" , json: "View" ]
1616 require Logger
17- import Unlock.GunzipTools
17+ import Unlock.GunzipTools , only: [ lowercase_headers: 1 ]
1818
1919 @ doc """
2020 A simple index "page", useful to verify that the proxy is up, since it is served
@@ -39,7 +39,6 @@ defmodule Unlock.Controller do
3939 - `%Unlock.Config.Item.Generic.HTTP{}` for HTTP-provided single GTFS-RT & CSV feeds
4040 - `%Unlock.Config.Item.DynamicIRVEAggregate{}` for the on-the-fly dynamic IRVE consolidation
4141 - `%Unlock.Config.Item.S3{}` for internal-S3-backed single file feeds (CSV or anything really)
42- - `%Unlock.Config.Item.SIRI{}` for SIRI proxying (experimental)
4342 - `%Unlock.Config.Item.GBFS{}` for GBFS feeds (with multiple endpoints)
4443
4544 Once the item is found in configuration, different `process_resource` pattern-matching variants
@@ -203,41 +202,6 @@ defmodule Unlock.Controller do
203202
204203 defp process_resource ( conn , % Unlock.Config.Item.Generic.HTTP { } ) , do: send_not_allowed ( conn )
205204
206- # NOTE: this code is designed for private use for now. I have tracked
207- # what is required or useful for public opening later here:
208- # https://github.com/etalab/transport-site/issues/2476
209- #
210- # SIRI support is experimental. For now we are encouraging instead SIRI provider to
211- # get their game up and improve their ops & software, so that they can directly handle
212- # SIRI loads without the proxy.
213- #
214- # For SIRI, only `POST` is allowed since this is the protocol.
215- #
216- # The code analyses the incoming XML payload, & replace the `requestor_ref` (used sometimes
217- # as an API key) transparently with the one we have configured.
218- #
219- defp process_resource ( % Plug.Conn { method: "POST" } = conn , % Unlock.Config.Item.SIRI { } = item ) do
220- { :ok , body , conn } = Plug.Conn . read_body ( conn , length: 1_000_000 )
221-
222- parsed = Unlock.SIRI . parse_incoming ( body )
223-
224- { modified_xml , external_requestor_refs } =
225- Unlock.SIRI.RequestorRefReplacer . replace_requestor_ref ( parsed , item . requestor_ref )
226-
227- # NOTE: here we assert both that the requestor ref is what is expected, but also that it
228- # is met once only. I am not deduping them at the moment on purpose, maybe we'll do that
229- # later based on experience.
230- if external_requestor_refs == [ Application . fetch_env! ( :transport , :unlock_siri_public_requestor_ref ) ] do
231- handle_authorized_siri_call ( conn , item , modified_xml )
232- else
233- send_resp ( conn , 403 , "Forbidden" )
234- end
235- end
236-
237- # Forbid `GET` calls for SIRI, explicitely, since this is not the way to issue a SIRI call.
238- defp process_resource ( % Plug.Conn { method: "GET" } = conn , % Unlock.Config.Item.SIRI { } ) ,
239- do: send_not_allowed ( conn )
240-
241205 defp process_resource ( % Plug.Conn { method: "GET" } = conn , % Unlock.Config.Item.GBFS { endpoint: nil } ) do
242206 conn |> send_resp ( 404 , "Not Found" )
243207 end
@@ -277,30 +241,6 @@ defmodule Unlock.Controller do
277241 |> override_resp_headers_if_configured ( item )
278242 end
279243
280- @ spec handle_authorized_siri_call ( Plug.Conn . t ( ) , Unlock.Config.Item.SIRI . t ( ) , Saxy.XML . element ( ) ) :: Plug.Conn . t ( )
281- # The SIRI query is serialized into iodata, then a `POST` query is issued.
282- #
283- # On completion, we unzip if needed to smooth out implementations, filter response headers,
284- # and send back the answer to the client.
285- defp handle_authorized_siri_call ( conn , % Unlock.Config.Item.SIRI { } = item , xml ) do
286- body = Saxy . encode_to_iodata! ( xml , version: "1.0" )
287-
288- response = Unlock.HTTP.Client . impl ( ) . post! ( item . target_url , item . request_headers , body )
289-
290- headers = response . headers |> lowercase_headers ( )
291-
292- # NOTE: for now, we unzip systematically. This will make it easier
293- # to analyse payloads & later remove sensitive data, even if we
294- # re-zip afterwards.
295- body = maybe_gunzip ( response . body , headers )
296-
297- headers
298- |> filter_response_headers ( )
299- |> Enum . reduce ( conn , fn { h , v } , c -> put_resp_header ( c , h , v ) end )
300- # No content-disposition as attachment for now
301- |> send_resp ( response . status , body )
302- end
303-
304244 # A wrapper grouping reused logic for two cases:
305245 # - `%Unlock.Config.Item.Generic.HTTP{}` (GTFS-RT, external CSV etc)
306246 # - `%Unlock.Config.Item.S3{}` (internal S3 backend)
0 commit comments