test_class.declarator: rule = new PowerMockRule()
test_class.modifier: @Rule
    public
test_class.original_string: @Rule
    public PowerMockRule rule = new PowerMockRule();
test_class.type: PowerMockRule
test_class.var_name: rule
test_class.file: node_modules/react-native/ReactAndroid/src/test/java/com/facebook/react/modules/network/NetworkingModuleTest.java
test_class.identifier: NetworkingModuleTest
test_case.body: @Test
    public void testHeaders() throws Exception {
      OkHttpClient httpClient = mock(OkHttpClient.class);
      when(httpClient.newCall(any(Request.class))).thenAnswer(new Answer<Object>() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
          Call callMock = mock(Call.class);
          return callMock;
        }
      });
      NetworkingModule networkingModule = new NetworkingModule(null, "", httpClient);
  
      List<JavaOnlyArray> headers = Arrays.asList(
          JavaOnlyArray.of("Accept", "text/plain"),
          JavaOnlyArray.of("User-Agent", "React test agent/1.0"));
  
      networkingModule.sendRequest(
        mock(ExecutorToken.class),
        "GET",
        "http://someurl/baz",
        0,
        JavaOnlyArray.from(headers),
        null,
        true,
        0);
      ArgumentCaptor<Request> argumentCaptor = ArgumentCaptor.forClass(Request.class);
      verify(httpClient).newCall(argumentCaptor.capture());
      Headers requestHeaders = argumentCaptor.getValue().headers();
      assertThat(requestHeaders.size()).isEqualTo(2);
      assertThat(requestHeaders.get("Accept")).isEqualTo("text/plain");
      assertThat(requestHeaders.get("User-Agent")).isEqualTo("React test agent/1.0");
    }
test_case.class_method_signature: NetworkingModuleTest.testHeaders()
test_case.full_signature: @Test public void testHeaders()
test_case.identifier: testHeaders
test_case.invocations: mock thenAnswer when newCall any mock asList of of sendRequest mock from forClass newCall verify capture headers getValue isEqualTo assertThat size isEqualTo assertThat get isEqualTo assertThat get
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testHeaders()
focal_class.declarator: CONTENT_ENCODING_HEADER_NAME = "content-encoding"
focal_class.modifier: private static final
focal_class.original_string: private static final String CONTENT_ENCODING_HEADER_NAME = "content-encoding";
focal_class.type: String
focal_class.var_name: CONTENT_ENCODING_HEADER_NAME
focal_class.declarator: CONTENT_TYPE_HEADER_NAME = "content-type"
focal_class.modifier: private static final
focal_class.original_string: private static final String CONTENT_TYPE_HEADER_NAME = "content-type";
focal_class.type: String
focal_class.var_name: CONTENT_TYPE_HEADER_NAME
focal_class.declarator: REQUEST_BODY_KEY_STRING = "string"
focal_class.modifier: private static final
focal_class.original_string: private static final String REQUEST_BODY_KEY_STRING = "string";
focal_class.type: String
focal_class.var_name: REQUEST_BODY_KEY_STRING
focal_class.declarator: REQUEST_BODY_KEY_URI = "uri"
focal_class.modifier: private static final
focal_class.original_string: private static final String REQUEST_BODY_KEY_URI = "uri";
focal_class.type: String
focal_class.var_name: REQUEST_BODY_KEY_URI
focal_class.declarator: REQUEST_BODY_KEY_FORMDATA = "formData"
focal_class.modifier: private static final
focal_class.original_string: private static final String REQUEST_BODY_KEY_FORMDATA = "formData";
focal_class.type: String
focal_class.var_name: REQUEST_BODY_KEY_FORMDATA
focal_class.declarator: USER_AGENT_HEADER_NAME = "user-agent"
focal_class.modifier: private static final
focal_class.original_string: private static final String USER_AGENT_HEADER_NAME = "user-agent";
focal_class.type: String
focal_class.var_name: USER_AGENT_HEADER_NAME
focal_class.declarator: MIN_BUFFER_SIZE = 8 * 1024
focal_class.modifier: private static final
focal_class.original_string: private static final int MIN_BUFFER_SIZE = 8 * 1024;
focal_class.type: int
focal_class.var_name: MIN_BUFFER_SIZE
focal_class.declarator: MAX_BUFFER_SIZE = 512 * 1024
focal_class.modifier: private static final
focal_class.original_string: private static final int MAX_BUFFER_SIZE = 512 * 1024;
focal_class.type: int
focal_class.var_name: MAX_BUFFER_SIZE
focal_class.declarator: CHUNK_TIMEOUT_NS = 100 * 1000000
focal_class.modifier: private static final
focal_class.original_string: private static final int CHUNK_TIMEOUT_NS = 100 * 1000000;
focal_class.type: int
focal_class.var_name: CHUNK_TIMEOUT_NS
focal_class.declarator: mClient
focal_class.modifier: private final
focal_class.original_string: private final OkHttpClient mClient;
focal_class.type: OkHttpClient
focal_class.var_name: mClient
focal_class.declarator: mCookieHandler
focal_class.modifier: private final
focal_class.original_string: private final ForwardingCookieHandler mCookieHandler;
focal_class.type: ForwardingCookieHandler
focal_class.var_name: mCookieHandler
focal_class.declarator: mDefaultUserAgent
focal_class.modifier: private final @Nullable
focal_class.original_string: private final @Nullable String mDefaultUserAgent;
focal_class.type: String
focal_class.var_name: mDefaultUserAgent
focal_class.declarator: mShuttingDown
focal_class.modifier: private
focal_class.original_string: private boolean mShuttingDown;
focal_class.type: boolean
focal_class.var_name: mShuttingDown
focal_class.file: node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.java
focal_class.identifier: NetworkingModule
focal_class.class_method_signature: NetworkingModule.NetworkingModule(
        ReactApplicationContext reactContext,
        @Nullable String defaultUserAgent,
        OkHttpClient client)
focal_class.full_signature:   NetworkingModule(
        ReactApplicationContext reactContext,
        @Nullable String defaultUserAgent,
        OkHttpClient client)
focal_class.identifier: NetworkingModule
focal_class.parameters: (
        ReactApplicationContext reactContext,
        @Nullable String defaultUserAgent,
        OkHttpClient client)
focal_class.signature:  NetworkingModule(
        ReactApplicationContext reactContext,
        @Nullable String defaultUserAgent,
        OkHttpClient client)
focal_class.class_method_signature: NetworkingModule.NetworkingModule(final ReactApplicationContext context)
focal_class.full_signature: public  NetworkingModule(final ReactApplicationContext context)
focal_class.identifier: NetworkingModule
focal_class.modifiers: public
focal_class.parameters: (final ReactApplicationContext context)
focal_class.signature:  NetworkingModule(final ReactApplicationContext context)
focal_class.class_method_signature: NetworkingModule.NetworkingModule(ReactApplicationContext context, String defaultUserAgent)
focal_class.full_signature: public  NetworkingModule(ReactApplicationContext context, String defaultUserAgent)
focal_class.identifier: NetworkingModule
focal_class.modifiers: public
focal_class.parameters: (ReactApplicationContext context, String defaultUserAgent)
focal_class.signature:  NetworkingModule(ReactApplicationContext context, String defaultUserAgent)
focal_class.class_method_signature: NetworkingModule.NetworkingModule(ReactApplicationContext reactContext, OkHttpClient client)
focal_class.full_signature: public  NetworkingModule(ReactApplicationContext reactContext, OkHttpClient client)
focal_class.identifier: NetworkingModule
focal_class.modifiers: public
focal_class.parameters: (ReactApplicationContext reactContext, OkHttpClient client)
focal_class.signature:  NetworkingModule(ReactApplicationContext reactContext, OkHttpClient client)
focal_class.class_method_signature: NetworkingModule.initialize()
focal_class.full_signature: @Override public void initialize()
focal_class.identifier: initialize
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void initialize()
focal_class.class_method_signature: NetworkingModule.getName()
focal_class.full_signature: @Override public String getName()
focal_class.identifier: getName
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: String
focal_class.signature: String getName()
focal_class.class_method_signature: NetworkingModule.onCatalystInstanceDestroy()
focal_class.full_signature: @Override public void onCatalystInstanceDestroy()
focal_class.identifier: onCatalystInstanceDestroy
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: void
focal_class.signature: void onCatalystInstanceDestroy()
focal_class.class_method_signature: NetworkingModule.sendRequest(
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)
focal_class.full_signature: @ReactMethod /** * @param timeout value of 0 results in no timeout */ public void sendRequest(
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)
focal_class.identifier: sendRequest
focal_class.modifiers: @ReactMethod /** * @param timeout value of 0 results in no timeout */ public
focal_class.parameters: (
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)
focal_class.return: void
focal_class.signature: void sendRequest(
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)
focal_class.class_method_signature: NetworkingModule.readWithProgress(
        ExecutorToken executorToken,
        int requestId,
        ResponseBody responseBody)
focal_class.full_signature: private void readWithProgress(
        ExecutorToken executorToken,
        int requestId,
        ResponseBody responseBody)
focal_class.identifier: readWithProgress
focal_class.modifiers: private
focal_class.parameters: (
        ExecutorToken executorToken,
        int requestId,
        ResponseBody responseBody)
focal_class.return: void
focal_class.signature: void readWithProgress(
        ExecutorToken executorToken,
        int requestId,
        ResponseBody responseBody)
focal_class.class_method_signature: NetworkingModule.shouldDispatch(long now, long last)
focal_class.full_signature: private static boolean shouldDispatch(long now, long last)
focal_class.identifier: shouldDispatch
focal_class.modifiers: private static
focal_class.parameters: (long now, long last)
focal_class.return: boolean
focal_class.signature: boolean shouldDispatch(long now, long last)
focal_class.class_method_signature: NetworkingModule.getBufferSize(ResponseBody responseBody)
focal_class.full_signature: private static int getBufferSize(ResponseBody responseBody)
focal_class.identifier: getBufferSize
focal_class.modifiers: private static
focal_class.parameters: (ResponseBody responseBody)
focal_class.return: int
focal_class.signature: int getBufferSize(ResponseBody responseBody)
focal_class.class_method_signature: NetworkingModule.onDataReceived(ExecutorToken ExecutorToken, int requestId, String data)
focal_class.full_signature: private void onDataReceived(ExecutorToken ExecutorToken, int requestId, String data)
focal_class.identifier: onDataReceived
focal_class.modifiers: private
focal_class.parameters: (ExecutorToken ExecutorToken, int requestId, String data)
focal_class.return: void
focal_class.signature: void onDataReceived(ExecutorToken ExecutorToken, int requestId, String data)
focal_class.class_method_signature: NetworkingModule.onRequestError(ExecutorToken ExecutorToken, int requestId, String error)
focal_class.full_signature: private void onRequestError(ExecutorToken ExecutorToken, int requestId, String error)
focal_class.identifier: onRequestError
focal_class.modifiers: private
focal_class.parameters: (ExecutorToken ExecutorToken, int requestId, String error)
focal_class.return: void
focal_class.signature: void onRequestError(ExecutorToken ExecutorToken, int requestId, String error)
focal_class.class_method_signature: NetworkingModule.onRequestSuccess(ExecutorToken ExecutorToken, int requestId)
focal_class.full_signature: private void onRequestSuccess(ExecutorToken ExecutorToken, int requestId)
focal_class.identifier: onRequestSuccess
focal_class.modifiers: private
focal_class.parameters: (ExecutorToken ExecutorToken, int requestId)
focal_class.return: void
focal_class.signature: void onRequestSuccess(ExecutorToken ExecutorToken, int requestId)
focal_class.class_method_signature: NetworkingModule.onResponseReceived(
        ExecutorToken ExecutorToken,
        int requestId,
        Response response)
focal_class.full_signature: private void onResponseReceived(
        ExecutorToken ExecutorToken,
        int requestId,
        Response response)
focal_class.identifier: onResponseReceived
focal_class.modifiers: private
focal_class.parameters: (
        ExecutorToken ExecutorToken,
        int requestId,
        Response response)
focal_class.return: void
focal_class.signature: void onResponseReceived(
        ExecutorToken ExecutorToken,
        int requestId,
        Response response)
focal_class.class_method_signature: NetworkingModule.translateHeaders(Headers headers)
focal_class.full_signature: private static WritableMap translateHeaders(Headers headers)
focal_class.identifier: translateHeaders
focal_class.modifiers: private static
focal_class.parameters: (Headers headers)
focal_class.return: WritableMap
focal_class.signature: WritableMap translateHeaders(Headers headers)
focal_class.class_method_signature: NetworkingModule.abortRequest(ExecutorToken executorToken, final int requestId)
focal_class.full_signature: @ReactMethod public void abortRequest(ExecutorToken executorToken, final int requestId)
focal_class.identifier: abortRequest
focal_class.modifiers: @ReactMethod public
focal_class.parameters: (ExecutorToken executorToken, final int requestId)
focal_class.return: void
focal_class.signature: void abortRequest(ExecutorToken executorToken, final int requestId)
focal_class.class_method_signature: NetworkingModule.clearCookies(
        ExecutorToken executorToken,
        com.facebook.react.bridge.Callback callback)
focal_class.full_signature: @ReactMethod public void clearCookies(
        ExecutorToken executorToken,
        com.facebook.react.bridge.Callback callback)
focal_class.identifier: clearCookies
focal_class.modifiers: @ReactMethod public
focal_class.parameters: (
        ExecutorToken executorToken,
        com.facebook.react.bridge.Callback callback)
focal_class.return: void
focal_class.signature: void clearCookies(
        ExecutorToken executorToken,
        com.facebook.react.bridge.Callback callback)
focal_class.class_method_signature: NetworkingModule.supportsWebWorkers()
focal_class.full_signature: @Override public boolean supportsWebWorkers()
focal_class.identifier: supportsWebWorkers
focal_class.modifiers: @Override public
focal_class.parameters: ()
focal_class.return: boolean
focal_class.signature: boolean supportsWebWorkers()
focal_class.class_method_signature: NetworkingModule.constructMultipartBody(
        ExecutorToken ExecutorToken,
        ReadableArray body,
        String contentType,
        int requestId)
focal_class.full_signature: private @Nullable MultipartBuilder constructMultipartBody(
        ExecutorToken ExecutorToken,
        ReadableArray body,
        String contentType,
        int requestId)
focal_class.identifier: constructMultipartBody
focal_class.modifiers: private @Nullable
focal_class.parameters: (
        ExecutorToken ExecutorToken,
        ReadableArray body,
        String contentType,
        int requestId)
focal_class.return: MultipartBuilder
focal_class.signature: MultipartBuilder constructMultipartBody(
        ExecutorToken ExecutorToken,
        ReadableArray body,
        String contentType,
        int requestId)
focal_class.class_method_signature: NetworkingModule.extractHeaders(
        @Nullable ReadableArray headersArray,
        @Nullable ReadableMap requestData)
focal_class.full_signature: private @Nullable Headers extractHeaders(
        @Nullable ReadableArray headersArray,
        @Nullable ReadableMap requestData)
focal_class.identifier: extractHeaders
focal_class.modifiers: private @Nullable
focal_class.parameters: (
        @Nullable ReadableArray headersArray,
        @Nullable ReadableMap requestData)
focal_class.return: Headers
focal_class.signature: Headers extractHeaders(
        @Nullable ReadableArray headersArray,
        @Nullable ReadableMap requestData)
focal_class.class_method_signature: NetworkingModule.getEventEmitter(ExecutorToken ExecutorToken)
focal_class.full_signature: private DeviceEventManagerModule.RCTDeviceEventEmitter getEventEmitter(ExecutorToken ExecutorToken)
focal_class.identifier: getEventEmitter
focal_class.modifiers: private
focal_class.parameters: (ExecutorToken ExecutorToken)
focal_class.return: DeviceEventManagerModule.RCTDeviceEventEmitter
focal_class.signature: DeviceEventManagerModule.RCTDeviceEventEmitter getEventEmitter(ExecutorToken ExecutorToken)
focal_class.superclass: extends ReactContextBaseJavaModule
focal_method.body: @ReactMethod
    /**
     * @param timeout value of 0 results in no timeout
     */
    public void sendRequest(
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout) {
      Request.Builder requestBuilder = new Request.Builder().url(url);
  
      if (requestId != 0) {
        requestBuilder.tag(requestId);
      }
  
      OkHttpClient client = mClient;
      // If the current timeout does not equal the passed in timeout, we need to clone the existing
      // client and set the timeout explicitly on the clone.  This is cheap as everything else is
      // shared under the hood.
      // See https://github.com/square/okhttp/wiki/Recipes#per-call-configuration for more information
      if (timeout != mClient.getConnectTimeout()) {
        client = mClient.clone();
        client.setReadTimeout(timeout, TimeUnit.MILLISECONDS);
      }
  
      Headers requestHeaders = extractHeaders(headers, data);
      if (requestHeaders == null) {
        onRequestError(executorToken, requestId, "Unrecognized headers format");
        return;
      }
      String contentType = requestHeaders.get(CONTENT_TYPE_HEADER_NAME);
      String contentEncoding = requestHeaders.get(CONTENT_ENCODING_HEADER_NAME);
      requestBuilder.headers(requestHeaders);
  
      if (data == null) {
        requestBuilder.method(method, RequestBodyUtil.getEmptyBody(method));
      } else if (data.hasKey(REQUEST_BODY_KEY_STRING)) {
        if (contentType == null) {
          onRequestError(
              executorToken,
              requestId,
              "Payload is set but no content-type header specified");
          return;
        }
        String body = data.getString(REQUEST_BODY_KEY_STRING);
        MediaType contentMediaType = MediaType.parse(contentType);
        if (RequestBodyUtil.isGzipEncoding(contentEncoding)) {
          RequestBody requestBody = RequestBodyUtil.createGzip(contentMediaType, body);
          if (requestBody == null) {
            onRequestError(executorToken, requestId, "Failed to gzip request body");
            return;
          }
          requestBuilder.method(method, requestBody);
        } else {
          requestBuilder.method(method, RequestBody.create(contentMediaType, body));
        }
      } else if (data.hasKey(REQUEST_BODY_KEY_URI)) {
        if (contentType == null) {
          onRequestError(
              executorToken,
              requestId,
              "Payload is set but no content-type header specified");
          return;
        }
        String uri = data.getString(REQUEST_BODY_KEY_URI);
        InputStream fileInputStream =
            RequestBodyUtil.getFileInputStream(getReactApplicationContext(), uri);
        if (fileInputStream == null) {
          onRequestError(executorToken, requestId, "Could not retrieve file for uri " + uri);
          return;
        }
        requestBuilder.method(
            method,
            RequestBodyUtil.create(MediaType.parse(contentType), fileInputStream));
      } else if (data.hasKey(REQUEST_BODY_KEY_FORMDATA)) {
        if (contentType == null) {
          contentType = "multipart/form-data";
        }
        ReadableArray parts = data.getArray(REQUEST_BODY_KEY_FORMDATA);
        MultipartBuilder multipartBuilder =
            constructMultipartBody(executorToken, parts, contentType, requestId);
        if (multipartBuilder == null) {
          return;
        }
        requestBuilder.method(method, multipartBuilder.build());
      } else {
        // Nothing in data payload, at least nothing we could understand anyway.
        requestBuilder.method(method, RequestBodyUtil.getEmptyBody(method));
      }
  
      client.newCall(requestBuilder.build()).enqueue(
          new Callback() {
            @Override
            public void onFailure(Request request, IOException e) {
              if (mShuttingDown) {
                return;
              }
              onRequestError(executorToken, requestId, e.getMessage());
            }
  
            @Override
            public void onResponse(Response response) throws IOException {
              if (mShuttingDown) {
                return;
              }
  
              // Before we touch the body send headers to JS
              onResponseReceived(executorToken, requestId, response);
  
              ResponseBody responseBody = response.body();
              try {
                if (useIncrementalUpdates) {
                  readWithProgress(executorToken, requestId, responseBody);
                  onRequestSuccess(executorToken, requestId);
                } else {
                  onDataReceived(executorToken, requestId, responseBody.string());
                  onRequestSuccess(executorToken, requestId);
                }
              } catch (IOException e) {
                onRequestError(executorToken, requestId, e.getMessage());
              }
            }
          });
    }
focal_method.class_method_signature: NetworkingModule.sendRequest(
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)
focal_method.full_signature: @ReactMethod /** * @param timeout value of 0 results in no timeout */ public void sendRequest(
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)
focal_method.identifier: sendRequest
focal_method.invocations: url tag getConnectTimeout clone setReadTimeout extractHeaders onRequestError get get headers method getEmptyBody hasKey onRequestError getString parse isGzipEncoding createGzip onRequestError method method create hasKey onRequestError getString getFileInputStream getReactApplicationContext onRequestError method create parse hasKey getArray constructMultipartBody method build method getEmptyBody enqueue newCall build onRequestError getMessage onResponseReceived body readWithProgress onRequestSuccess onDataReceived string onRequestSuccess onRequestError getMessage
focal_method.modifiers: @ReactMethod /** * @param timeout value of 0 results in no timeout */ public
focal_method.parameters: (
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)
focal_method.return: void
focal_method.signature: void sendRequest(
        final ExecutorToken executorToken,
        String method,
        String url,
        final int requestId,
        ReadableArray headers,
        ReadableMap data,
        final boolean useIncrementalUpdates,
        int timeout)