internal HttpRequestMessage CreateBinaryRequest(ReportRequest report) { var binaryReport = report.ToByteArray(); var request = new HttpRequestMessage(HttpMethod.Post, _url) { Version = _options.UseHttp2 ? new Version(2, 0) : new Version(1, 1), Content = new ByteArrayContent(binaryReport) }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); return(request); }
/// <summary> /// Send a report of spans to the LightStep Satellite. /// </summary> /// <param name="report">An <see cref="ReportRequest" /></param> /// <returns>A <see cref="ReportResponse" />. This is usually not very interesting.</returns> public async Task <ReportResponse> SendReport(ReportRequest report) { // force net45 to attempt tls12 first and fallback appropriately ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; _client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/octet-stream")); var reportsByteArray = report.ToByteArray(); var request = new HttpRequestMessage(HttpMethod.Post, _url) { Version = _options.UseHttp2 ? new Version(2, 0) : new Version(1, 1), Content = new ByteArrayContent(reportsByteArray) }; request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); ReportResponse responseValue = new ReportResponse(); try { var response = await _client.SendAsync(request); response.EnsureSuccessStatusCode(); var responseData = await response.Content.ReadAsStreamAsync(); responseValue = ReportResponse.Parser.ParseFrom(responseData); } catch (HttpRequestException ex) { Console.WriteLine(ex); Console.WriteLine("resetting httpclient"); _client.Dispose(); _client = new HttpClient(); } return(responseValue); }