cloudflare-tcp-fetcher
Advanced tools
Comparing version 0.9.1 to 0.9.2
@@ -1,7 +0,13 @@ | ||
import { fetchUsingTcp } from "cloudflare-tcp-fetcher"; | ||
import { fetchUsingTcp } from "../../src/index"; | ||
export default { | ||
async fetch(request: Request, env: never, ctx: ExecutionContext): Promise<Response> { | ||
return fetchUsingTcp("https://google.com"); | ||
const response = await fetchUsingTcp("https://httpbin.org/delete", { | ||
method: "DELETE" | ||
}); | ||
return Response.json({ | ||
body: await response.json() | ||
}); | ||
}, | ||
}; |
{ | ||
"name": "cloudflare-tcp-fetcher", | ||
"version": "0.9.1", | ||
"version": "0.9.2", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -12,5 +12,22 @@ # cloudflare-tcp-fetcher | ||
### Using the fetchUsingTcp function | ||
You can also input the TcpFetcher in the `init` object to reuse a connection. | ||
```ts | ||
import { fetchUsingTcp } from "cloudflare-tcp-fetcher"; | ||
export default { | ||
async fetch(request: Request, env: never, ctx: ExecutionContext): Promise<Response> { | ||
return fetchUsingTcp("https://google.com", { | ||
method: "GET" | ||
}); | ||
} | ||
} | ||
``` | ||
### Using the TcpFetcher class | ||
You can re-use the TcpFetcher class until the worker is closed. | ||
> Note: you can not use the `TcpFetcher` instance with `fetch` because the worker will complain that `TcpFetcher` is not an instance of `Fetcher` :/ | ||
```ts | ||
@@ -20,3 +37,3 @@ import { TcpFetcher } from "cloudflare-tcp-fetcher"; | ||
export default { | ||
async fetch(request: Request, env: never, ctx: ExecutionContext): Promise<Response> { | ||
async fetch(request: Request, env: never, ctx: ExecutionContext): Promise<Response> { | ||
const fetcher = new TcpFetcher(); | ||
@@ -30,16 +47,1 @@ | ||
``` | ||
### Using the fetchUsingTcp function | ||
You can also input the TcpFetcher in the `init` object to reuse a connection. | ||
```ts | ||
import { fetchUsingTcp } from "cloudflare-tcp-fetcher"; | ||
export default { | ||
async fetch(request: Request, env: never, ctx: ExecutionContext): Promise<Response> { | ||
return fetchUsingTcp("https://google.com", { | ||
method: "GET" | ||
}); | ||
} | ||
} | ||
``` |
@@ -33,3 +33,3 @@ import { connect } from 'cloudflare:sockets'; | ||
write(`GET ${url.pathname}${url.search}${url.hash} HTTP/1.1\r\n`); | ||
write(`${request.method} ${url.pathname}${url.search}${url.hash} HTTP/1.1\r\n`); | ||
write(`Host: ${url.host}\r\n`); | ||
@@ -36,0 +36,0 @@ |
103179
1634
45