forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheaders.livecodescript
More file actions
69 lines (57 loc) · 1.76 KB
/
Copy pathheaders.livecodescript
File metadata and controls
69 lines (57 loc) · 1.76 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
script "TestLibUrlHeaders"
local sLogField
on TestSetup
TestSkipIfNot "platform", "MacOS,Windows,Linux"
TestSkipIf "stacks loaded", "tsNetLibURL"
TestSkipIf "environment", "server"
if not TestIsInStandalone() then
local tLibURl
put TestGetEngineRepositoryPath() & "/ide-support/revliburl.livecodescript" into tLibUrl
send "extensionInitialize" to stack tLibUrl
end if
create field
put it into sLogField
libUrlSetLogField sLogField
end TestSetup
-- Parse the log field to extract the HTTP header block
-- This is a bit fragile
private function GetHeadersFromLogField
local tHeaders, tFound, tLine
put false into tFound
repeat for each line tLine in the text of sLogField
if not tFound then
if "/ HTTP/1.1" is in tLine then
put true into tFound
else
next repeat
end if
end if
if tLine is empty then
exit repeat
end if
put tLine & return after tHeaders
end repeat
return tHeaders
end GetHeadersFromLogField
on TestHostHeader
constant kTestHost = "uniquehostname.example.org"
set the httpHeaders to "Host:" && kTestHost
post "dummy content" to "http://127.0.0.1:16000"
local tHeaders
put GetHeadersFromLogField() into tHeaders
TestDiagnostic tHeaders
local tHostCount
put 0 into tHostCount
repeat for each line tLine in tHeaders
put word 1 to -1 of tLine into tLine
if tLine begins with "Host:" then
TestAssert "host header has correct value", tLine ends with kTestHost
add 1 to tHostCount
end if
end repeat
TestAssert "exactly one host header", tHostCount is 1
end TestHostHeader
on TestTeardown
set the httpHeaders to empty
libUrlSetLogField empty
end TestTeardown