Skip to content

Commit 1b8c007

Browse files
committed
Work around a bug in Mono.Addins with gzip responses (#1547)
Some internal code in Mono.Addins assumes the header's ContentLength property is never null, but this is not the case for gzipped responses from Github's server. This started happening recently so it may have been a change on Github's end. The workaround is to register our own HttpClient provider which disables gzip compression in our requests. Fixes: #1542 (cherry picked from commit d0442c1)
1 parent 18fd277 commit 1b8c007

1 file changed

Lines changed: 20 additions & 6 deletions

File tree

Pinta/AddinSetupService.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
//
1+
//
22
// AddinSetupService.cs
3-
//
3+
//
44
// Author:
55
// Lluis Sanchez Gual <lluis@novell.com>
6-
//
6+
//
77
// Copyright (c) 2011 Novell, Inc (http://www.novell.com)
8-
//
8+
//
99
// Permission is hereby granted, free of charge, to any person obtaining a copy
1010
// of this software and associated documentation files (the "Software"), to deal
1111
// in the Software without restriction, including without limitation the rights
1212
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1313
// copies of the Software, and to permit persons to whom the Software is
1414
// furnished to do so, subject to the following conditions:
15-
//
15+
//
1616
// The above copyright notice and this permission notice shall be included in
1717
// all copies or substantial portions of the Software.
18-
//
18+
//
1919
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2020
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2121
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -24,6 +24,8 @@
2424
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2525
// THE SOFTWARE.
2626

27+
using System.Net;
28+
using System.Net.Http;
2729
using Mono.Addins;
2830
using Mono.Addins.Setup;
2931
using Pinta.Core;
@@ -34,6 +36,18 @@ public sealed class AddinSetupService : SetupService
3436
{
3537
internal AddinSetupService (AddinRegistry r) : base (r)
3638
{
39+
Mono.Addins.Setup.HttpClientProvider.SetHttpClientFactory (CreateHttpClient);
40+
}
41+
42+
private static HttpClient CreateHttpClient (string uri)
43+
{
44+
// Work around a bug (#1542) in Mono.Addins.Setup.HttpClientDownloadFileRequest,
45+
// which assumes that ContentLength is never null.
46+
// Github's server (which hosts the repo) doesn't provide this for gzipped responses.
47+
HttpClientHandler handler = new () {
48+
AutomaticDecompression = DecompressionMethods.Deflate
49+
};
50+
return new HttpClient (handler);
3751
}
3852

3953
public bool AreRepositoriesRegistered ()

0 commit comments

Comments
 (0)