// This may look like C code, but it's really -*- C++ -*-
/*
 * Copyright (C) 2009 Emweb bvba, Kessel-Lo, Belgium.
 *
 * See the LICENSE file for terms of use.
 */
#ifndef HTTP_RESPONSE_H_
#define HTTP_RESPONSE_H_

#include <string>
#include <Wt/WGlobal>
#include <Wt/Http/ResponseContinuation>
#include <string>

namespace Wt {

  class WResource;
  class WebSession;

  namespace Http {

/*! \class Response Wt/Http/Response Wt/Http/Response
 *  \brief An HTTP response.
 *
 * Use the HTTP response to format a response to an HTTP request (see
 * Request).
 *
 * More specifically you can:
 * - set the content mime type using setMimeType()
 * - add HTTP headers using addHeader()
 * - stream content into out()
 *
 * You may chose to provide only a partial response. In that case, use
 * createContinuation() to create a continuation object to which you
 * can annotate information for the next request to process the
 * response further.
 *
 * \sa WResource::handleRequest()
 */
class WT_API Response
{
public:
  /*! \brief Sets the response status.
   *
   * Unless a overriden, 200 OK will be assumed.
   */
  void setStatus(int status);

  /*! \brief Set the content mime type.
   *
   * The content mimetype is used by the browser to correctly interpret
   * the resource.
   */
  void setMimeType(const std::string& mimeType);

  /*! \brief Add an HTTP header.
   *
   * Headers may be added only before setting the content mime-type
   * (setMimeType()), and before streaming any data to the out()
   * stream.
   */
  void addHeader(const std::string& name, const std::string& value);

  /*! \brief Create a continuation object for this response.
   *
   * By creating a continuation object, a new request will be made for
   * the resource to retrieve more data, after the current data has
   * been sent out.
   *
   * \sa continuation()
   */
  ResponseContinuation *createContinuation();

  /*! \brief Return the continuation, if one was created for this response.
   *
   * Returns the continuation that was previously created using
   * createContinuation(), or 0 if no continuation was created yet.
   *
   * \sa createContinuation()
   */
  ResponseContinuation *continuation() const;

  /*! \brief Returns the stream for getting the response output.
   */
  std::ostream& out();

  WT_BOSTREAM& bout() { return out(); }

private:
  WResource            *resource_;
  WebResponse          *response_;
  ResponseContinuation *continuation_;
  WT_BOSTREAM          *out_;

  Response(WResource *resource, WebResponse *response,
	   ResponseContinuation *continuation);
  Response(WResource *resource, WT_BOSTREAM& out);

  friend class Wt::WResource;
  friend class Wt::WebSession;
};

  }
}

#endif // HTTP_RESPONSE_H_
