@@ -73,6 +73,10 @@ 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+ byte [] pbBytes = com .aliyun .gateway .sls .util .Client .serializeToPbBytes (request .body );
78+ request .stream = Tea .toReadable (pbBytes );
79+ request .headers .put ("content-type" , "application/x-protobuf" );
7680 }
7781
7882 }
@@ -83,7 +87,7 @@ public void modifyRequest(com.aliyun.gateway.spi.models.InterceptorContext conte
8387 // for php bug, Argument #1 ($value) could not be passed by reference
8488 if (!com .aliyun .teautil .Common .isUnset (rawSizeRef )) {
8589 bodyRawSize = rawSizeRef ;
86- } else if (!com .aliyun .teautil .Common .isUnset (request . body )) {
90+ } else if (!com .aliyun .teautil .Common .isUnset (bodyBytes )) {
8791 bodyRawSize = "" + com .aliyun .gateway .sls .util .Client .bytesLength (bodyBytes ) + "" ;
8892 }
8993
@@ -199,17 +203,19 @@ public String makeContentHash(byte[] content, String signatureVersion) throws Ex
199203 public void modifyResponse (com .aliyun .gateway .spi .models .InterceptorContext context , com .aliyun .gateway .spi .models .AttributeMap attributeMap ) throws Exception {
200204 com .aliyun .gateway .spi .models .InterceptorContext .InterceptorContextRequest request = context .request ;
201205 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 )) {
206+ Number statusCode = response .statusCode ;
207+ String requestId = response .headers .get ("x-log-requestid" );
208+ if (com .aliyun .teautil .Common .is4xx (statusCode ) || com .aliyun .teautil .Common .is5xx (statusCode )) {
203209 Object error = com .aliyun .teautil .Common .readAsJSON (response .body );
204210 java .util .Map <String , Object > resMap = com .aliyun .teautil .Common .assertAsMap (error );
205211 throw new TeaException (TeaConverter .buildMap (
206212 new TeaPair ("code" , resMap .get ("errorCode" )),
207213 new TeaPair ("message" , resMap .get ("errorMessage" )),
208214 new TeaPair ("accessDeniedDetail" , resMap .get ("accessDeniedDetail" )),
209215 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 )
216+ new TeaPair ("httpCode" , statusCode ),
217+ new TeaPair ("requestId" , requestId ),
218+ new TeaPair ("statusCode" , statusCode )
213219 ))
214220 ));
215221 }
@@ -235,6 +241,9 @@ public void modifyResponse(com.aliyun.gateway.spi.models.InterceptorContext cont
235241 response .deserializedBody = obj ;
236242 } else if (com .aliyun .teautil .Common .equalString (request .bodyType , "array" )) {
237243 response .deserializedBody = com .aliyun .teautil .Common .readAsJSON (uncompressedData );
244+ } else if (com .aliyun .teautil .Common .equalString (request .bodyType , "protobuf" )) {
245+ byte [] pbBytes = com .aliyun .teautil .Common .readAsBytes (uncompressedData );
246+ response .deserializedBody = com .aliyun .gateway .sls .util .Client .deserializeFromPbBytes (pbBytes , statusCode , response .headers );
238247 } else {
239248 response .deserializedBody = com .aliyun .teautil .Common .readAsString (uncompressedData );
240249 }
0 commit comments