File: php_httprequest1.tpl

package info (click to toggle)
weevely 4.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,336 kB
  • sloc: python: 7,732; php: 1,035; sh: 53; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download | duplicates (4)
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
if(class_exists('HttpRequest')) {
    $r = new HttpRequest("${ url }", HttpRequest::METH_${ request if not data else 'POST' });

    $r->setOptions(array('connecttimeout'=>${ connect_timeout }));

    % if header or cookie or user_agent or data:
    $r->addHeaders(
        array(
    % for h in header:
    %   if not (data and (h.title().startswith('Content-Length: '))) and not (user_agent and h.title().startswith('User-Agent: ')):
            "${ h.split(':')[0] }" => "${ h.split(':')[1].lstrip() }",
    %   endif
    % endfor
    % if user_agent:
            'User-Agent'=>"${ user_agent }",
    % endif
    % if cookie:
              'Cookie'=>"${ cookie }",
    % endif
        )
    );
    % endif

    % if data:
    $r->addRawPostData("${ ''.join(data) }");
    % endif

    try {
        $r = $r->send();
    } catch (HttpException $ex) { }

    print("HTTP/" . $r->getHttpVersion() . " " . $r->getResponseCode() . " " . $r->getResponseStatus() . "\r\n");

    foreach($r->getHeaders() as $h => $v) {
        print("$h: $v\r\n");
    }
    print("\r\n" . $r->getBody());
}