Exemple #1
0
void HttpReply::finishedSlot()
{

   QString status(headerValue("Qchemserv-Status"));

qDebug() << "HttpReply finishedSlot called with header"; 
qDebug() << "-------------------------------------------------------------";
   dumpHeader();
qDebug() << "HttpReply finishedSlot called with message"; 
qDebug() << m_message;
qDebug() << "HttpReply finishedSlot called with status"; 
qDebug() << status;
qDebug() << "-------------------------------------------------------------";



   if (status.contains("OK")) {
      if (m_status != Error) m_status = m_interrupt ? Interrupted : Finished;
      if (m_message.isEmpty()) {
         QLOG_TRACE() << "HttpReply message empty, returning header";
         m_message = headerAsString(); 
      }
   }else if (status.contains("ERROR")) {
      m_status  = Error;
      m_message = headerValue("Qchemserv-Error");
   }else  {
      m_status  = Error;
      m_message = "QChem server temporarily unavailable";
   }

   finished();
}
Exemple #2
0
int onHeaderValue(http_parser *parser, const char *p,size_t len)
{
    QByteArray buffer(p,len);
    QSharedPointer<QString> headerValue(new QString(buffer));
    static_cast<TcpSocket*>(parser->data)->getHeader().addHeaderInfo(headerValue);
    return 0;
}
Exemple #3
0
std::size_t Message::contentLength() const
{
   std::string value = headerValue("Content-Length");
   if (value.empty())
      return 0;

   return safe_convert::stringTo<std::size_t>(value, 0);
}
Exemple #4
0
const char *HTTPRequest::envValue(const char *name) const
{
  if (strcmp(name, "CONTENT_TYPE") == 0) {
    return headerValue("Content-Type");
  } else if (strcmp(name, "CONTENT_LENGTH") == 0) {
    return headerValue("Content-Length");
  } else if (strcmp(name, "SERVER_SIGNATURE") == 0) {
    return "<address>Wt httpd server</address>";
  } else if (strcmp(name, "SERVER_SOFTWARE") == 0) {
    return "Wthttpd/" WT_VERSION_STR ;
  } else if (strcmp(name, "SERVER_ADMIN") == 0) {
    return "webmaster@localhost";
  } else if (strcmp(name, "REMOTE_ADDR") == 0) {
    return remoteAddr().c_str();
  } else if (strcmp(name, "DOCUMENT_ROOT") == 0) {
    return reply_->configuration().docRoot().c_str();
  } else
    return 0;
}
Exemple #5
0
std::string HTTPRequest::envValue(const std::string& name) const
{
  if (name == "CONTENT_TYPE") {
    return headerValue("Content-Type");
  } else if (name == "CONTENT_LENGTH") {
    return headerValue("Content-Length");
  } else if (name == "SERVER_SIGNATURE") {
    return "<address>Wt httpd Server ("
      + envValue("SERVER_SOFTWARE")
      + ")</address>";
  } else if (name == "SERVER_SOFTWARE") {
    return "Wthttpd/"
      + boost::lexical_cast<std::string>(WT_SERIES) + '.'
      + boost::lexical_cast<std::string>(WT_MAJOR) + '.'
      + boost::lexical_cast<std::string>(WT_MINOR);
  } else if (name == "SERVER_ADMIN") {
    return "webmaster@localhost"; // FIXME
  } else if (name == "REMOTE_ADDR") {
    return remoteAddr();
  } else if (name == "DOCUMENT_ROOT") {
    return reply_->configuration().docRoot();
  } else
    return std::string();
}
RHTTPTransaction CTestCase15::GetTransactionL(TInt aIndex, RHTTPSession aSession, MHTTPTransactionCallback& aClient)
	{
	__ASSERT_ALWAYS(aIndex<KTransactionCount, User::Invariant());
	
	RStringF method = aSession.StringPool().StringF(HTTP::EGET,RHTTPSession::GetTable());
	_LIT8(KTxtUri, "http://127.0.0.1");
	TUriParser8 uri; 
	uri.Parse(KTxtUri());
	
	// Buffer size needs to be reduced in the session property before the first transaction.
	if( aIndex == 0 )
		{
		RHTTPConnectionInfo connInfo = aSession.ConnectionInfo();
		connInfo.SetPropertyL(aSession.StringPool().StringF(HTTP::EBatchingBufferSize,RHTTPSession::GetTable()), KBufferSize);
		}
		
	// If this is the 2nd request add large amount of header data to make the request
	// larger than the buffer size
	if( aIndex == 2 )
		{
		// Add a fairly large header
		RHTTPTransaction trans = aSession.OpenTransactionL(uri, aClient, method);
		RHTTPHeaders headers = trans.Request().GetHeaderCollection();
		
		_LIT8(KTxtHeaderName, "This_Is_A_Long_Header_Name");
		_LIT8(KTxtHeaderValue, "This_Is_A_Long_Header_Value_abcdefghijklmnopqrstuvwxyz1234567890");
		RStringF headerStrName = aSession.StringPool().OpenFStringL(KTxtHeaderName());
		CleanupClosePushL(headerStrName);
		RStringF headerStrValue = aSession.StringPool().OpenFStringL(KTxtHeaderValue());
		CleanupClosePushL(headerStrValue);
		THTTPHdrVal headerValue(headerStrValue);
		headers.SetFieldL(headerStrName, headerValue);
		CleanupStack::PopAndDestroy(2, &headerStrName);
		
		return trans;
		}
		
	return aSession.OpenTransactionL(uri, aClient, method);
	}
Exemple #7
0
UString UHttpClient_Base::getBasicAuthorizationHeader()
{
   U_TRACE_NO_PARAM(0, "UHttpClient_Base::getBasicAuthorizationHeader()")

   UString headerValue(300U), tmp(100U), data(100U);

   // ---------------------------------------------------------------------------------------------------------------------------
   // According to RFC 2617 HTTP Authentication: Basic and Digest Access Authentication
   // ---------------------------------------------------------------------------------------------------------------------------
   // For "Basic" authentication, the user and password are concatentated with a colon separator before being encoded in base64.
   // According to RFC 2068 (HTTP/1.1) the Username and Password are defined as TEXT productions and are therefore supposed to be
   // encoded in ISO-8859-1 before being Base64-encoded
   // ---------------------------------------------------------------------------------------------------------------------------

   tmp.snprintf(U_CONSTANT_TO_PARAM("%v:%v"), user.rep, password.rep);

   UBase64::encode(tmp, data);

   // Authorization: Basic cy5jYXNhenphOnN0ZWZhbm8x

   headerValue.snprintf(U_CONSTANT_TO_PARAM("Basic %v"), data.rep);

   U_RETURN_STRING(headerValue);
}
Exemple #8
0
  bool
  ParseHeader(nsACString::const_iterator& aStart,
              nsACString::const_iterator& aEnd,
              bool* aWasEmptyHeader)
  {
    MOZ_ASSERT(aWasEmptyHeader);
    // Set it to a valid value here so we don't forget later.
    *aWasEmptyHeader = false;

    const char* beginning = aStart.get();
    nsACString::const_iterator end(aEnd);
    if (!FindCRLF(aStart, end)) {
      return false;
    }

    if (aStart.get() == beginning) {
      *aWasEmptyHeader = true;
      return true;
    }

    nsAutoCString header(beginning, aStart.get() - beginning);

    nsACString::const_iterator headerStart, headerEnd;
    header.BeginReading(headerStart);
    header.EndReading(headerEnd);
    if (!FindCharInReadable(':', headerStart, headerEnd)) {
      return false;
    }

    nsAutoCString headerName(StringHead(header, headerStart.size_backward()));
    headerName.CompressWhitespace();
    if (!NS_IsValidHTTPToken(headerName)) {
      return false;
    }

    nsAutoCString headerValue(Substring(++headerStart, headerEnd));
    if (!NS_IsReasonableHTTPHeaderValue(headerValue)) {
      return false;
    }
    headerValue.CompressWhitespace();

    if (headerName.LowerCaseEqualsLiteral("content-disposition")) {
      nsCCharSeparatedTokenizer tokenizer(headerValue, ';');
      bool seenFormData = false;
      while (tokenizer.hasMoreTokens()) {
        const nsDependentCSubstring& token = tokenizer.nextToken();
        if (token.IsEmpty()) {
          continue;
        }

        if (token.EqualsLiteral("form-data")) {
          seenFormData = true;
          continue;
        }

        if (seenFormData &&
            StringBeginsWith(token, NS_LITERAL_CSTRING("name="))) {
          mName = StringTail(token, token.Length() - 5);
          mName.Trim(" \"");
          continue;
        }

        if (seenFormData &&
            StringBeginsWith(token, NS_LITERAL_CSTRING("filename="))) {
          mFilename = StringTail(token, token.Length() - 9);
          mFilename.Trim(" \"");
          continue;
        }
      }

      if (mName.IsVoid()) {
        // Could not parse a valid entry name.
        return false;
      }
    } else if (headerName.LowerCaseEqualsLiteral("content-type")) {
      mContentType = headerValue;
    }

    return true;
  }
Exemple #9
0
const char *HTTPRequest::contentType() const
{
  return headerValue("Content-Type");
}
Exemple #10
0
std::size_t Message::contentLength() const
{
    return safe_convert::stringTo<std::size_t>(headerValue("Content-Length"), 0);
}
Exemple #11
0
std::string Message::contentType() const
{
    return headerValue("Content-Type") ;
}