示例#1
0
HttpHeader HttpHeader::Builder::build() const {
    std::string headerStr;

    switch (m_requestType) {
    case eRequestType::HTTP_REQUEST_GET: {
        headerStr += "GET ";
        headerStr += m_requestPath;
        headerStr += " HTTP/1.1\r\n";
        break;
    }
    case eRequestType::HTTP_REQUEST_POST: {
        headerStr += "POST ";
        headerStr += m_requestPath;
        headerStr += " HTTP/1.1\r\n";
        break;
    }
    case eRequestType::HTTP_RESPONSE: {
        headerStr += "HTTP/1.1 ";
        headerStr += StatusString(m_statusCode);
        headerStr += "\r\n";
        break;
    }

    case eRequestType::UNKNOWN: {
        return HttpHeader();
    }
    }

    headerStr += Joiner().on("\r\n").join(m_headers.begin(), m_headers.end());
    headerStr += "\r\n\r\n";

    HttpHeader rVal;
    rVal.parsePartial(core::memory::ConstBlob((u8 *) headerStr.c_str(), headerStr.length()));
    return rVal;
}
示例#2
0
bool ETagUrlChecker::check(HttpHeader& header, Url&url) {
    if (header.getEtag() == "")
        return false;
    if (header.getEtag() == url.getEtag())
        return false;
    return true;
}
示例#3
0
void fcyNet::SendGetRequest(Client* pClient, const string& Host, const string& Path)
{
	// 创建GET请求
	string tRequestGet = "GET ";
	tRequestGet += Path;
	tRequestGet += " HTTP/1.1\r\n";
	
	// 发送GET请求
	pClient->Send((fcData)&tRequestGet[0], tRequestGet.length());

	// 创建头
	HttpHeader tHeader;
	tHeader["Host"] = Host;
	tHeader["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
	tHeader["Accept-Language"] = "zh-cn,zh;q=0.5";
	tHeader["Accept-Encoding"] = "deflate;q=1.0,gzip;q=0.7";
	tHeader["Accept-Charset"] = "GB2312,utf-8;q=0.7,*;q=0.7";
	// tHeader["Connection"] = "keep-alive";
	// tHeader["Keep-Alive"] = "300";
	tHeader["Connection"] = "close";
	tHeader["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)"; 
	tHeader["Cache-Control"] = "no-cache";
	tHeader["Pragma"] = "no-cache";

	// 发送头
	tHeader.Send(pClient);
}
void RequestParameters::parseMultiPart(const MultiPart & multiPart)
{
    QList<QPair<QString, QVariant >> parameters;

    for (const Part & part : multiPart.getParts())
    {
        HttpHeader contentDisposition = part.getHeader(http::ContentDisposition);
        HttpHeaderElement element = contentDisposition.getElement();
        if (element.getName()=="form-data")
        {
            QString name = element.getParameter("name");
            if (part.hasHeader(http::ContentType))
            {
                UploadedFile uploadedFile;
                uploadedFile.setContent(part.getContent());
                if (element.isSet("filename"))
                {
                    uploadedFile.setFilename(element.getParameter("filename"));
                }
                parameters << QPair<QString, QVariant>(name, uploadedFile.toQVariant());
            }
            else
            {
                parameters << QPair<QString, QVariant>(name, QString(part.getContent()));
            }
        }
    }

    parseList(parameters);
}
示例#5
0
HttpRequest HttpRequest::Builder::build() const {
  const HttpHeader header = m_header.build();
  if (header.getRequestType() == HttpHeader::eRequestType::HTTP_REQUEST_GET) {
    ASSERT(m_body.size() == 0);
  }
  return HttpRequest(header, m_body);
}
示例#6
0
YETI_Result HttpEntity::set_headers(const HttpHeaders & headers)
{
    HttpHeader * header;
    header = headers.get_header(YETI_HTTP_HEADER_CONTENT_LENGTH);
    if (header != NULL) {
        m_content_length_is_known_ = true;
        YETI_LargeSize length;
        if (YETI_SUCCEEDED(header->get_value().to_integer64(length))) {
            m_content_length_ = length;
        } else {
            m_content_length_ = 0;
        }
    }

    header = headers.get_header(YETI_HTTP_HEADER_CONTENT_TYPE);
    if (header != NULL) {
        m_content_type_ = header->get_value();
    }

    header = headers.get_header(YETI_HTTP_HEADER_CONTENT_ENCODING);
    if (header != NULL) {
        m_content_encoding_ = header->get_value();
    }

    header = headers.get_header(YETI_HTTP_HEADER_TRANSFER_ENCODING);
    if (header != NULL) {
        m_transfer_encoding_ = header->get_value();
    }

    return YETI_SUCCESS;
}
示例#7
0
const String * HttpHeaders::get_header_value(const char * name) const
{
    HttpHeader * header = get_header(name);
    if (header == NULL) {
        return NULL;
    } else {
        return &header->get_value();
    }
}
示例#8
0
YETI_Result HttpHeaders::set_header(const char * name, const char * value, bool replace/* = true*/)
{
    HttpHeader * header = get_header(name);
    if (header == NULL) {
        return add_header(name, value);
    } else if (replace) {
        return header->set_value(value);
    } else  {
        return YETI_SUCCESS;
    }
}
示例#9
0
文件: test.cpp 项目: skiloop/wmtor
void testGetWebPage(Url&url) {

    HttpClient client;
    HttpHeader httpheader;
    HttpContent httpcontent;
    client.requestWebPage(url, httpheader, httpcontent);
    //string header;
    //client.requestHeader(url,header);
    //cout<<header<<endl;
    cout << httpheader.getHeaderStr() << endl;
}
示例#10
0
void HttpRequest::parseHeader(const HttpHeader& header) {
	addHeader(header);
	QString headerName = header.getName();
	QString value = header.getValue();
	if (headerName==http::Host) {
		url.setAuthority(value);
	} else if (headerName==http::Cookie) {
		cookies.parse(value);
	} else if (headerName==http::ContentType) {
		contentType.parse(value);
	}
}
示例#11
0
void Chatting::OnTransactionReadyToRead(
		Tizen::Net::Http::HttpSession& httpSession,
		Tizen::Net::Http::HttpTransaction& httpTransaction,
		int availableBodyLen) {
	AppLog("OnTransactionReadyToRead");

	HttpResponse* pHttpResponse = httpTransaction.GetResponse();
	if (pHttpResponse->GetHttpStatusCode() == HTTP_STATUS_OK) {
		HttpHeader* pHttpHeader = pHttpResponse->GetHeader();
		if (pHttpHeader != null) {
			String* tempHeaderString = pHttpHeader->GetRawHeaderN();
			ByteBuffer* pBuffer = pHttpResponse->ReadBodyN();
			AppLog((const char*)pBuffer->GetPointer());
			String str((const char*) (pBuffer->GetPointer()));

//			IJsonValue* pJson = JsonParser::ParseN(*pBuffer);
//
//			JsonObject *pObject = static_cast<JsonObject*>(pJson);
//
//			   JsonString *userName = new JsonString("username");
//			   IJsonValue *pValName = null;
//
//			   JsonString *dates = new JsonString("date");
//			   IJsonValue *pValDate = null;
//
//
//			   pObject->GetValue(userName, pValName);
//			   pObject->GetValue(dates,pValDate);
//
//
//			   JsonString* pName = static_cast<JsonString*>(pValName);
//			   JsonString* pDate= static_cast<JsonString*>(pValDate);
//
//			   String text(L"이름: ");
//			   text.Append(*pName);
//			   text.Append("\n날짜: ");
//			   text.Append(*pDate);

//	String text(str);
//	text.Append(availableBodyLen);

//	__pEditArea->SetText(text);

			Draw();

			delete tempHeaderString;
			delete pBuffer;
		}
	}
}
示例#12
0
int HttpClient::requestHeader(Url &url, HttpHeader &header) {
    string headStr;
    int ret = requestHeader(url, headStr);
    header.setHeaderStr(headStr);
    return ret;

}
void HttpProtocol::parseHeader(string& str,HttpHeader& http)
{
	int i=0;
	vector<string> p;
	split(str,":",p);
	http.set(p[0],p[1]);		
}
示例#14
0
void
UserProfileForm::OnTransactionHeaderCompleted(HttpSession& httpSession, HttpTransaction& httpTransaction, int headerLen, bool rs)
{

	HttpResponse* pHttpResponse = httpTransaction.GetResponse();
	if(pHttpResponse == null)
		return;
	HttpHeader* pHttpHeader = pHttpResponse->GetHeader();
	if(pHttpHeader != null)
	{
		String* tempHeaderString = pHttpHeader->GetRawHeaderN();
		AppLog("HeaderString=%ls\n",tempHeaderString->GetPointer());
	}

	AppLog("OnTransactionHeaderCompleted\n");
}
示例#15
0
void
HttpResponse::VisitHeaders (HttpHeaderVisitor visitor, void *context)
{
    HttpHeader *header;

    VERIFY_MAIN_THREAD;

    if (headers == NULL)
        return;

    header = (HttpHeader *) headers->First ();
    while (header != NULL) {
        visitor (context, header->GetHeader (), header->GetValue ());
        header = (HttpHeader *) header->next;
    }
}
示例#16
0
bool
HttpResponse::ContainsHeader (const char *header, const char *value)
{
    HttpHeader *node;

    if (headers == NULL)
        return false;

    node = (HttpHeader *) headers->First ();
    while (node != NULL) {
        if (!strcmp (node->GetHeader (), header) && !strcmp (node->GetValue (), value))
            return true;
        node = (HttpHeader *) node->next;
    }

    return false;
}
示例#17
0
static void Server(String r)
{
	TcpSocket   server;
	if(server.Listen(4000, 10)) {

		TcpSocket socket;
		LOG("Waiting...");
		bool b = socket.Accept(server);
		if(b) {
			LOG("Connection accepted");
			HttpHeader http;
			http.Read(socket);
			socket.Put(r);
			socket.Close();
		}
	}
}
void HttpHeaderCollection::AddHeader(HttpHeader httpHeader)
{
    if (this->IsHeaderPresent(httpHeader.GetHeaderName()))
    {
        throw exception::http::http_header_already_present();
    }

    this->m_headers.push_back(httpHeader);
}
void HttpProtocol::geneHeader(std::string& str,const HttpHeader& http)
{
	map<string,string> m;
	http.get(m);
	map<string,string>::iterator it = m.begin();
	for(;it != m.end(); it++)
		str = str+(*it).first + ":" + (*it).second + "\n";
	str+="\n";
}
示例#20
0
void wmtor::CheckUrl_wholePage(Url &url, HttpClient&cli, ofstream &ofile) {
    HttpHeader header;
    HttpContent content;
    cli.requestWebPage(url, header, content);
    ofile << "url:" << url.getUrlStr() << endl;
    ofile << "header:" << header.getHeaderStr() << endl;
    cout << "url:" << url.getUrlStr() << endl;
    cout << "urlEtag:" << header.getEtag() << endl;
    string contentMD5 = content.getMD5Str();

    if ( !contentMD5.empty() && contentMD5 != url.getPageMD5Str()) {
        url.setEtag(header.getEtag());
        url.setAge(0);
        url.setPageMD5Str(contentMD5);
        saveNewPage(url,content, header);
        reportNewWebPage(url);
    }
}
/**
*  @brief
*    A HTTP request has been received
*/
void HttpServerConnection::OnHttpRequest(const HttpHeader &cHttpHeader)
{
	// [DEBUG]
//	cHttpHeader.Print();

	// Perform HTTP request
	if (cHttpHeader.GetMessageType() == HttpRequest)
		m_pServer->OnRequest(this, &cHttpHeader);
}
示例#22
0
HttpOtpPostLogin::HttpOtpPostLogin(const char* buf, unsigned len, const UString& user_field,
                                   const UString& pin_field, const UString& token_field, const UString& passwd_field,
                                   const UString& cf_field, HttpHeader& header)
{
   U_TRACE(5, "HttpOtpPostLogin::HttpOtpPostLogin(%.*S,%u,%.*S,%.*S,%.*S,%.*S,%p)", len, buf, len,
                     U_STRING_TO_TRACE(user_field), U_STRING_TO_TRACE(pin_field), U_STRING_TO_TRACE(token_field),
                     U_STRING_TO_TRACE(passwd_field), U_STRING_TO_TRACE(cf_field), &header)

   HttpField* f = header.find(U_STRING_FROM_CONSTANT("Content-Type"));

   U_INTERNAL_ASSERT_POINTER(f)

   U_INTERNAL_ASSERT(f->value.find("application/x-www-form-urlencoded") != unsigned(-1))

   buffer.assign(buf, len);

   (void) U_VEC_SPLIT(vec, buffer, "=&"); // "user=stefano+casazza&pin=12345&token=autorizzativo"

   unsigned i = 0;

   while (i < vec.size())
      {
      if (vec[i] == user_field)
         {
         U_STR_RESERVE(user, 64);

         Url::decode(vec[i+1], user);
         }
      else if (vec[i] == pin_field)
         {
         U_STR_RESERVE(pin, 64);

         Url::decode(vec[i+1], pin);
         }
      else if (vec[i] == token_field)
         {
         U_STR_RESERVE(token, 64);

         Url::decode(vec[i+1], token);
         }
      else if (vec[i] == passwd_field)
         {
         U_STR_RESERVE(passwd, 64);

         Url::decode(vec[i+1], passwd);
         }
      else if (vec[i] == cf_field)
         {
         U_STR_RESERVE(cf, 64);

         Url::decode(vec[i+1], cf);
         }

      i += 2;
      }
}
示例#23
0
void HttpEntity::setHeader(const HttpHeader& header, bool merge) {
	QList<HttpHeader>& list = headers[header.getName()];
	if (list.isEmpty()) {
		list << header;
	} else {
		if (merge) {
			list.first().merge(header);
		} else {
			list[0] = header;
		}
	}
}
示例#24
0
		Buffer HttpMessage::ToBuffer(const HttpLine& _line, const HttpHeader& _header, const Buffer& _content)
		{
			string line = _line.ToString();
			string header = _header.ToString();

			Buffer buffer(line.length() + header.length() + 1 + _content.Length()); // +1 for the extra '\n'.
			memcpy(buffer.Field(), line.c_str(), line.length());
			memcpy(buffer.Field() + line.length(), header.c_str(), header.length());
			buffer.Field()[line.length() + header.length()] = '\n';
			memcpy(buffer.Field() + line.length() + header.length() + 1, _content.Field(), _content.Length());
			return buffer;
		}
示例#25
0
void HttpResponse::sendResponse() {
	if(this->_code != NULL) {
		char* outBuf = new char[1024];
		memset(outBuf, '\0', sizeof(outBuf));
		strcat(outBuf, this->_code);
		strcat(outBuf, "\r\n");
		for(int i=0; i<this->_headers->count(); i++) {
			HttpHeader* header = this->_headers->get(i);
			strcat(outBuf, header->key());
			strcat(outBuf, ": ");
			strcat(outBuf, header->value());
			strcat(outBuf, "\r\n");
		}
		if(this->_body != NULL) {
			strcat(outBuf, "\r\n");
			strcat(outBuf, this->_body);
		}
		strcat(outBuf, "\r\n");
		Serial.println(outBuf);
		this->_socket->write((uint8_t*)outBuf, strlen(outBuf));
		delete outBuf;
	}
}
示例#26
0
int wmtor::savePage(HttpContent &content, HttpHeader &header) {
    try {
        ofstream headerFile("header.txt", ios::app);
        ofstream contentFile("content.txt", ios::app);
        if (headerFile.is_open() && contentFile.is_open()) {
            headerFile << header.getHeaderStr() << endl;
            contentFile << content.getContentStr() << endl;
        }
        if (headerFile.is_open())headerFile.close();
        if (contentFile.is_open())contentFile.close();
        return 0;
    } catch (exception* e) {
        cerr << e->what() << endl;
        return -1;
    }
}
示例#27
0
void wmtor::CheckUrl(Url &url, HttpClient&cli, ofstream &ofile) {
    HttpHeader header;
    cli.requestHeader(url, header);
    ofile << "url:" << url.getUrlStr() << endl;
    ofile << "header:" << header.getHeaderStr() << endl;
    cout << "url:" << url.getUrlStr() << endl;
    cout << "urlEtag:" << header.getEtag() << endl;
    if (header.getEtag() != "") {
        if (header.getEtag() != url.getEtag()) {
            HttpContent content;
            cli.requestContent(url, content, header.getContentLength());
            string contentMD5 = content.getMD5Str();
            url.setEtag(header.getEtag());
            url.setAge(header.getAge());
            url.setPageMD5Str(contentMD5);
            savePage(content, header);
            reportNewWebPage(url);
        }
    } else {
    }
}
示例#28
0
文件: http.cpp 项目: kitech/mwget
bool http_file_valid( KSocket *csock ,URL * furl , long * size  ) 
{
	bool dret ;
	char rbuff[1024] = {0};
	char *pos = rbuff ;
	char *s = 0 ;
		HttpHeader header;
		header.AddHeader( "GET", furl->GetPath());
		header.AddHeader( "Host", furl->GetHost());
		header.AddHeader( "Connection", "Close");

		char range[50] = {0};
		sprintf(range,"bytes=%ld-", *size);
		header.AddHeader( "Range",range);
		std::string hs = header.HeaderString() ;
		csock->Write(hs.c_str(), hs.length());
		
		int rlen = 0 ;		
		do
		{
			rlen = csock->Peek(rbuff + rlen  , sizeof(rbuff) );
			if( ( s = strstr(rbuff ,"\r\n\r\n") ) != 0 )
			{
				*size = s - rbuff + 4 ;
				break ;
			}
			
		}while(true);
		
		header.ClearHeaders();
		header.Parse(rbuff);

		if( header.GetHeader( "Status" ) .compare("200") < 0 
			|| header.GetHeader( "Status" ) .compare("300") >= 0 ) 
		{
			fprintf(stderr,"Header status (%d)  \n",header.GetHeader( "Status" ).c_str() );
			*size = 0 ;
			return false ;
		}

		//read head now , really data 
		memset(rbuff,0,sizeof(rbuff));
		csock->Read(rbuff , *size ) ;
		//fprintf(stderr,"Header (%ld)  is %s \n", *size ,rbuff);

		*size = atol(header.GetHeader( "Content-Length" ).c_str());
		
	dret = true ;
	
	return dret ; 
	
}
示例#29
0
int
U_EXPORT main (int argc, char* argv[])
{
   U_ULIB_INIT(argv);

   U_TRACE(5,"main(%d)",argc)

   UString value, path, domain, port, not_found;

   HttpCookie c1(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM("Name=value")),
              c2(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_2)),
              c5(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_5));

   U_ASSERT( c5.find(U_STRING_FROM_CONSTANT("otptoken"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("pluto") )

   U_ASSERT( c1.count(U_STRING_FROM_CONSTANT("Name"))    == 1 )
   U_ASSERT( c2.count(U_STRING_FROM_CONSTANT("$Domain")) == 2 )

   U_ASSERT( c1.find(U_STRING_FROM_CONSTANT("Name"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("value") )
   U_ASSERT( path    == not_found )
   U_ASSERT( domain  == not_found )
   U_ASSERT( port    == not_found )

   U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("NameB"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("ValueB") )
   U_ASSERT( domain  == U_STRING_FROM_CONSTANT("domain1") )
   U_ASSERT( port    == not_found )

#ifdef SERGIO
   U_ASSERT( path    == U_STRING_FROM_CONSTANT("/") )
#else
   U_ASSERT( path    == U_STRING_FROM_CONSTANT("\"/\"") )
#endif

   U_ASSERT( c2.del(U_STRING_FROM_CONSTANT("NameB")) == true )

   value = path = domain = port = not_found;

   U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("Name"), value, path, domain, port)  == false )
   U_ASSERT( value   == not_found )
   U_ASSERT( path    == not_found )
   U_ASSERT( domain  == not_found )
   U_ASSERT( port    == not_found )

   U_ASSERT( c2.find(U_STRING_FROM_CONSTANT("NameC"), value, path, domain, port)  == true )
   U_ASSERT( value   == U_STRING_FROM_CONSTANT("ValueC") )
   U_ASSERT( path    == U_STRING_FROM_CONSTANT("domain1") )

#ifdef SERGIO
   U_ASSERT( port    == U_STRING_FROM_CONSTANT("123") )
   U_ASSERT( domain  == U_STRING_FROM_CONSTANT("/") )
#else
   U_ASSERT( port    == U_STRING_FROM_CONSTANT("\"123\"") )
   U_ASSERT( domain  == U_STRING_FROM_CONSTANT("\"/\"") )
#endif

   HttpSetCookie s1(U_CONSTANT_TO_PARAM("Set-Cookie"),  U_CONSTANT_TO_PARAM(SETCOOKIE_1)),
                 s2(U_CONSTANT_TO_PARAM("Set-Cookie2"), U_CONSTANT_TO_PARAM(SETCOOKIE_2));

   U_ASSERT( s1.count(U_STRING_FROM_CONSTANT("Domain"))  == 2 )
   U_ASSERT( s2.count(U_STRING_FROM_CONSTANT("Port"))    == 1 )

   HttpCookie c3(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_AUTH) );

   U_ASSERT( c3.count(U_STRING_FROM_CONSTANT("AUTHTOKEN")) == 1 )

   value = path = domain = port = not_found;

   U_ASSERT( c3.find(U_STRING_FROM_CONSTANT("AUTHTOKEN"), value, path, domain, port)  == true )

   U_ASSERT( path    == not_found )
   U_ASSERT( domain  == not_found )
   U_ASSERT( port    == not_found )

   value.erase(value.size()-1, 1);
   value.erase(0, 1);

#ifdef U_PROXY_UNIT
   DES3engine eng("pippo");
   OtpAuthToken a(&eng, value);
#else
   u_des3_key("pippo");
   OtpAuthToken a(0, value);
#endif

   U_ASSERT( a.tid     == U_STRING_FROM_CONSTANT("Current_Server_ID") )
   U_ASSERT( a.uid     == U_STRING_FROM_CONSTANT("User_ID") )
   U_ASSERT( a.sid     == U_STRING_FROM_CONSTANT("Session_ID") )
   U_ASSERT( a.ts      == U_STRING_FROM_CONSTANT("20031125131800") )
   U_ASSERT( a.cf      == U_STRING_FROM_CONSTANT("codicefiscale1") )
   U_ASSERT( a.migrate == true )

   HttpHeader h;
   HttpField* f = new HttpField(U_STRING_FROM_CONSTANT("Content-Type"), U_STRING_FROM_CONSTANT(" application/x-www-form-urlencoded"));
   HttpBaAuthorization* ba = new HttpBaAuthorization(U_CONSTANT_TO_PARAM("Authorization"),
                                                     U_CONSTANT_TO_PARAM(" Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="));
   HttpBaAuthorization* ba1 = new HttpBaAuthorization(U_CONSTANT_TO_PARAM("Authorization"),
                                                      U_CONSTANT_TO_PARAM(" Basic dXRlbnRlMTpzaWQx"));

   h.add(ba);
   h.add(f);
   h.add(ba1);

   HttpOtpPostLogin p(U_CONSTANT_TO_PARAM(POST_BODY), U_STRING_FROM_CONSTANT("user"),
                                                    U_STRING_FROM_CONSTANT("pin"),
                                                    U_STRING_FROM_CONSTANT("token"),
                                                    U_STRING_FROM_CONSTANT("password"),
                                                    U_STRING_FROM_CONSTANT("cf"), h);

   U_ASSERT( p.user  == U_STRING_FROM_CONSTANT("stefano casazza") )
   U_ASSERT( p.pin   == U_STRING_FROM_CONSTANT("12345") )
   U_ASSERT( p.token == U_STRING_FROM_CONSTANT("autorizzativo") )

   HttpField* p1 = h.del(U_STRING_FROM_CONSTANT("Content-Type"));

   U_ASSERT( p1 !=  0 )
   U_ASSERT( p1 == f )

   HttpBaAuthorization* p2 = (HttpBaAuthorization*) h.find(U_STRING_FROM_CONSTANT("Authorization"));

   U_ASSERT( p2 !=  0 )
   U_ASSERT( p2 == ba )

   U_ASSERT( p2->user   == U_STRING_FROM_CONSTANT("Aladdin") )
   U_ASSERT( p2->passwd == U_STRING_FROM_CONSTANT("open sesame") )

   HttpBaAuthorization* p3 = (HttpBaAuthorization*) h.find(U_STRING_FROM_CONSTANT("Authorization"), 1);

   U_ASSERT( p3 !=  0 )
   U_ASSERT( p3 == ba1 )

   U_ASSERT( p3->user   == U_STRING_FROM_CONSTANT("utente1") )
   U_ASSERT( p3->passwd == U_STRING_FROM_CONSTANT("sid1") )

   h.clear();

   UString result;

   a.stringify(result);

// TID=trustACCESS1;UID=utente1;SID=;TS=20031201174127;CF=codicefiscale1
#  define COOKIE_AUTH_1 \
"U2FsdGVkX1/QsrBvmsVHx0rrX78ldh6IJu1+4GhKoJ9O5ETSbfSiDip1gszkZX7w5ah6vkYfRWI8271LcNKhUsZVehRoscudLO8uotQgeiiF1B46ITphGw=="

// TID=trustACCESS1;UID=utente1;SID=sid;TS=20031201174127;CF=codicefiscale1;HP1=Profile_Header1;HPn=Profile_Headern;MIGRATE
#  define COOKIE_AUTH_2 \
"U2FsdGVkX1+tUkpPi14NVlKhm5KUFbSH0JFvi23+8B75MnKgtyD/sc0hc0ESmSahiYozVbS6a3OoZfWDHX3G3zuUwCP7n1+3jXK0wu6niifYUW+cKBk1WUdpJZd0xjJernDsWtPfq9j30uatAhHULG57vdrKlbtxM/EIaiaUow1AeLuDiZDcTRonghpI/aaz"

#ifdef U_PROXY_UNIT
   DES3engine eng1("password");
   OtpAuthToken c(&eng1, U_STRING_FROM_CONSTANT(COOKIE_AUTH_2));
   DES3engine eng2("password");
   OtpAuthToken b(&eng2, U_STRING_FROM_CONSTANT(COOKIE_AUTH_1));
#else
   u_des3_key("password");
   OtpAuthToken c(0, U_STRING_FROM_CONSTANT(COOKIE_AUTH_2));
   u_des3_reset();
   OtpAuthToken b(0, U_STRING_FROM_CONSTANT(COOKIE_AUTH_1));
#endif

   U_ASSERT( b.is_valid() == false )
   U_ASSERT( c.is_valid() == true )

   U_ASSERT( c.tid     == U_STRING_FROM_CONSTANT("trustACCESS1") )
   U_ASSERT( c.uid     == U_STRING_FROM_CONSTANT("utente1") )
   U_ASSERT( c.sid     == U_STRING_FROM_CONSTANT("sid") )
   U_ASSERT( c.ts      == U_STRING_FROM_CONSTANT("20031201174127") )
   U_ASSERT( c.cf      == U_STRING_FROM_CONSTANT("codicefiscale1") )
   U_ASSERT( c.migrate == true )

   value = not_found;

   U_ASSERT( c.find(U_STRING_FROM_CONSTANT("HP1"), value)  == true )
   U_ASSERT( value == U_STRING_FROM_CONSTANT("Profile_Header1") )

   U_ASSERT( c.del(U_STRING_FROM_CONSTANT("HP1"))  == true )

   value = not_found;

   U_ASSERT( c.find(U_STRING_FROM_CONSTANT("HPn"), value)  == true )
   U_ASSERT( value == U_STRING_FROM_CONSTANT("Profile_Headern") )

   HttpCookie c4(U_CONSTANT_TO_PARAM("Cookie"), U_CONSTANT_TO_PARAM(COOKIE_PROBLEM) );

   U_ASSERT( c4.count(U_STRING_FROM_CONSTANT("otptoken")) == 1 )

   value = path = domain = port = not_found;

   U_ASSERT( c4.find(U_STRING_FROM_CONSTANT("otptoken"), value, path, domain, port) == true )

   value.erase(value.size()-1, 1);
   value.erase(0, 1);

#ifdef U_PROXY_UNIT
   DES3engine eng3("password");
   OtpAuthToken d(&eng3, value);
#else
   u_des3_reset();
   OtpAuthToken d(0, value);
#endif

   U_ASSERT( d.is_valid() == false )

   result.erase(result.size()-1, 1);
   result.erase(0, 1);

   cout.write(result.data(), result.size());
}
示例#30
0
文件: http.cpp 项目: kitech/mwget
bool HttpRetriever::TaskValid(  long bsize    )
{
	KSocket *csock = this->mCtrlSock ;
	KSocket *dsock = this->mTranSock ;
	
	URL * furl = this->mUrl ;
	
	long * size = & bsize ;
	
	bool dret ;
	char rbuff[1024] = {0};
	char *pos = rbuff ;
	char *s = 0 ;
	char range[50] = {0};
	
		HttpHeader header;

		//fprintf(stderr , " GET %s \n" ,furl->GetPath());
		header.AddHeader( "GET", furl->GetFullPath() );
		header.AddHeader( "Host", furl->GetHost());
		header.AddHeader( "Connection", "Close");

		//header.Dump() ;
		
		sprintf(range,"bytes=%ld-", *size);
		header.AddHeader( "Range",range);
		std::string hs = header.HeaderString() ;
		csock->Write(hs.c_str(), hs.length());		

		fprintf(stderr , "%s" , hs.c_str());
		
		int rlen = 0 ;		
		do
		{
			
			rlen = csock->Peek(rbuff + rlen  , sizeof(rbuff) );
			fprintf(stderr, "Peeking %s \n" , rbuff );
			if( rlen <= 0 ) break ;
			if( ( s = strstr(rbuff ,"\r\n\r\n") ) != 0 )
			{
				*size = s - rbuff + 4 ;
				break ;
			}
			
		}while(true);
		
		header.ClearHeaders();
		header.Parse(rbuff);

		//header.Dump() ;
		std::string status = header.GetHeader( "Status" ) ;
		
		if ( status.compare("400") < 0 && status.compare("300") >= 0  ) 
		{
			//if follow into the redirector url
			//rewrite url
			//now this function lack test, i think i cant work correct
			fprintf(stderr , "400 Redirect Signal found\n");
			return false ;
		}
		else if ( status.compare("300") < 0 && status.compare("200") >= 0  ) 
		{
			//normal response
		}
		else //if( status.compare("200") < 0 || status.compare("400") >= 0 ) 
		{
			fprintf(stderr,"Header status (%s)  \n",header.GetHeader( "Status" ).c_str() );

			*size = 0 ;
			return false ;
		}		

		//read head now , really data 
		memset(rbuff,0,sizeof(rbuff));
		csock->Read(rbuff , *size ) ;
		//fprintf(stderr,"Header (%ld)  is %s \n", *size ,rbuff);

				
		*size = atol(header.GetHeader( "Content-Length" ).c_str());
	this->mContentLength = * size ;
		
	dsock->SetSocket(csock) ;
		
	dret = true ;
	
	return dret ; 
	return false ;
}