"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Duplicati/Library/Backend/OAuthHelper/JSONWebHelper.cs" between
duplicati-2.0.5.104-2.0.5.104_canary_2020-03-25.tar.gz and duplicati-2.0.5.106-2.0.5.106_canary_2020-05-11.tar.gz

About: Duplicati is a backup client that securely stores encrypted, incremental, compressed backups on local devices, cloud storage services and remote file servers (for Windows, macOS and Linux). A remark: This officially "pre-release" seems to run stable.

JSONWebHelper.cs  (duplicati-2.0.5.104-2.0.5.104_canary_2020-03-25):JSONWebHelper.cs  (duplicati-2.0.5.106-2.0.5.106_canary_2020-05-11)
skipping to change at line 291 skipping to change at line 291
} }
public virtual async Task<T> ReadJSONResponseAsync<T>(AsyncHttpRequest r eq, CancellationToken cancelToken, object requestdata = null) public virtual async Task<T> ReadJSONResponseAsync<T>(AsyncHttpRequest r eq, CancellationToken cancelToken, object requestdata = null)
{ {
using (var resp = await GetResponseAsync(req, cancelToken, requestda ta).ConfigureAwait(false)) using (var resp = await GetResponseAsync(req, cancelToken, requestda ta).ConfigureAwait(false))
return ReadJSONResponse<T>(resp); return ReadJSONResponse<T>(resp);
} }
public virtual T ReadJSONResponse<T>(HttpWebResponse resp) public virtual T ReadJSONResponse<T>(HttpWebResponse resp)
{ {
using(var rs = Duplicati.Library.Utility.AsyncHttpRequest.TrySetTime using (var rs = Duplicati.Library.Utility.AsyncHttpRequest.TrySetTim
out(resp.GetResponseStream())) eout(resp.GetResponseStream()))
using(var tr = new System.IO.StreamReader(rs)) using(var ps = new StreamPeekReader(rs))
using(var jr = new Newtonsoft.Json.JsonTextReader(tr)) {
return new Newtonsoft.Json.JsonSerializer().Deserialize<T>(jr); try
{
using (var tr = new System.IO.StreamReader(ps))
using (var jr = new Newtonsoft.Json.JsonTextReader(tr))
return new Newtonsoft.Json.JsonSerializer().Deserialize<
T>(jr);
}
catch (Exception ex)
{
// If we get invalid JSON, report the peek value
if (ex is Newtonsoft.Json.JsonReaderException)
throw new IOException($"Invalid JSON data: \"{ps.PeekDat
a()}\"", ex);
// Otherwise, we have no additional help to offer
throw;
}
}
} }
/// <summary> /// <summary>
/// Use this method to register an exception handler, /// Use this method to register an exception handler,
/// which can throw another, more meaningful exception /// which can throw another, more meaningful exception
/// </summary> /// </summary>
/// <param name="ex">The exception being processed.</param> /// <param name="ex">The exception being processed.</param>
protected virtual void ParseException(Exception ex) protected virtual void ParseException(Exception ex)
{ {
} }
skipping to change at line 521 skipping to change at line 535
{ {
public readonly byte[] Header; public readonly byte[] Header;
public readonly MultipartItem Part; public readonly MultipartItem Part;
public HeaderPart(byte[] header, MultipartItem part) public HeaderPart(byte[] header, MultipartItem part)
{ {
Header = header; Header = header;
Part = part; Part = part;
} }
} }
/// <summary>
/// A utility class that shadows the real stream but provides access
/// to the first 2kb of the stream to use in error reporting
/// </summary>
protected class StreamPeekReader : Stream
{
private readonly Stream m_base;
private readonly byte[] m_peekbuffer = new byte[1024 * 2];
private int m_peekbytes = 0;
public StreamPeekReader(Stream source)
{
m_base = source;
}
public string PeekData()
{
if (m_peekbuffer.Length == 0)
return string.Empty;
return Encoding.UTF8.GetString(m_peekbuffer, 0, m_peekbytes);
}
public override bool CanRead => m_base.CanRead;
public override bool CanSeek => m_base.CanSeek;
public override bool CanWrite => m_base.CanWrite;
public override long Length => m_base.Length;
public override long Position { get => m_base.Position; set => m_bas
e.Position = value; }
public override void Flush() => m_base.Flush();
public override long Seek(long offset, SeekOrigin origin) => m_base.
Seek(offset, origin);
public override void SetLength(long value) => m_base.SetLength(value
);
public override void Write(byte[] buffer, int offset, int count) =>
m_base.Write(buffer, offset, count);
public override IAsyncResult BeginRead(byte[] buffer, int offset, in
t count, AsyncCallback callback, object state) => m_base.BeginRead(buffer, offse
t, count, callback, state);
public override IAsyncResult BeginWrite(byte[] buffer, int offset, i
nt count, AsyncCallback callback, object state) => m_base.BeginWrite(buffer, off
set, count, callback, state);
public override bool CanTimeout => m_base.CanTimeout;
public override void Close() => m_base.Close();
public override Task CopyToAsync(Stream destination, int bufferSize,
CancellationToken cancellationToken) => m_base.CopyToAsync(destination, bufferS
ize, cancellationToken);
protected override void Dispose(bool disposing) => base.Dispose(disp
osing);
public override int EndRead(IAsyncResult asyncResult) => m_base.EndR
ead(asyncResult);
public override void EndWrite(IAsyncResult asyncResult) => m_base.En
dWrite(asyncResult);
public override Task FlushAsync(CancellationToken cancellationToken)
=> m_base.FlushAsync(cancellationToken);
public override int ReadTimeout { get => m_base.ReadTimeout; set =>
m_base.ReadTimeout = value; }
public override Task WriteAsync(byte[] buffer, int offset, int count
, CancellationToken cancellationToken) => m_base.WriteAsync(buffer, offset, coun
t, cancellationToken);
public override int WriteTimeout { get => m_base.WriteTimeout; set =
> m_base.WriteTimeout = value; }
public override async Task<int> ReadAsync(byte[] buffer, int offset,
int count, CancellationToken cancellationToken)
{
var br = 0;
if (m_peekbytes < m_peekbuffer.Length - 1)
{
var maxb = Math.Min(count, m_peekbuffer.Length - m_peekbytes
);
br = await m_base.ReadAsync(m_peekbuffer, m_peekbytes, maxb,
cancellationToken);
Array.Copy(m_peekbuffer, m_peekbytes, buffer, offset, br);
m_peekbytes += br;
offset += br;
count -= br;
if (count == 0 || br < maxb)
return br;
}
return await m_base.ReadAsync(buffer, offset, count, cancellatio
nToken) + br;
}
public override int Read(byte[] buffer, int offset, int count)
{
var br = 0;
if (m_peekbytes < m_peekbuffer.Length - 1)
{
var maxb = Math.Min(count, m_peekbuffer.Length - m_peekbytes
);
br = m_base.Read(m_peekbuffer, m_peekbytes, maxb);
Array.Copy(m_peekbuffer, m_peekbytes, buffer, offset, br);
m_peekbytes += br;
offset += br;
count -= br;
if (count == 0 || br < maxb)
return br;
}
return m_base.Read(buffer, offset, count) + br;
}
}
} }
} }
 End of changes. 2 change blocks. 
5 lines changed or deleted 128 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)