Beispiel #1
0
        public override void SetAuth(HttpWebRequest request, Stream body)
        {
            string pathAndQuery = request.Address.PathAndQuery;

            byte[] pathAndQueryBytes = Config.Encoding.GetBytes(pathAndQuery);
            using (MemoryStream buffer = new MemoryStream()) {
                string digestBase64 = null;
                if (request.ContentType == "application/x-www-form-urlencoded" && body != null)
                {
                    if (!body.CanSeek)
                    {
                        throw new Exception("stream can not seek");
                    }
                    Util.IO.Copy(buffer, body);
                    digestBase64 = SignRequest(request, buffer.ToArray());
                }
                else
                {
                    buffer.Write(pathAndQueryBytes, 0, pathAndQueryBytes.Length);
                    buffer.WriteByte((byte)'\n');
                    digestBase64 = mac.Sign(buffer.ToArray());
                }
                string authHead = "QBox " + digestBase64;
                request.Headers.Add("Authorization", authHead);
            }
        }