|
|
@@ -78,9 +78,20 @@ async function makeHttp11Request(
|
|
|
let responseData = ''
|
|
|
|
|
|
while (true) {
|
|
|
- const n = await conn.read(buffer)
|
|
|
- if (n === null) break
|
|
|
- responseData += decoder.decode(buffer.subarray(0, n))
|
|
|
+ try {
|
|
|
+ const n = await conn.read(buffer)
|
|
|
+ if (n === null) break
|
|
|
+ responseData += decoder.decode(buffer.subarray(0, n))
|
|
|
+ } catch (e) {
|
|
|
+ // Handle UnexpectedEof during read - connection closed by server
|
|
|
+ // This is expected when server sends Connection: close
|
|
|
+ if (e instanceof Deno.errors.UnexpectedEof ||
|
|
|
+ (e instanceof Error && e.name === 'UnexpectedEof')) {
|
|
|
+ console.log('[HTTP/1.1] Connection closed by server (expected with Connection: close)')
|
|
|
+ break
|
|
|
+ }
|
|
|
+ throw e
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
console.log('[HTTP/1.1] Received response length:', responseData.length)
|
|
|
@@ -129,7 +140,14 @@ async function makeHttp11Request(
|
|
|
try {
|
|
|
conn.close()
|
|
|
} catch (e) {
|
|
|
- console.error('[HTTP/1.1] Error closing connection:', e)
|
|
|
+ // Gracefully handle connection closure errors
|
|
|
+ // UnexpectedEof during close means server already closed the connection
|
|
|
+ if (e instanceof Deno.errors.UnexpectedEof ||
|
|
|
+ (e instanceof Error && e.name === 'UnexpectedEof')) {
|
|
|
+ console.log('[HTTP/1.1] Connection already closed by server')
|
|
|
+ } else {
|
|
|
+ console.error('[HTTP/1.1] Error closing connection:', e)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|