Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
fixes some request payload length issues on empty zipping up of POST …
Browse files Browse the repository at this point in the history
…requests
  • Loading branch information
didimitrie committed Mar 30, 2018
1 parent aef9e85 commit 9d18a4e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 37 deletions.
3 changes: 2 additions & 1 deletion SpeckleCore/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public static List<SpeckleObject> Serialise( IEnumerable<object> objectList )
/// <returns>A native type, a SpeckleAbstract if no explicit conversion found, or null.</returns>
public static List<object> Deserialise( IEnumerable<SpeckleObject> objectList )
{
return objectList.Select( obj => Deserialise( obj ) ).ToList();
var copy = objectList.ToArray();
return copy.Select( obj => Deserialise( obj ) ).ToList();
}

/// <summary>
Expand Down
74 changes: 39 additions & 35 deletions SpeckleCore/GzipContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,46 +10,50 @@

namespace SpeckleCore
{
/// <summary>
/// https://cymbeline.ch/2014/03/16/gzip-encoding-an-http-post-request-body/
/// </summary>
internal sealed class GzipContent : HttpContent
{
private readonly HttpContent content;

public GzipContent(HttpContent content)
{
this.content = content;

/// <summary>
/// https://cymbeline.ch/2014/03/16/gzip-encoding-an-http-post-request-body/
/// </summary>
internal sealed class GzipContent : HttpContent
{
private readonly HttpContent content;

// Keep the original content's headers ...
if (content != null)
foreach (KeyValuePair<string, IEnumerable<string>> header in content.Headers)
{
Headers.TryAddWithoutValidation(header.Key, header.Value);
}
public GzipContent( HttpContent content )
{
if(content == null)
{
return;
}

// ... and let the server know we've Gzip-compressed the body of this request.
Headers.ContentEncoding.Add("gzip");
}
this.content = content;

protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
// Keep the original content's headers ...
if ( content != null )
foreach ( KeyValuePair<string, IEnumerable<string>> header in content.Headers )
{
// Open a GZipStream that writes to the specified output stream.
using (GZipStream gzip = new GZipStream(stream, CompressionMode.Compress, true))
{
// Copy all the input content to the GZip stream.
if (content != null)
await content.CopyToAsync(gzip);
else
await (new System.Net.Http.StringContent(string.Empty)).CopyToAsync(gzip);
}
Headers.TryAddWithoutValidation( header.Key, header.Value );
}

protected override bool TryComputeLength(out long length)
{
length = -1;
return false;
}
// ... and let the server know we've Gzip-compressed the body of this request.
Headers.ContentEncoding.Add( "gzip" );
}

protected override async Task SerializeToStreamAsync( Stream stream, TransportContext context )
{
// Open a GZipStream that writes to the specified output stream.
using ( GZipStream gzip = new GZipStream( stream, CompressionMode.Compress, true ) )
{
// Copy all the input content to the GZip stream.
if ( content != null )
await content.CopyToAsync( gzip );
else
await ( new System.Net.Http.StringContent( string.Empty ) ).CopyToAsync( gzip );
}
}

protected override bool TryComputeLength( out long length )
{
length = -1;
return false;
}
}
}
1 change: 0 additions & 1 deletion SpeckleCore/SpeckleApiClientApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2724,7 +2724,6 @@ public async System.Threading.Tasks.Task<ResponseStreamClone> StreamCloneAsync(
{
using ( var request_ = new System.Net.Http.HttpRequestMessage() )
{
request_.Content = new System.Net.Http.StringContent( string.Empty, System.Text.Encoding.UTF8, "application/json" );
request_.Method = new System.Net.Http.HttpMethod( "POST" );
request_.Headers.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue( "application/json" ) );

Expand Down

0 comments on commit 9d18a4e

Please sign in to comment.