"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_error = require('../primordials/error.js');
const require_http_request_response_types = require('./response-types.js');
const require_http_request_request = require('./request.js');

//#region src/http-request/node.ts
/**
* @file Node-side HTTP request layer — the public surface (`httpJson`,
*   `httpText`, `httpRequest`, `HttpResponseError`) for consumers on Node.
*   Pairs with `./browser` (browser-safe variant via `fetch`); both files
*   expose the same named exports so the package.json `'browser'` condition can
*   swap them by platform without consumers changing their imports. `httpJson`
*   and `httpText` live here directly; `httpRequest` and the shared types are
*   re-exported from their dedicated leaves so the sub-imports
*   (`./http-request/request`, `./http-request/response-types`) stay loadable
*   individually for callers that don't want the convenience wrappers in their
*   bundle.
*/
/**
* GET / POST a JSON endpoint. Automatically sets `Accept: application/json` and
* `Content-Type: application/json` (when a body is present); user-supplied
* headers always win. Throws `HttpResponseError` on non-2xx.
*/
async function httpJson(url, options) {
	const { body, headers = {}, ...restOptions } = {
		__proto__: null,
		...options
	};
	const defaultHeaders = { Accept: "application/json" };
	if (body) defaultHeaders["Content-Type"] = "application/json";
	const response = await require_http_request_request.httpRequest(url, {
		body,
		headers: {
			...defaultHeaders,
			...headers
		},
		...restOptions
	});
	if (!response.ok) throw new require_http_request_response_types.HttpResponseError(response);
	try {
		return response.json();
	} catch (e) {
		throw new require_primordials_error.ErrorCtor("Failed to parse JSON response", { cause: e });
	}
}
/**
* GET / POST a text endpoint. Sets `Accept: text/plain` (and `Content-Type:
* text/plain` on bodies); user headers override. Throws `HttpResponseError` on
* non-2xx.
*/
async function httpText(url, options) {
	const { body, headers = {}, ...restOptions } = {
		__proto__: null,
		...options
	};
	const defaultHeaders = { Accept: "text/plain" };
	if (body) defaultHeaders["Content-Type"] = "text/plain";
	const response = await require_http_request_request.httpRequest(url, {
		body,
		headers: {
			...defaultHeaders,
			...headers
		},
		...restOptions
	});
	if (!response.ok) throw new require_http_request_response_types.HttpResponseError(response);
	return response.text();
}

//#endregion
exports.HttpResponseError = require_http_request_response_types.HttpResponseError;
exports.httpJson = httpJson;
exports.httpRequest = require_http_request_request.httpRequest;
exports.httpText = httpText;