Gzip无法在aws lambda中工作(无服务器)

时间:2017-11-23 10:44:10

标签: java amazon-web-services lambda aws-lambda serverless

我正在尝试从java代码压缩lambda响应,但在浏览器中它无法解码

    @Override
    public Map handleRequest(Map<String,Object> input, Context context) {

           Map<String, Object> repsonse = new HashMap<>();
           HashMap<String, String> headers = new HashMap<>();              
           headers.put("Content-Encoding", "gzip");
           headers.put("Content-Type", "text/html");
           final String sampleHtml = "<h1>Hello World</h1>";  
           ByteArrayOutputStream out = new ByteArrayOutputStream();
           GZIPOutputStream gzip = new GZIPOutputStream(out);
           gzip.write(sampleHtml.getBytes());
           gzip.close();
           String responseString = out.toString("ISO-8859-1");
           response.put("headers", headers);           
           response.put("body", responseString);
           response.put("statusCode", 200);
           response.put("isBase64Encoded", true);
           return response;
    }

0 个答案:

没有答案