partial void PrepareRequest(Transaction body, HttpClient client, HttpRequestMessage request, string url)
        {
            var uriBuilder = new UriBuilder(request.RequestUri);
            var query      = HttpUtility.ParseQueryString(uriBuilder.Query);

            if (conn is LocalConnection)
            {
                query["dbname"] = conn.DbName;
                if (!_isEmpty(body.Source_dbname))
                {
                    query["source_dbname"] = body.Source_dbname;
                }
            }
            query["open_mode"] = body.Mode.ToString();
            if (conn is ManagementConnection || conn is CloudConnection)
            {
                query["region"] = EnumString.GetDescription(conn.Region);
            }
            if (conn is CloudConnection)
            {
                query["compute_name"] = conn.ComputeName;
            }
            uriBuilder.Query   = query.ToString();
            request.RequestUri = uriBuilder.Uri;

            // populate headers
            request.Headers.Host = request.RequestUri.Host;
            request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json; charset=utf-8");

            // sign request here
            var raiRequest = new RAIRequest(request, conn);

            raiRequest.Sign(debugLevel: DebugLevel);
            DelveClient.AddExtraHeaders(request);

            // use HTTP 2.0 (to handle keep-alive)
            request.Version = System.Net.HttpVersion.Version20;

            // have a separate keep-alive task (per thread)
            if (!isStatusRequest(body))
            {
                var tokenSource = new CancellationTokenSource();
                AsyncLocalKeepAliveCancellationTokenSource.Value = tokenSource;
                CancellationToken ct = tokenSource.Token;

                /**
                 * TODO: currently we swallo exceptions in KeepClientAlive.
                 * If we want to throw, then we need to change this to asynchronously handle the throw
                 * e.g.
                 * try {
                 *   await this.KeepClientAlive(client, url, ct).ConfigureAwait(false);
                 * } catch (Exception e) {
                 *   // Handle here
                 * }
                 **/
                var keep_alive_task = this.KeepClientAlive(client, url, ct).ConfigureAwait(false);
            }
        }
예제 #2
0
        partial void PrepareRequest(System.Net.Http.HttpClient client, System.Net.Http.HttpRequestMessage request, string url)
        {
            if (request.Content == null)
            {
                request.Content = new StringContent("");
            }
            // populate headers
            request.Headers.Clear();
            request.Content.Headers.Clear();
            request.Headers.Host = request.RequestUri.Host;
            request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json");

            RAIRequest raiReq = new RAIRequest(request, conn);

            raiReq.Sign();
            DelveClient.AddExtraHeaders(request);
        }
예제 #3
0
        public void Test2()
        {
            string dbname = IntegrationTestsCommons.genDbname("testcsharpclient");

            CloudConnection cloudConn = new CloudConnection(
                new LocalConnection(dbname),
                creds: new RAICredentials(
                    "e3536f8d-cbc6-4ed8-9de6-74cf4cb724a1",
                    "krnXRBoE0lX6NddvryxKIE+7RWrkWg6xk8NcGaSOdCo="
                    ),
                verifySSL: false
                );

            HttpRequestMessage httpReq = new HttpRequestMessage();

            httpReq.Method     = HttpMethod.Get;
            httpReq.RequestUri = new Uri("https://127.0.0.1:8443/database");
            httpReq.Content    = new StringContent("{}");
            httpReq.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            httpReq.Headers.Host = "127.0.0.1";
            RAIRequest req = new RAIRequest(httpReq, cloudConn, service: "database+list");

            req.Sign(DateTime.Parse("2020-05-04T10:36:00"), debugLevel: cloudConn.DebugLevel);

            string output = string.Join(
                "\n",
                from header in req.InnerReq.Headers.Union(req.InnerReq.Content.Headers)
                orderby header.Key.ToLower()
                select string.Format(
                    "{0}: {1}",
                    header.Key.ToLower(),
                    string.Join(",", header.Value).Trim()
                    )
                ) + "\n";
            string expected =
                "authorization: RAI01-ED25519-SHA256 " +
                "Credential=e3536f8d-cbc6-4ed8-9de6-74cf4cb724a1/20200504/us-east/database+list/rai01_request, " +
                "SignedHeaders=content-type;host;x-rai-date, " +
                "Signature=77d211417454ded42dc931d25c57af6cab6cbc70f75bef4c849d37585188d659158c8c944eab866e3147bbcde21257ae0a1dfece3c0f3f43a838b3f9524e0f0a\n" +
                "content-type: application/json\n" +
                "host: 127.0.0.1\n" +
                "x-rai-date: 20200504T103600Z\n";

            Assert.AreEqual(output, expected);
        }