Source

Magnum / source / libs / magnum_net_http / source / magnum / net / http / HttpResponse.cpp

Full commit
/* 
  Magnum 
  Copyright (C) 2002-2012 Kaya Kupferschmidt. All Rights Reserved.

  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.

  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, under the terms in LICENSE.TXT.

  Kaya Kupferschmidt  (k.kupferschmidt@dimajix.de)
*/

#include "magnum/net/http/HttpRequest.h"
#include "magnum/net/http/HttpResponse.h"


namespace magnum { namespace net { namespace http {
using magnum::object::Nil;


/*--------------------------------------------------------------------------*/
/**
 */
HttpResponse::HttpResponse() 
: m_Version(HttpVersion::Http_1_1) 
{
}


/*--------------------------------------------------------------------------*/
/**
 */
HttpResponse::HttpResponse(const URL& url) 
    : m_Url(url)
    , m_Version(HttpVersion::Http_1_1) 
{
}


/*--------------------------------------------------------------------------*/
/**
 */
HttpResponse::HttpResponse(const HttpRequest& r)
	: m_Url(r.getURL())
	, m_Version(r.getVersion())
	, m_Method(r.getMethod()) 
{
}


/*--------------------------------------------------------------------------*/
/**
 */
HttpResponse::~HttpResponse()
{
}


/*--------------------------------------------------------------------------*/
/**
 */
void HttpResponse::discard() 
{
	if (m_InputStream != Nil) {
	    m_InputStream->discard();
	    m_InputStream = Nil;
	}
}


/*--------------------------------------------------------------------------*/
/**
 */
void HttpResponse::writeTo(OutputStream* out) const
{
	if (getVersion() == HttpVersion::Http_0_9)
        *out << "HTTP/0.9 ";
	else if (getVersion() == HttpVersion::Http_1_0)
        *out << "HTTP/1.0 ";
	else if (getVersion() == HttpVersion::Http_1_1)
        *out << "HTTP/1.1 ";
	else
        *out << "HTTP/1.0 ";
    *out << m_Status.toCString();
	
	getHeaders().writeTo(out);
}

} } }