////////////////////////////////////////////////////////////////////////// // CHttpHelper bool CHttpHelper::IsConnectionKeepAlive(NPT_HttpMessage& message) { const NPT_String* connection = message.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_CONNECTION); // the DLNA says that all HTTP 1.0 requests should be closed immediately by the server NPT_String protocol = message.GetProtocol(); if (protocol.Compare(NPT_HTTP_PROTOCOL_1_0, true) == 0) return false; // all HTTP 1.1 requests without a Connection header // or with a keep-alive Connection header should be kept alive if possible return (!connection || connection->Compare("keep-alive", true) == 0); }
/*---------------------------------------------------------------------- | PLT_HttpHelper::IsConnectionKeepAlive +---------------------------------------------------------------------*/ bool PLT_HttpHelper::IsConnectionKeepAlive(NPT_HttpMessage& message) { const NPT_String* connection = message.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_CONNECTION); // if we have the keep-alive header then no matter what protocol version, we want keep-alive // if we are in HTTP 1.1 and we don't have the keep-alive header, make sure we also don't have the Connection: close header. NPT_String protocol = message.GetProtocol(); if ((!protocol.Compare(NPT_HTTP_PROTOCOL_1_1, true) && (!connection || connection->Compare("Close", true))) || (connection && !connection->Compare("keep-alive", true))) { return true; } return false; }
/*---------------------------------------------------------------------- | PLT_HttpHelper::IsConnectionKeepAlive +---------------------------------------------------------------------*/ bool PLT_HttpHelper::IsConnectionKeepAlive(NPT_HttpMessage& message) { const NPT_String* connection = message.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_CONNECTION); // the DLNA says that all HTTP 1.0 requests should be closed immediately by the server // all HTTP 1.1 requests without a Connection header or with a Connection header // NOT saying "Close" should be kept alive NPT_String protocol = message.GetProtocol(); if (!protocol.Compare(NPT_HTTP_PROTOCOL_1_1, true) && (!connection || connection->Compare("close", true))) { return true; } return false; }
/*---------------------------------------------------------------------- | NPT_HttpMessage::SetBody +---------------------------------------------------------------------*/ NPT_Result PLT_HttpHelper::SetBody(NPT_HttpMessage& message, NPT_InputStreamReference stream, NPT_HttpEntity** entity /* = NULL */) { // get the entity NPT_HttpEntity* _entity = message.GetEntity(); if (_entity == NULL) { // no entity yet, create one message.SetEntity(_entity = new NPT_HttpEntity()); } if (entity) *entity =_entity; // set the entity body return _entity->SetInputStream(stream, true); }
/*---------------------------------------------------------------------- | NPT_HttpMessage::SetBody +---------------------------------------------------------------------*/ NPT_Result PLT_HttpHelper::SetBody(NPT_HttpMessage& message, NPT_InputStreamReference& stream, NPT_LargeSize len) { if (len == 0) { NPT_CHECK_SEVERE(stream->GetAvailable(len)); } // get the entity NPT_HttpEntity* entity = message.GetEntity(); if (entity == NULL) { // no entity yet, create one message.SetEntity(entity = new NPT_HttpEntity()); } // set the entity body entity->SetInputStream(stream); entity->SetContentLength(len); return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_HttpHelper::GetContentLength +---------------------------------------------------------------------*/ NPT_Result PLT_HttpHelper::GetContentLength(NPT_HttpMessage& message, NPT_LargeSize& len) { len = 0; const NPT_String* val = message.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_CONTENT_LENGTH); NPT_CHECK_POINTER(val); return val->ToInteger(len); }
/*---------------------------------------------------------------------- | PLT_HttpHelper::GetContentType +---------------------------------------------------------------------*/ NPT_Result PLT_HttpHelper::GetContentType(NPT_HttpMessage& message, NPT_String& type) { type = ""; const NPT_String* val = message.GetHeaders().GetHeaderValue(NPT_HTTP_HEADER_CONTENT_TYPE); NPT_CHECK_POINTER(val); type = *val; return NPT_SUCCESS; }
/*---------------------------------------------------------------------- | PLT_HttpHelper::IsBodyStreamSeekable +---------------------------------------------------------------------*/ bool PLT_HttpHelper::IsBodyStreamSeekable(NPT_HttpMessage& message) { NPT_HttpEntity* entity = message.GetEntity(); NPT_InputStreamReference stream; if (!entity || NPT_FAILED(entity->GetInputStream(stream))) return true; // try to get current position and seek there NPT_Position position; if (NPT_FAILED(stream->Tell(position)) || NPT_FAILED(stream->Seek(position))) { return false; } return true; }
/*---------------------------------------------------------------------- | PLT_HttpHelper::GetBody +---------------------------------------------------------------------*/ NPT_Result PLT_HttpHelper::GetBody(NPT_HttpMessage& message, NPT_String& body) { NPT_Result res; NPT_InputStreamReference stream; // get stream NPT_HttpEntity* entity = message.GetEntity(); if (!entity || NPT_FAILED(entity->GetInputStream(stream))) { return NPT_FAILURE; } // extract body NPT_StringOutputStream* output_stream = new NPT_StringOutputStream(&body); res = NPT_StreamToStreamCopy(*stream, *output_stream, 0, entity->GetContentLength()); delete output_stream; return res; }
/*---------------------------------------------------------------------- | PLT_HttpHelper::SetContentLength +---------------------------------------------------------------------*/ void PLT_HttpHelper::SetContentLength(NPT_HttpMessage& message, NPT_LargeSize len) { message.GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_LENGTH, NPT_String::FromIntegerU(len)); }
/*---------------------------------------------------------------------- | PLT_HttpHelper::SetContentType +---------------------------------------------------------------------*/ void PLT_HttpHelper::SetContentType(NPT_HttpMessage& message, const char* type) { message.GetHeaders().SetHeader(NPT_HTTP_HEADER_CONTENT_TYPE, type); }