We moved this page to our Documentation Portal. You can find the latest updates here. |
Question
Dynamic Speed Limiting
Environment
OnApp CDN
Answer
Note: This feature is not available on the UI, and therefore, kindly contact our support team if you would like to enable it. Dynamic Speed Limiting feature allows customers to restrict the maximum speed based on the specified parameter on the URL, e.g.:
- http://cdn.example.com/testvideo.mp4?speed=1000 - the maximum speed allowed to stream this video is up to 1000B/s
This feature also works along with the existing feature, URL signing, where the speed parameter is required to match with the hash key.
- http://cdn.example.com/testvideo.mp4?speed=1000&secure=SasZXasd - This is the same as above, however, if visitor changing the speed value manually themselves, the video will not able to be viewed.
For generating the harsh key, kindly refer to below for example script in Python:
import hashlib import string import base64 import time # Fill in speed parameter and secret key secret_key = '' speed = '1000' url="/index.html" # Expiry time expires_y = 2013 expires_m = 9 expires_d = 29 expires_H = 0 expires_M = 0 expires_S = 0 expires = str(int(time.mktime(time.strptime("%d-%d-%d %d:%d:%d" % (expires_y , expires_m , expires_d , expires_H , expires_M , expires_S) , '%Y-%m-%d %H:%M:%S')))) def get_hashkey(url , secret_key , expires='', speed=''): keystr = "%s%s%s%s" % (expires , url , secret_key, speed) #hash_key = md5.new() # for python < 2.5 hash_key = hashlib.md5() hash_key.update(keystr) base64_hash_key = base64.encodestring(hash_key.digest()).rstrip('\n').replace('+' , '-').replace('/' , '_') return base64_hash_key # Print the results: print "Details: '%s' '%s' '%s' '%s'" % (url, secret_key, expires, speed) print "No Expires : %s " % (get_hashkey(url , secret_key)) print "With Expires : %s " % (get_hashkey(url , secret_key , expires)) print "No Expires & Speed : %s " % (get_hashkey(url , secret_key, speed=speed)) print "With Expires & Speed : %s " % (get_hashkey(url , secret_key , expires, speed=speed))