Skip to content

Batch hardcodes ensureHttps: true, ignoring ApiClient protocol option #30

@jmikitova

Description

@jmikitova

Summary

The Batch class unconditionally passes true for ensureHttps in its super() call:

// lib/requests/batch.js, line 25
super('POST', '/batch/', sum_timeouts(requests), true);

This means _buildRequestUrl in ApiClient always uses https for batch requests, even when the client was explicitly configured with protocol: 'http':

// lib/api-client.js, line 105
let usedProtocol = (request.ensureHttps) ? 'https' : this.protocol;

Problem

When using a local mock server (e.g., for development or testing) over HTTP, you configure the client like:

new ApiClient(dbId, token, { baseUri: 'localhost:9300', protocol: 'http' });

Non-batch requests correctly use http://. However, any Batch request ignores the configured protocol and forces https://localhost:9300, causing connection failures.

The only workaround is to mutate the ensureHttps property directly on the Batch instance after construction:

const batch = new Batch(requests);
batch.ensureHttps = false; // force-override the hardcoded value

This is unpleasant for a few reasons:

  • It relies on a property that is not part of the public API and could silently break on any update.
  • It requires every caller to know about this quirk and remember to apply the override.
  • The inconsistency is non-obvious: the ApiClient exposes a protocol option that works for all other request types but is silently ignored for Batch.

Context

The JSDoc on Batch even says the request is "encapsulating a sequence of requests into a single HTTPS request" - which suggests the hardcoded value may be intentional. If so, it would be helpful to document why it must always be HTTPS even when a non-HTTPS protocol is explicitly configured, since this is an unexpected inconsistency between batch and non-batch requests.


Happy to hear if this is intentional and we're simply missing the right way to approach it. Otherwise, we'd appreciate a fix or guidance on the preferred workaround. Thanks for the great library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions