-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathurl_rewrite.coffee
52 lines (43 loc) · 1.41 KB
/
url_rewrite.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
class URLRewrite
constructor: (@env) ->
@userAgent = @env.get 'ReplayLogger'
loginURL: (request) ->
basePathRegex = @env.get 'basePathRegex'
if basePathRegex
prefix = request.path.match(basePathRegex)[1]
else
prefix = ''
loginPath = "#{prefix}#{@env.get 'authPath'}"
@getURL request, loginPath
loginData: ->
opts =
headers:
'User-Agent': @userAgent
data: @env.get 'authData'
getOptions: (cookie, postData) ->
headers:
'User-Agent': @userAgent
'Cookie': cookie
data: postData
followRedirects: false
processPath: (path) ->
pathConfig = @env.get 'path'
if pathConfig
path.replace pathConfig.regex, pathConfig.replace
else
path
processHost: (host) ->
hostConfig = @env.get 'host'
if hostConfig
host.replace hostConfig.regex, hostConfig.replace
else
host
getClientId: (url) ->
clientRegex = @env.get 'clientRegex'
url.match(clientRegex)[1]
getURL: (request, inpath = request.path) ->
protocol = if request.server_info.HTTPS? then 'https://' else 'http://'
host = @processHost request.server_info.HTTP_HOST
path = @processPath inpath
"#{protocol}#{host}#{path}"
module.exports = URLRewrite