@@ -73,6 +73,9 @@ public void modifyRequest(com.aliyun.gateway.spi.models.InterceptorContext conte
7373 } else if (com .aliyun .darabonbastring .Client .equals (request .reqBodyType , "binary" )) {
7474 // content-type: application/octet-stream
7575 bodyBytes = com .aliyun .teautil .Common .assertAsBytes (request .body );
76+ } else if (com .aliyun .darabonbastring .Client .equals (request .reqBodyType , "protobuf" )) {
77+ bodyBytes = com .aliyun .gateway .sls .util .Client .serializeToPbBytes (request .body );
78+ request .headers .put ("content-type" , "application/x-protobuf" );
7679 }
7780
7881 }
@@ -83,12 +86,12 @@ public void modifyRequest(com.aliyun.gateway.spi.models.InterceptorContext conte
8386 // for php bug, Argument #1 ($value) could not be passed by reference
8487 if (!com .aliyun .teautil .Common .isUnset (rawSizeRef )) {
8588 bodyRawSize = rawSizeRef ;
86- } else if (!com .aliyun .teautil .Common .isUnset (request . body )) {
89+ } else if (!com .aliyun .teautil .Common .isUnset (bodyBytes )) {
8790 bodyRawSize = "" + com .aliyun .gateway .sls .util .Client .bytesLength (bodyBytes ) + "" ;
8891 }
8992
9093 // compress if needed, and set body and hash
91- if (!com .aliyun .teautil .Common .isUnset (request . body )) {
94+ if (!com .aliyun .teautil .Common .isUnset (bodyBytes )) {
9295 if (!com .aliyun .teautil .Common .empty (finalCompressType )) {
9396 byte [] compressed = com .aliyun .gateway .sls .util .Client .compress (bodyBytes , finalCompressType );
9497 bodyBytes = compressed ;
@@ -199,17 +202,19 @@ public String makeContentHash(byte[] content, String signatureVersion) throws Ex
199202 public void modifyResponse (com .aliyun .gateway .spi .models .InterceptorContext context , com .aliyun .gateway .spi .models .AttributeMap attributeMap ) throws Exception {
200203 com .aliyun .gateway .spi .models .InterceptorContext .InterceptorContextRequest request = context .request ;
201204 com .aliyun .gateway .spi .models .InterceptorContext .InterceptorContextResponse response = context .response ;
202- if (com .aliyun .teautil .Common .is4xx (response .statusCode ) || com .aliyun .teautil .Common .is5xx (response .statusCode )) {
205+ Number statusCode = response .statusCode ;
206+ String requestId = response .headers .get ("x-log-requestid" );
207+ if (com .aliyun .teautil .Common .is4xx (statusCode ) || com .aliyun .teautil .Common .is5xx (statusCode )) {
203208 Object error = com .aliyun .teautil .Common .readAsJSON (response .body );
204209 java .util .Map <String , Object > resMap = com .aliyun .teautil .Common .assertAsMap (error );
205210 throw new TeaException (TeaConverter .buildMap (
206211 new TeaPair ("code" , resMap .get ("errorCode" )),
207212 new TeaPair ("message" , resMap .get ("errorMessage" )),
208213 new TeaPair ("accessDeniedDetail" , resMap .get ("accessDeniedDetail" )),
209214 new TeaPair ("data" , TeaConverter .buildMap (
210- new TeaPair ("httpCode" , response . statusCode ),
211- new TeaPair ("requestId" , response . headers . get ( "x-log-requestid" ) ),
212- new TeaPair ("statusCode" , response . statusCode )
215+ new TeaPair ("httpCode" , statusCode ),
216+ new TeaPair ("requestId" , requestId ),
217+ new TeaPair ("statusCode" , statusCode )
213218 ))
214219 ));
215220 }
@@ -235,6 +240,9 @@ public void modifyResponse(com.aliyun.gateway.spi.models.InterceptorContext cont
235240 response .deserializedBody = obj ;
236241 } else if (com .aliyun .teautil .Common .equalString (request .bodyType , "array" )) {
237242 response .deserializedBody = com .aliyun .teautil .Common .readAsJSON (uncompressedData );
243+ } else if (com .aliyun .teautil .Common .equalString (request .bodyType , "protobuf" )) {
244+ byte [] pbBytes = com .aliyun .teautil .Common .readAsBytes (uncompressedData );
245+ response .deserializedBody = com .aliyun .gateway .sls .util .Client .deserializeFromPbBytes (pbBytes , statusCode , response .headers );
238246 } else {
239247 response .deserializedBody = com .aliyun .teautil .Common .readAsString (uncompressedData );
240248 }
0 commit comments