~george-edison55/jethttp/jethttp-singlethread

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
//=================================================
//
//             JetHTTP - CCGIOutput.cpp
//           Copyright 2011 - Nathan Osman
//     This file is released under the GPL v3
//
//=================================================

#include <CCGIOutput.h>

// Qt includes
#include <QProcessEnvironment>
#include <QUrl>

void CCGIOutput::ProcessRequest(QString request_url, QString query_string, CHeaderManager & headers)
{
    // In order to do this the most efficient way, we'll
    // simply tack the parameters we got together again
    // in a QUrl so we can URL-decode them, etc.
    QUrl url(QObject::tr("%1?%2").arg(request_url).arg(query_string));

    // Assume that /var/www is the document root
    QString absolute_path(m_settings.GetSetting("System/DocumentRoot", "/var/www").toString());
    absolute_path.append(request_url);

    // Now we have the absolute path to the CGI
    // script.

    // Our first step is to set some environment variables
    QProcessEnvironment env;

    env.insert("SERVER_SOFTWARE",   "JetHTTP 0.1 Beta");
    env.insert("GATEWAY_INTERFACE", "CGI/1.1");
    env.insert("SERVER_PROTOCOL",   "HTTP/1.1");

    env.insert("QUERY_STRING",      url.encodedQuery());
    env.insert("REQUEST_URI",       url.toString());
    env.insert("SCRIPT_FILENAME",   absolute_path);

    env.insert("REQUEST_METHOD",    "GET");

    /*
    if(bPost)
    {
        env.insert("CONTENT_LENGTH", tr("%1").arg(content_length));
        env.insert("CONTENT_TYPE",   "application/x-www-form-urlencoded");
    }
    */

    // TODO: fix this
    env.insert("REMOTE_ADDR",       "127.0.0.1");

    env.insert("REDIRECT_STATUS",   "true");

    // Now we call the derived method 'Invoke'
    Invoke(env, absolute_path, headers);
}