
include 'constants.bnf'

<%pre
    import socket
    import random
    import struct
    import logging

    host = $host

    try:
        skt
    except NameError:
        try:
            skt = socket.socket()
            skt.connect(($host,80))
        except socket.error, e:
            logging.error('%s', e)
            exit()
%>

$SEND_HTTP_REQUEST(start):
    REQUEST <%
        print $$
        print

        skt.send($$)
        $* = skt.recv(1500)

        headers,body = $*.split('\r\n\r\n', 1)

        print '%s\n' % headers
        print '%s' % body
    %>;

REQUEST:
    "GET " URL " HTTP/1.1" CRLF
    "Host: " &host CRLF
    HEADER {0,10}
    CRLF
    ;

URL: '/' ('index.' EXTENSION | WORD '.' EXTENSION);

EXTENSION: WORD[:3];

HEADER: HEADERS ": " WORD CRLF;

HEADERS:
    'Content-Type' | 'Date' | 'Content-Encoding'
    ;