denoland/deno · error · NodeError

ERR_METHOD_NOT_IMPLEMENTED

ERR_METHOD_NOT_IMPLEMENTED

Error message

The _implicitHeader() method is not implemented

What it means

The base OutgoingMessage implements _implicitHeader() as a stub that throws ERR_METHOD_NOT_IMPLEMENTED. Real subclasses override it: ClientRequest renders the request head (see error 231) and ServerResponse stores status line + headers. The hook is invoked whenever body data must be written before headers were explicitly sent, so the error surfaces only on a raw or incompletely subclassed OutgoingMessage.

Source

Thrown at ext/node/polyfills/_http_outgoing.ts:683

    },
    writable: true,
    enumerable: true,
    configurable: true,
  },
  pipe: {
    __proto__: null,
    value: function pipe() {
      // OutgoingMessage should be write-only. Piping from it is disabled.
      this.emit("error", new ERR_STREAM_CANNOT_PIPE());
    },
    writable: true,
    enumerable: true,
    configurable: true,
  },
  _implicitHeader: {
    __proto__: null,
    value: function _implicitHeader() {
      throw new ERR_METHOD_NOT_IMPLEMENTED("_implicitHeader()");
    },
    writable: true,
    enumerable: true,
    configurable: true,
  },
  _finish: {
    __proto__: null,
    value: function _finish() {
      assert(this.socket);
      this.emit("prefinish");
    },
    writable: true,
    enumerable: true,
    configurable: true,
  },
  // This logic is probably a bit confusing. Let me explain a bit:
  //
  // In both HTTP servers and clients it is possible to queue up several

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Use ClientRequest or ServerResponse instead of raw OutgoingMessage for concrete messages
  2. In a subclass, implement _implicitHeader() to call this._storeHeader(...) with your status/request line and headers
  3. In tests, stub the method explicitly: msg._implicitHeader = () => msg._storeHeader('HTTP/1.1 200 OK\r\n', {})

Example fix

// before
class FakeOutgoing extends OutgoingMessage {}
const m = new FakeOutgoing();
m.write('hi'); // throws

// after
class FakeOutgoing extends OutgoingMessage {
  _implicitHeader() {
    this._storeHeader('HTTP/1.1 200 OK\r\n', { 'content-length': '2' });
  }
}
m.write('hi');
Defensive patterns

Strategy: fallback

Validate before calling

if (typeof msg._implicitHeader !== 'function' || /\[native/.test(String(msg._implicitHeader)) || msg._implicitHeader === OutgoingMessage.prototype._implicitHeader) {
  msg._implicitHeader = () => msg._storeHeader('HTTP/1.1 200 OK\r\n', {});
}

Type guard

const implementsImplicitHeader = (msg) => msg._implicitHeader !== OutgoingMessage.prototype._implicitHeader;

Try / catch

try { msg.write(chunk); } catch (e) { if (e.code === 'ERR_METHOD_NOT_IMPLEMENTED' && /_implicitHeader/.test(e.message)) { msg._implicitHeader = () => msg._storeHeader(head, headers); msg.write(chunk); } else throw e; }

Prevention

When it happens

Trigger: Instantiating OutgoingMessage directly and calling write()/end() without prior _storeHeader; creating a custom subclass (mocks, test doubles, protocol adapters) that overrides _send but not _implicitHeader, then relying on implicit header generation.

Common situations: Test harnesses mocking OutgoingMessage for unit tests of server internals; exotic protocol bridges built on OutgoingMessage instead of ClientRequest/ServerResponse; partial copies of Node internals missing the override after an upgrade.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/3c3c1f089b96b057. Report an issue: GitHub.