void RTSPRequestInterface::AppendContentLength(UInt32 contentLength)
{
    if (!fStandardHeadersWritten)
        this->WriteStandardHeaders();

    char dataSize[10];
    dataSize[sizeof(dataSize) -1] = 0;
    qtss_snprintf(dataSize, sizeof(dataSize) -1, "%lu", contentLength);
    StrPtrLen contentLengthStr(dataSize);
    this->AppendHeader(qtssContentLengthHeader, &contentLengthStr);
    
}
	void HTTPClientBinding::ExecuteRequest()
	{
		// Begin the request
		try
		{
			for (int x = 0; x < this->GetInt("maxRedirects"); x++)
			{
				Poco::URI uri(this->url);

				// Prepare the HTTP session
				this->PrepareSession(uri);

				// Get request path
				std::string path(uri.getPathAndQuery());
				if (path.empty())
					path = "/";

				// Prepare the request
				Poco::Net::HTTPRequest request(this->method, path, Poco::Net::HTTPMessage::HTTP_1_1);
				request.set("User-Agent", this->GetString("userAgent").c_str());

				// Set cookies
				if (!this->requestCookies.empty())
					request.setCookies(this->requestCookies);

				// Apply basic authentication credentials
				basicCredentials.authenticate(request);

				// Set headers
				if (this->headers.size() > 0)
				{
					std::map<std::string, std::string>::iterator i = this->headers.begin();
					while (i != this->headers.end())
					{
						if (i->first.empty() || i->second.empty())
							continue;
						request.set(i->first, i->second);
						i++;
					}
				}

				// Set content length
				// FIXME: we should almost have a standard int -> string conversion
				// method that is re-useable else where in the code base.
				std::ostringstream contentLengthStr(std::ios::binary | std::ios::out);
				contentLengthStr << this->contentLength;
				request.set("Content-Length", contentLengthStr.str());

				// Send request and grab an output stream to send body
				std::ostream& out = session->sendRequest(request);

				// Output request body if we have data to send
				if (this->contentLength > 0)
					this->SendRequestBody(out);

				// Get the response
				std::istream& in = session->receiveResponse(this->response);
				int status = this->response.getStatus();
				int responseLength = this->response.getContentLength();

				// Handle redirects
				if (status == 301 || status == 302)
				{
					if (!this->response.has("Location"))
					{
						break;
					}
					this->url = this->response.get("Location");
					logger->Debug("redirect to %s", this->url.c_str());
					this->SetString("url", this->url);
					this->FireEvent(Event::HTTP_REDIRECT);
					continue;
				}

				// Get cookies from response
				this->GetCookies();

				// Set response status code and text
				this->Set("status", Value::NewInt(status));
				this->Set("statusText", Value::NewString(this->response.getReason().c_str()));

				this->ChangeState(2); // headers received
				this->ChangeState(3); // loading

				// Receive data from response
				if (responseLength > 0)
					this->ReceiveResponseBody(in, responseLength);

				this->FireEvent(Event::HTTP_DONE);
				break;
			}
		}
		catch (...)
		{
			// Timeout or IO error occurred
			logger->Debug("Timeout occurred");
			this->SetBool("timedOut", true);
			this->FireEvent(Event::HTTP_TIMEOUT);
		}

		// Destroy the session here, so that even if this HTTPClient isn't
		// garbage collected, the socket will close.
		this->session = 0;

		this->Set("connected", Value::NewBool(false));
		this->ChangeState(4); // closed
	}