|
|
@@ -11,7 +11,7 @@ const corsHeaders = {
|
|
|
*
|
|
|
* This Edge Function acts as a transparent proxy to the ShopRenter API.
|
|
|
* It solves the HTTP version compatibility issue where n8n uses HTTP/2+
|
|
|
- * but ShopRenter API requires HTTP/1.0.
|
|
|
+ * but ShopRenter API requires HTTP/1.1 with Connection: close.
|
|
|
*
|
|
|
* Usage from n8n:
|
|
|
* 1. Set X-ShopRenter-Token header with access token (from ShopRenter OAuth)
|
|
|
@@ -24,11 +24,11 @@ const corsHeaders = {
|
|
|
*/
|
|
|
|
|
|
/**
|
|
|
- * Makes an HTTP/1.0 request using raw TCP/TLS connection
|
|
|
- * This is necessary because ShopRenter API strictly requires HTTP/1.0
|
|
|
- * and Deno's fetch API only supports HTTP/1.1 and HTTP/2
|
|
|
+ * Makes an HTTP/1.1 request using raw TCP/TLS connection
|
|
|
+ * This is necessary because ShopRenter API works with HTTP/1.1
|
|
|
+ * and Deno's fetch API uses HTTP/2 which causes connection issues
|
|
|
*/
|
|
|
-async function makeHttp10Request(
|
|
|
+async function makeHttp11Request(
|
|
|
hostname: string,
|
|
|
path: string,
|
|
|
method: string,
|
|
|
@@ -42,9 +42,9 @@ async function makeHttp10Request(
|
|
|
})
|
|
|
|
|
|
try {
|
|
|
- // Build HTTP/1.0 request
|
|
|
+ // Build HTTP/1.1 request
|
|
|
const requestLines: string[] = [
|
|
|
- `${method} ${path} HTTP/1.0`,
|
|
|
+ `${method} ${path} HTTP/1.1`,
|
|
|
`Host: ${hostname}`,
|
|
|
]
|
|
|
|
|
|
@@ -53,7 +53,7 @@ async function makeHttp10Request(
|
|
|
requestLines.push(`${key}: ${value}`)
|
|
|
}
|
|
|
|
|
|
- // Add Connection: close for HTTP/1.0
|
|
|
+ // Add Connection: close for HTTP/1.1
|
|
|
requestLines.push('Connection: close')
|
|
|
|
|
|
// Empty line to end headers
|
|
|
@@ -66,7 +66,7 @@ async function makeHttp10Request(
|
|
|
|
|
|
const request = requestLines.join('\r\n')
|
|
|
|
|
|
- console.log('[HTTP/1.0] Sending request:', request.split('\r\n').slice(0, 10).join('\n'))
|
|
|
+ console.log('[HTTP/1.1] Sending request:', request.split('\r\n').slice(0, 10).join('\n'))
|
|
|
|
|
|
// Send request
|
|
|
const encoder = new TextEncoder()
|
|
|
@@ -83,7 +83,7 @@ async function makeHttp10Request(
|
|
|
responseData += decoder.decode(buffer.subarray(0, n))
|
|
|
}
|
|
|
|
|
|
- console.log('[HTTP/1.0] Received response length:', responseData.length)
|
|
|
+ console.log('[HTTP/1.1] Received response length:', responseData.length)
|
|
|
|
|
|
// Parse HTTP response
|
|
|
const headerEndIndex = responseData.indexOf('\r\n\r\n')
|
|
|
@@ -117,7 +117,7 @@ async function makeHttp10Request(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- console.log('[HTTP/1.0] Response received:', status, statusText)
|
|
|
+ console.log('[HTTP/1.1] Response received:', status, statusText)
|
|
|
|
|
|
return {
|
|
|
status,
|
|
|
@@ -129,7 +129,7 @@ async function makeHttp10Request(
|
|
|
try {
|
|
|
conn.close()
|
|
|
} catch (e) {
|
|
|
- console.error('[HTTP/1.0] Error closing connection:', e)
|
|
|
+ console.error('[HTTP/1.1] Error closing connection:', e)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -254,10 +254,10 @@ serve(async (req) => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- console.log(`[ShopRenter Proxy] Making HTTP/1.0 request to: ${hostname}${fullPath}`)
|
|
|
+ console.log(`[ShopRenter Proxy] Making HTTP/1.1 request to: ${hostname}${fullPath}`)
|
|
|
|
|
|
- // Make HTTP/1.0 request using raw TCP/TLS connection
|
|
|
- const shopRenterResponse = await makeHttp10Request(
|
|
|
+ // Make HTTP/1.1 request using raw TCP/TLS connection
|
|
|
+ const shopRenterResponse = await makeHttp11Request(
|
|
|
hostname,
|
|
|
fullPath,
|
|
|
req.method,
|