Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compression #17

Merged
merged 3 commits into from
Sep 14, 2016
Merged

Compression #17

merged 3 commits into from
Sep 14, 2016

Conversation

BerendWouters
Copy link

@BerendWouters BerendWouters commented Sep 10, 2016

Adds gzip-compression to the .NET-client library
Related to issue: #16

@pofider
Copy link
Contributor

pofider commented Sep 10, 2016

Thanks. That is great!

However it seems that your change only compresses the response, which doesn't have benefit for pdf/excel reports.

Didn't you want to rather compress the request body?
Something like this? (not tested, not finished)

public async Task<Report> RenderAsync(object request, CancellationToken ct = default(CancellationToken))
{
            var client = CreateClient();

            byte[] jsonBytes = Encoding.UTF8.GetBytes(ValidateAndSerializeRequest(request));
            var ms = new MemoryStream();
            using (var gzip = new GZipStream(ms, CompressionMode.Compress, true))
            {
                gzip.Write(jsonBytes, 0, jsonBytes.Length);
            }
            ms.Position = 0;

            var content = new StreamContent(ms);
            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            content.Headers.ContentEncoding.Add("gzip");
            var response =
                await
                client.PostAsync("api/report", content, ct).ConfigureAwait(false);


            if (response.StatusCode != HttpStatusCode.OK)
                throw JsReportException.Create("Unable to render template. ", response);

            response.EnsureSuccessStatusCode();

            return await ReportFromResponse(response).ConfigureAwait(false);
 }

@BerendWouters
Copy link
Author

Ah yes, I was mistaken. I'll update and test it accordingly.

@pofider
Copy link
Contributor

pofider commented Sep 14, 2016

Looks great and works for me. I'm going to merge it in, if it is complete from you.

@BerendWouters
Copy link
Author

Thanks :)

@pofider pofider merged commit 94a58d4 into jsreport:master Sep 14, 2016
@pofider
Copy link
Contributor

pofider commented Sep 14, 2016

Great job, thank you.

@BerendWouters
Copy link
Author

Any idea when the NuGet-package will be updated?

@pofider
Copy link
Contributor

pofider commented Sep 15, 2016

Now:)
https://www.nuget.org/packages/jsreport.Client/1.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants