コード例 #1
0
NS_IMETHODIMP
HttpBaseChannel::ExplicitSetUploadStream(nsIInputStream *aStream,
                                       const nsACString &aContentType,
                                       int64_t aContentLength,
                                       const nsACString &aMethod,
                                       bool aStreamHasHeaders)
{
  // Ensure stream is set and method is valid 
  NS_ENSURE_TRUE(aStream, NS_ERROR_FAILURE);

  if (aContentLength < 0 && !aStreamHasHeaders) {
    nsresult rv = aStream->Available(reinterpret_cast<uint64_t*>(&aContentLength));
    if (NS_FAILED(rv) || aContentLength < 0) {
      NS_ERROR("unable to determine content length");
      return NS_ERROR_FAILURE;
    }
  }

  nsresult rv = SetRequestMethod(aMethod);
  NS_ENSURE_SUCCESS(rv, rv);

  if (!aStreamHasHeaders) {
    // SetRequestHeader propagates headers to chrome if HttpChannelChild 
    nsAutoCString contentLengthStr;
    contentLengthStr.AppendInt(aContentLength);
    SetRequestHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthStr, 
                     false);
    SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), aContentType, 
                     false);
  }

  mUploadStreamHasHeaders = aStreamHasHeaders;
  mUploadStream = aStream;
  return NS_OK;
}
コード例 #2
0
ファイル: networking.cpp プロジェクト: N00bKefka/MoSync
int RtspConnection::sendAndVerify(int method) {
	setMethod(method);
	SetRequestHeader("CSeq", intToString(CSeq));

	if(gotSessionId) {
		SetRequestHeader("Session", sessionId);
	}

	if(finish()<0) return CONNERR_GENERIC;
	const std::string *cseqStr = GetResponseHeader("CSeq");
	if(!cseqStr) return CONNERR_GENERIC;
	int recvCSeq = atoi(cseqStr->c_str());
	if(recvCSeq != CSeq) return CONNERR_GENERIC;

	const std::string *recvSessionId = GetResponseHeader("Session");
	if(recvSessionId) {
		std::string temp = *recvSessionId + ";";
		if(gotSessionId) {
			if(temp != sessionId) {
				return CONNERR_GENERIC;
			}
		} else {
			gotSessionId = true;
			sessionId = temp;
		}
	}

	return 0;
}
コード例 #3
0
CopyObjectRequest::CopyObjectRequest(const std::string &bucket_name, const std::string &object_name, const std::string &source_bucket_name, const std::string &source_object_name) :
    ObjectRequest(bucket_name, object_name, kHttpPut) {
    m_source_bucket_name = source_bucket_name;
    m_source_object_name = source_object_name;

    Log::PrintLog(DEBUG, TRACE, "add source bucket name , " + source_bucket_name);
    Log::PrintLog(DEBUG, TRACE, "add source object name , " + source_object_name);

    std::stringstream ss;
    ss<<"/"<<source_bucket_name<<"/"<<source_object_name;
    SetRequestHeader("x-bce-copy-source",ss.str());
    SetRequestHeader("Content-Length","0");
    SetRequestHeader("Content-Type","text/plain"); 
}
コード例 #4
0
void
HttpBaseChannel::AddCookiesToRequest()
{
  if (mLoadFlags & LOAD_ANONYMOUS) {
    return;
  }

  bool useCookieService = 
    (XRE_GetProcessType() == GeckoProcessType_Default);
  nsXPIDLCString cookie;
  if (useCookieService) {
    nsICookieService *cs = gHttpHandler->GetCookieService();
    if (cs) {
      cs->GetCookieStringFromHttp(mURI,
                                  nsnull,
                                  this, getter_Copies(cookie));
    }

    if (cookie.IsEmpty()) {
      cookie = mUserSetCookieHeader;
    }
    else if (!mUserSetCookieHeader.IsEmpty()) {
      cookie.Append(NS_LITERAL_CSTRING("; ") + mUserSetCookieHeader);
    }
  }
  else {
    cookie = mUserSetCookieHeader;
  }

  // If we are in the child process, we want the parent seeing any
  // cookie headers that might have been set by SetRequestHeader()
  SetRequestHeader(nsDependentCString(nsHttp::Cookie), cookie, false);
}
コード例 #5
0
NS_IMETHODIMP
nsViewSourceChannel::SetRequestHeader(const nsACString & aHeader,
                                      const nsACString & aValue,
                                      bool aMerge)
{
    return !mHttpChannel ? NS_ERROR_NULL_POINTER :
        mHttpChannel->SetRequestHeader(aHeader, aValue, aMerge);
}
コード例 #6
0
NS_IMETHODIMP
HttpBaseChannel::SetUploadStream(nsIInputStream *stream,
                               const nsACString &contentType,
                               PRInt32 contentLength)
{
  // NOTE: for backwards compatibility and for compatibility with old style
  // plugins, |stream| may include headers, specifically Content-Type and
  // Content-Length headers.  in this case, |contentType| and |contentLength|
  // would be unspecified.  this is traditionally the case of a POST request,
  // and so we select POST as the request method if contentType and
  // contentLength are unspecified.

  if (stream) {
    if (contentType.IsEmpty()) {
      mUploadStreamHasHeaders = true;
      mRequestHead.SetMethod(nsHttp::Post); // POST request
    } else {
      if (contentLength < 0) {
        // Not really kosher to assume Available == total length of
        // stream, but apparently works for the streams we see here.
        stream->Available((PRUint32 *) &contentLength);
        if (contentLength < 0) {
          NS_ERROR("unable to determine content length");
          return NS_ERROR_FAILURE;
        }
      }
      // SetRequestHeader propagates headers to chrome if HttpChannelChild 
      nsCAutoString contentLengthStr;
      contentLengthStr.AppendInt(PRInt64(contentLength));
      SetRequestHeader(NS_LITERAL_CSTRING("Content-Length"), contentLengthStr, 
                       false);
      SetRequestHeader(NS_LITERAL_CSTRING("Content-Type"), contentType, 
                       false);
      mUploadStreamHasHeaders = false;
      mRequestHead.SetMethod(nsHttp::Put); // PUT request
    }
  } else {
    mUploadStreamHasHeaders = false;
    mRequestHead.SetMethod(nsHttp::Get); // revert to GET request
  }
  mUploadStream = stream;
  return NS_OK;
}
コード例 #7
0
int CopyObjectRequest::AddCopyMetaDataDirective(const std::string &directive) {
    if(directive == "replace" || directive == "copy") {
        SetRequestHeader("x-bce-copy-metadata-directive", directive);
        return 0;
    }

    Log::PrintLog(ERROR, TRACE, "add copy meta data directive fail!");
    return kBosIllegalArgument;

}
コード例 #8
0
int CopyObjectRequest::AddCopySourceIfMatch(const std::string &etag) {
    SetRequestHeader("x-bce-copy-source-if-match", etag);
    return 0;
}