Improve protobuf support (#2513)

Summary:
* Update protobuf library to support map types
* Improved usage messaging in UI
* Always attempt to decode requests with a protobuf definition
## Changelog
Improved protobuf support

Pull Request resolved: https://github.com/facebook/flipper/pull/2513

Reviewed By: mweststrate

Differential Revision: D30162379

Pulled By: passy

fbshipit-source-id: 201fb06045822641be5840b121da180a201be974
This commit is contained in:
Harold Martin
2021-08-09 02:41:13 -07:00
committed by Facebook GitHub Bot
parent 410445a1ed
commit efd75ea435
3 changed files with 21 additions and 5 deletions

View File

@@ -25,7 +25,7 @@ android {
implementation project(':network-plugin') implementation project(':network-plugin')
implementation deps.protobuf implementation deps.protobuf
implementation "com.squareup.retrofit2:retrofit:2.9.0" implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.github.hbmartin:protobuf_java_to_protobufjs:0.1.0" implementation "com.github.hbmartin:protobuf_java_to_protobufjs:0.2.0"
compileOnly deps.jsr305 compileOnly deps.jsr305
} }
} }

View File

@@ -63,6 +63,10 @@ export class ProtobufDefinitionsRepository {
} }
} }
public hasDefinition(method: string, path: string): boolean {
return this.rawDefinitions.hasOwnProperty(this.key(method, path));
}
private generateRoots(key: string) { private generateRoots(key: string) {
if (key in this.cachedDecodedDefinitions) { if (key in this.cachedDecodedDefinitions) {
return; return;

View File

@@ -670,7 +670,11 @@ class ProtobufFormatter {
formatRequest(request: Request) { formatRequest(request: Request) {
if ( if (
getHeaderValue(request.requestHeaders, 'content-type') === getHeaderValue(request.requestHeaders, 'content-type') ===
'application/x-protobuf' 'application/x-protobuf' ||
this.protobufDefinitionRepository.hasDefinition(
request.method,
request.url,
)
) { ) {
const protobufDefinition = const protobufDefinition =
this.protobufDefinitionRepository.getRequestType( this.protobufDefinitionRepository.getRequestType(
@@ -681,7 +685,9 @@ class ProtobufFormatter {
return ( return (
<Text> <Text>
Could not locate protobuf definition for request body of{' '} Could not locate protobuf definition for request body of{' '}
{request.url} {request.url} <br />
Please send ProtobufJS definitions with the plugin's
addProtobufDefinitions method.
</Text> </Text>
); );
} }
@@ -704,7 +710,11 @@ class ProtobufFormatter {
if ( if (
getHeaderValue(request.responseHeaders, 'content-type') === getHeaderValue(request.responseHeaders, 'content-type') ===
'application/x-protobuf' || 'application/x-protobuf' ||
request.url.endsWith('.proto') request.url.endsWith('.proto') ||
this.protobufDefinitionRepository.hasDefinition(
request.method,
request.url,
)
) { ) {
const protobufDefinition = const protobufDefinition =
this.protobufDefinitionRepository.getResponseType( this.protobufDefinitionRepository.getResponseType(
@@ -715,7 +725,9 @@ class ProtobufFormatter {
return ( return (
<Text> <Text>
Could not locate protobuf definition for response body of{' '} Could not locate protobuf definition for response body of{' '}
{request.url} {request.url} <br />
Please send ProtobufJS definitions with the plugin's
addProtobufDefinitions method.
</Text> </Text>
); );
} }