Skip to content

Commit bab96f2

Browse files
committed
docs(driver): clarify HTTP localhost routing
Fetch cannot reliably set the tenant Host header, so HTTP local development requires a tenant-aware proxy.
1 parent 054ecb5 commit bab96f2

4 files changed

Lines changed: 7 additions & 7 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ const rows = await database.sql({ query: 'SELECT * FROM tracks LIMIT ?', paramet
8686

8787
HTTP has no session. A transaction must be contained in one request; do not split `BEGIN`, writes, and `COMMIT` across `database.sql()` calls. The same applies to temporary tables, `ATTACH`, connection-scoped `PRAGMA` settings, and a later `last_insert_rowid()` call. HTTP construction does not make a network request, so invalid credentials or an unavailable gateway are reported by the first query rather than the constructor callback.
8888

89+
When using a localhost gateway with HTTP, configure a tenant-aware local reverse proxy. Browser and Node Fetch implementations do not reliably allow the driver to set the tenant `Host` header; the WebSocket transport remains the direct localhost option.
90+
8991
## Examples
9092

9193
Check out all the supported platforms with related examples [here](https://github.com/sqlitecloud/sqlitecloud-js/tree/main/examples)!

‎src/drivers/connection-http.ts‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { SQLiteCloudConnection } from './connection'
44
import { decodeGatewayResponse } from './gateway-response'
55
import { buildGatewaySqlUrl } from './gateway-url'
66
import { ErrorCallback, ResultsCallback, SQLiteCloudCommand, SQLiteCloudConfig, SQLiteCloudError } from './types'
7-
import { encodeBigIntMarkers, getAbortError, isBrowser } from './utilities'
7+
import { encodeBigIntMarkers, getAbortError } from './utilities'
88
import { Buffer } from 'buffer'
99

1010
const BASE64_BLOB_TRANSFER_FORMAT = 'base64-blobs-v1'
@@ -123,8 +123,6 @@ export class SQLiteCloudHttpConnection extends SQLiteCloudConnection {
123123
const token = this.config.apikey || this.config.token
124124
const headers: Record<string, string> = { 'Content-Type': 'application/json' }
125125
if (token) headers.Authorization = `Bearer ${token}`
126-
// Browsers intentionally cannot override Host. Local browser development needs a tenant-aware proxy.
127-
if (!isBrowser && this.config.gatewayurl?.includes('localhost') && this.config.host) headers.Host = this.config.host
128126
return headers
129127
}
130128

‎src/drivers/types.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ export interface SQLiteCloudConfig {
106106
*
107107
* Example: with `host: 'crvheg7dhk.g4.sqlite.cloud'` and the default `gatewayurl`,
108108
* the driver opens `wss://crvheg7dhk.g4.gateway.sqlite.cloud:443`. For local
109-
* development, pass a value containing `localhost` (eg `'ws://localhost:4000'`)
110-
* and the driver will route TCP to that target while forwarding `host` as the
111-
* gateway Host header. */
109+
* development, pass a value containing `localhost` (eg `'ws://localhost:4000'`).
110+
* The WebSocket transport forwards `host` as the gateway Host header. Fetch
111+
* forbids that header, so HTTP transport needs a tenant-aware local proxy. */
112112
gatewayurl?: string
113113
/** Preferred blob transfer format when using websocket transport. Defaults to base64-blobs-v1 for new clients. */
114114
websocketBlobFormat?: SQLiteCloudWebsocketBlobTransferFormat

‎test/connection-http-unit.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe('HTTP gateway transport', () => {
5656
'http://localhost:8090/v2/weblite/sql',
5757
expect.objectContaining({
5858
method: 'POST',
59-
headers: expect.objectContaining({ Authorization: 'Bearer secret', 'Content-Type': 'application/json', Host: 'tenant.g4.sqlite.cloud' })
59+
headers: { Authorization: 'Bearer secret', 'Content-Type': 'application/json' }
6060
})
6161
)
6262
expect(JSON.parse(fetchMock.mock.calls[0]?.[1]?.body)).toEqual({

0 commit comments

Comments
 (0)