예제 #1
0
bool uwsgi_handler::handle_request() {
    // Do something with the url for example
    // const std::string& url = request().var("REQUEST_URI");
    // Or print all incoming variables
    // request().print_vars();

    typedef tasks::net::uwsgi_thrift_transport<tasks::net::http_response> transport_type;
    typedef apache::thrift::protocol::TBinaryProtocol protocol_type;

    boost::shared_ptr<transport_type> transport(new transport_type(response_p()));
    boost::shared_ptr<protocol_type> protocol(new protocol_type(transport));
    tasks::tools::thrift_server_writer<id_name, transport_type, protocol_type> writer("lookup", transport, protocol);

    id_name m;
    m.id = 33;
    m.name = "testtest";
    writer.write(m);

    // Now send back a response
    response().set_status("200 OK");
    response().set_header("Content-Type", "application/x-thrift");
    send_response();

    stats::inc_req();

    return true;
}
예제 #2
0
status_t show_file_list(http_response page, const char *desc, list lst)
{
    list_iterator i;
    char buf[100];
    struct tm t;

    const char *table_start =
        "<table columns='2' border='1' borderwidth='2'>\n"
        "<th>File name</th>\n"
        "<th>Alias/URI</th>\n"
        "<th>Size</th>\n"
        "<th>Last modified</th>\n";

    const char *table_end =
        "</table>\n";

    if (!response_p(page, desc))
        return failure;

    if (!response_add(page, table_start))
        return failure;

    for (i = list_first(lst); !list_end(i); i = list_next(i)) {
        fileinfo fi = list_get(i);
        const struct stat *pst = fileinfo_stat(fi);

        verbose(3, "Adding table td for file %s\n", fileinfo_alias(fi));
        if (!response_add(page, "<tr>\n")
        || !response_td(page, fileinfo_name(fi))
        || !response_td(page, fileinfo_alias(fi)))
            return failure;

        sprintf(buf, "%d", (int)pst->st_size);
        if (!response_td(page, buf))
            return failure;

        localtime_r(&pst->st_mtime, &t);
        asctime_r(&t, buf);
        if (!response_td(page, buf) || !response_add(page, "</tr>\n"))
            return failure;
    }

    if (!response_add(page, table_end))
        return failure;

    return success;
}