/*
**
**      Copyright (c) 2000-2004 ChoiceStream, Inc.  All Rights Reserved
**
**      ChoiceStream
**      210 Broadway
**      Cambridge, MA 02139
**
**  $Id: httprequest.h,v 1.16 2005/03/18 22:33:45 mmastroianni Exp $
**
**/

#ifndef CSM_HTTPREQUEST_H
#define CSM_HTTPREQUEST_H

#include <string>
#include <vector>
#include <list>

#include "strutil.h"

typedef std::hash_map<std::string, std::list<std::string> > HttpHeaders;

// Standard HTTP content-types to pass in from our code
const static std::string CONTENT_FORM_URLENCODED = "application/x-www-form-urlencoded";
const static std::string CONTENT_TEXT_XML        = "text/xml";
const static std::string CONTENT_CS_RPC          = "application/x-choicestream-rpc";

namespace csm {

    enum HttpMethod
    {
        HTTP_NULL_METHOD = 0,
        HTTP_GET,
        HTTP_POST,
        HTTP_HEAD,
        HTTP_OPTIONS,
        HTTP_DELETE,
        HTTP_PUT,
        HTTP_TRACE,
        HTTP_CONNECT
    };

    struct HttpForm
    {
        std::string name;
        std::string type;
        std::string contents;
    };

    typedef std::vector<HttpForm> HttpFormList;

    struct HttpRequest
    {
        HttpRequest();
        // In a POST request, is this multipart/mime?
        bool multipart;
        
        // Right now only GET and POST are supported
        HttpMethod   method;

        // Any extra HTTP headers
        // Note: Do NOT set Content-Type or -Length
        // in here...
        HttpHeaders  headers;

        // The target endpoint
        std::string  url;

        // If the request is not multipart, only the first 
        // form is used.
        HttpFormList body;

        // The following are needed to configure the curl request underlying all of this
        std::string     userAgent;
        int             connectTimeout;
        int             timeout;
        bool            useCookies;
        std::string     cookieFile;
        bool            followRedirect;
        int             maxRedirectFollow;
    };
}

#endif

