raccoongang / xblock-video

Universal Video XBlock with pluggable backend for many video hosting providers
GNU General Public License v3.0
5 stars 16 forks source link

Studio hangs on srt_to_vtt call when host not localhost #279

Closed bryanlandia closed 2 years ago

bryanlandia commented 7 years ago

To reproduce:

  1. Browse to Studio on a domain other than 127.0.0.1 or localhost
  2. Create a Video XBlock instance
  3. Upload SRT caption files
  4. Preview instance in Studio
  5. AJAX calls to /preview/xblock/block-v1:.../handler/srt_to_vtt/?/asset-v1:XXX+type@asset+block@YYY.srt... will time out after 1 min with a 504 error
  6. Subsequent requests to Studio will also return 504

This occurs when browsing directly to Studio port or via Nginx.

504 errors loading

It is resolved with the changes in this diff.

diff --git a/video_xblock/mixins.py b/video_xblock/mixins.py
index 14588e2..fea15d3 100644
--- a/video_xblock/mixins.py
+++ b/video_xblock/mixins.py
@@ -325,7 +325,7 @@ class TranscriptsMixin(XBlock):
             webob.Response: WebVTT transcripts wrapped in Response object.
         """
         caps_path = request.query_string
-        caps = requests.get(request.host_url + caps_path).text
+        caps = requests.get(request.scheme+'://127.0.0.1' + caps_path).text
         return Response(self.convert_caps_to_vtt(caps))

     @XBlock.handler

Honestly, I'm not really sure why it is a problem. We have an XHR request sent to the handler_url for srt_to_vtt, which then makes a Python requests requests.get to the same domain.

(I suspect that this other change would also need to be made... )

diff --git a/video_xblock/mixins.py b/video_xblock/mixins.py
index 14588e2..0245683 100644
--- a/video_xblock/mixins.py
+++ b/video_xblock/mixins.py
@@ -302,7 +302,7 @@ class TranscriptsMixin(XBlock):
         """
         trans_path = self.get_path_for(request.query_string)
         filename = self.get_file_name_from_path(trans_path)
-        transcript = requests.get(request.host_url + request.query_string).text
+        transcript = requests.get(request.scheme + '://127.0.0.1' + request.query_string).text
         response = Response(transcript)
         headerlist = [
             ('Content-Type', 'text/plain'),

@wowkalucky @z4y4ts

bryanlandia commented 7 years ago

I implemented these changes as an at least temporary fix, here: https://github.com/appsembler/xblock-video/tree/appsembler/hotfix/srt-requests-use-localhost

I can make a PR if you want, but not sure what branch.