File: simple_request.htb

package info (click to toggle)
httest 2.2.6-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,188 kB
  • sloc: ansic: 17,134; sh: 10,389; makefile: 490; lisp: 145
file content (75 lines) | stat: -rw-r--r-- 1,578 bytes parent folder | download
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
70
71
72
73
74
75
# This DSL is for testing Applications.
# Implements a request method with automatic cookie handling and follow 
# redirect. It is much like get a page with your favorit browser.
#

MODULE SIMPLE

BLOCK _FOLLOW RECURSION
_IF "$RECURSION" GT 20 
  _DEBUG Give up more than 20 redirects!
  _EXPECT headers "!HTTP/.\.. 302"
_END IF
_GREP headers "(HTTP/.\.. .*)" STATUS
_GREP headers "Location: (.*)" LOCATION
_RECORD RES ALL
_WAIT
_IF "${STATUS}" MATCH "302"
  _IF "YES${LOCATION}" NOT MATCH "^YES$"
    _SIMPLE:REQUEST GET $LOCATION
    __
    _OP $RECURSION ADD 1 RECURSION
    _SIMPLE:FOLLOW $RECURSION
  _END IF
_END IF
END

BLOCK _REQUEST METHOD URL
_GREP VAR(URL) "(https?:)" SCHEMA
_IF "$SCHEMA" NOT MATCH "^https?:" 
  _SET SCHEMA=relative
_END IF
_IF "$SCHEMA" NOT MATCH "^relative$"
  _MATCH VAR(URL) "(https?)://([^/]+)(/.*)" SCHEMA HOST URI
  _GREP VAR(HOST) "([^:]+):?(.*)?" NAME PORT
  _SET _HOST=$NAME:$PORT
  _IF "$SCHEMA" MATCH "^https$"
    _SET _PORT=SSL:$PORT
    _IF "YES${PORT}" MATCH "^YES$"
      _SET PORT=443
      _SET _PORT=SSL:443
      _SET _HOST=$NAME
    _END IF
  _ELSE
    _IF "YES$PORT" NOT MATCH "^YES$"
      _SET _PORT=$PORT
    _ELSE
      _SET PORT=80
      _SET _PORT=80
      _SET _HOST=$NAME
    _END IF
  _END IF
  _REQ $NAME $_PORT
_ELSE
  _MATCH VAR(URL) "(/.*)" URI
_END IF
__$METHOD $URI HTTP/1.1
__Host: $_HOST
__User-Agent: Mozilla
__Cookie: AUTO
END

BLOCK _GET URL
_AUTO_CLOSE on
_SIMPLE:REQUEST GET $URL
__
_SIMPLE:FOLLOW 0
_PLAY SOCKET
END

BLOCK _POST URL
_AUTO_CLOSE on
_SIMPLE:REQUEST POST $URL
__Content-Length: AUTO
END