diff --git a/WebHDFS/WebHDFSClient.cs b/WebHDFS/WebHDFSClient.cs index c587d75..8d1fcdf 100644 --- a/WebHDFS/WebHDFSClient.cs +++ b/WebHDFS/WebHDFSClient.cs @@ -23,7 +23,8 @@ public class WebHDFSClient : IDisposable /// Optional credentials. /// Optional timeout. /// Optional HttpMessageHandler. - public WebHDFSClient(string BaseAPI, NetworkCredential Credentials = null, TimeSpan? Timeout = null, HttpMessageHandler CustomHttpMessageHandler = null) + /// Expect server will return continue (100) before success + public WebHDFSClient(string BaseAPI, NetworkCredential Credentials = null, TimeSpan? Timeout = null, HttpMessageHandler CustomHttpMessageHandler = null, bool? ExpectContinue = null) { _baseAPI = BaseAPI.TrimEnd('/'); @@ -39,6 +40,7 @@ public WebHDFSClient(string BaseAPI, NetworkCredential Credentials = null, TimeS AllowAutoRedirect = false, Credentials = Credentials, PreAuthenticate = true + }; } @@ -46,6 +48,7 @@ public WebHDFSClient(string BaseAPI, NetworkCredential Credentials = null, TimeS { Timeout = Timeout.GetValueOrDefault(TimeSpan.FromMinutes(5)) }; + _httpClient.DefaultRequestHeaders.ExpectContinue = ExpectContinue.GetValueOrDefault(); } /// @@ -88,12 +91,22 @@ public async Task WriteStream( WebHDFSHttpQueryParameter.SetBuffersize(query, buffersize); string requestPath = _baseAPI + path + '?' + query; - + var response = await _httpClient.PutAsync(requestPath, new ByteArrayContent(new byte[] {})); if(response.StatusCode.Equals(HttpStatusCode.TemporaryRedirect)) { + var response2 = await _httpClient.PutAsync(response.Headers.Location, new StreamContent(stream)); - response2.EnsureSuccessStatusCode(); + try + { + response2.EnsureSuccessStatusCode(); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + throw; + } + return response2.IsSuccessStatusCode; } throw new InvalidOperationException("Should get a 307. Instead we got: " +