7
7
import requests
8
8
import argparse
9
9
import fnmatch
10
+ import zlib
10
11
from time import sleep
11
12
from json import loads
12
13
@@ -1021,6 +1022,16 @@ def main(*argv, **kwargs):
1021
1022
write (reports )
1022
1023
write ("-------------------------------------------------" )
1023
1024
1025
+ # Handle reports encoding for Python 2 and 3
1026
+ if not isinstance (reports , bytes ):
1027
+ reports = reports .encode ("utf-8" )
1028
+
1029
+ # Compress reports using zlib and output with gzip header
1030
+ write (" Gzipping contents.." )
1031
+ gzip_worker = zlib .compressobj (9 , zlib .DEFLATED , zlib .MAX_WBITS | 16 )
1032
+ reports_gzip = gzip_worker .compress (reports ) + gzip_worker .flush ()
1033
+ write (" Compressed contents to {0} bytes" .format (len (reports_gzip )))
1034
+
1024
1035
s3 = None
1025
1036
trys = 0
1026
1037
while trys < 3 :
@@ -1034,7 +1045,8 @@ def main(*argv, **kwargs):
1034
1045
headers = {
1035
1046
"Accept" : "text/plain" ,
1036
1047
"X-Reduced-Redundancy" : "false" ,
1037
- },
1048
+ "X-Content-Type" : "application/x-gzip"
1049
+ }
1038
1050
)
1039
1051
if res .status_code in (400 , 406 ):
1040
1052
raise Exception (res .text )
@@ -1044,15 +1056,14 @@ def main(*argv, **kwargs):
1044
1056
res = res .text .strip ().split ()
1045
1057
result , upload_url = res [0 ], res [1 ]
1046
1058
1047
- # Handle reports encoding for Python 2 and 3
1048
- if not isinstance (reports , bytes ):
1049
- reports = reports .encode ("utf-8" )
1050
-
1051
1059
write (" Uploading to S3..." )
1052
1060
s3 = requests .put (
1053
1061
upload_url ,
1054
- data = reports ,
1055
- headers = {"Content-Type" : "text/plain" ,},
1062
+ data = reports_gzip ,
1063
+ headers = {
1064
+ "Content-Type" : "application/x-gzip" ,
1065
+ "Content-Encoding" : "gzip"
1066
+ }
1056
1067
)
1057
1068
s3 .raise_for_status ()
1058
1069
assert s3 .status_code == 200
@@ -1070,10 +1081,12 @@ def main(*argv, **kwargs):
1070
1081
res = requests .post (
1071
1082
"%s/upload/v2?%s" % (codecov .url , urlargs ),
1072
1083
verify = codecov .cacert ,
1073
- data = "\n " .join (
1074
- (reports , s3 .reason if s3 else "" , s3 .text if s3 else "" )
1075
- ),
1076
- headers = {"Accept" : "text/plain" },
1084
+ data = reports_gzip ,
1085
+ headers = {
1086
+ "Accept" : "text/plain" ,
1087
+ "Content-Type" : "application/x-gzip" ,
1088
+ "Content-Encoding" : "gzip"
1089
+ }
1077
1090
)
1078
1091
if res .status_code < 500 :
1079
1092
write (" " + res .text )
0 commit comments