Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Make Camera Endpoint Compatible with NGROK
Browse files Browse the repository at this point in the history
Certain ngrok configurations pass an "X-Original-Host" header as part of
the request if the host header is rewritten. This adds support for
detecting and using that header to make the Camera listing endpoint
seamless for clients using an ngrok URL
  • Loading branch information
Thomas Cannon committed Sep 29, 2016
1 parent 79cd1e3 commit 9aaabf6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Telemachus/src/CameraResponsibility.cs
Expand Up @@ -19,6 +19,7 @@ public class CameraResponsibility : IHTTPRequestResponder
/// The page prefix that this class handles
public const String PAGE_PREFIX = "/telemachus/cameras";
public const String CAMERA_LIST_ENDPOINT = PAGE_PREFIX;
public const String NGROK_ORIGINAL_HOST_HEADER = "X-Original-Host";
protected Regex _cameraNameEndpointRegex;
protected Regex cameraNameEndpointRegex
{
Expand Down Expand Up @@ -80,7 +81,17 @@ public void setCameraCapture()

public string cameraURL(HttpListenerRequest request, CameraCapture camera)
{
return request.Url.Scheme + "://" + request.UserHostName + PAGE_PREFIX + "/" + UnityEngine.WWW.EscapeURL(camera.cameraManagerName());
String hostname = "";
if (request.Headers.Contains(NGROK_ORIGINAL_HOST_HEADER))
{
hostname = request.Headers[NGROK_ORIGINAL_HOST_HEADER];
}
else
{
hostname = request.UserHostName;
}

return request.Url.Scheme + "://" + hostname + PAGE_PREFIX + "/" + UnityEngine.WWW.EscapeURL(camera.cameraManagerName());
}

public bool processCameraManagerIndex(HttpListenerRequest request, HttpListenerResponse response)
Expand Down

0 comments on commit 9aaabf6

Please sign in to comment.