audiobookshelf icon indicating copy to clipboard operation
audiobookshelf copied to clipboard

[Bug]: docker use HTTP_PROXY env request error

Open ilwzmf opened this issue 2 years ago • 9 comments

Describe the issue

docker里配置了HTTP_PROXY和HTTPS_PROXY访问任何地址都报错 我需要使用代理才能访问google和部分podcasts 此代理在其他docker使用正常,同样的地址使用此代理在chrome访问正常

Sorry for the bad English, the following is google translation

HTTP_PROXY and HTTPS_PROXY are configured in docker to access any address and report an error I need to use a proxy to access google and some podcasts This proxy is used normally in other dockers, and the same address uses this proxy to access normally in chrome

Steps to reproduce the issue

请求已经到了代理服务器,但返回的都是错误,我不确定是否传的参数有问题

以下为log: Failed Error: Request failed with status code 400 at createError (/node_modules/axios/lib/core/createError.js:16:15) at settle (/node_modules/axios/lib/core/settle.js:17:12) at IncomingMessage.handleStreamEnd (/node_modules/axios/lib/adapters/http.js:322:11) at IncomingMessage.emit (node:events:525:35) at endReadableNT (node:internal/streams/readable:1358:12) at processTicksAndRejections (node:internal/process/task_queues:83:21) { config: { transitional: { silentJSONParsing: true, forcedJSONParsing: true, clarifyTimeoutError: false }, adapter: [Function: httpAdapter], transformRequest: [ [Function: transformRequest] ], transformResponse: [ [Function: transformResponse] ], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus], headers: { Accept: 'application/json, text/plain, /', 'User-Agent': 'axios/0.26.1', host: 'openlibrary.org' }, method: 'get', url: 'https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93', data: undefined }, request: <ref *1> ClientRequest { _events: [Object: null prototype] { abort: [Function (anonymous)], aborted: [Function (anonymous)], connect: [Function (anonymous)], error: [Function (anonymous)], socket: [Function (anonymous)], timeout: [Function (anonymous)], finish: [Function: requestOnFinish] }, _eventsCount: 7, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: false, maxRequestsOnConnectionReached: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: false, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, strictContentLength: false, _contentLength: 0, _hasBody: true, _trailer: '', finished: true, _headerSent: true, _closed: false, socket: Socket { connecting: false, _hadError: false, _parent: null, _host: 'v2fly-uncn', _closeAfterHandlingError: false, _readableState: [ReadableState], _events: [Object: null prototype], _eventsCount: 7, _maxListeners: undefined, _writableState: [WritableState], allowHalfOpen: false, _sockname: null, _pendingData: null, _pendingEncoding: '', server: null, _server: null, parser: null, _httpMessage: [Circular *1], [Symbol(async_id_symbol)]: 55362, [Symbol(kHandle)]: [TCP], [Symbol(lastWriteQueueSize)]: 0, [Symbol(timeout)]: null, [Symbol(kBuffer)]: null, [Symbol(kBufferCb)]: null, [Symbol(kBufferGen)]: null, [Symbol(kCapture)]: false, [Symbol(kSetNoDelay)]: false, [Symbol(kSetKeepAlive)]: true, [Symbol(kSetKeepAliveInitialDelay)]: 60, [Symbol(kBytesRead)]: 0, [Symbol(kBytesWritten)]: 0, [Symbol(RequestTimeout)]: undefined }, _header: 'GET https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93 HTTP/1.1\r\n' + 'Accept: application/json, text/plain, /\r\n' + 'User-Agent: axios/0.26.1\r\n' + 'host: openlibrary.org\r\n' + 'Connection: close\r\n' + '\r\n', _keepAliveTimeout: 0, _onPendingData: [Function: nop], agent: Agent { _events: [Object: null prototype], _eventsCount: 2, _maxListeners: undefined, defaultPort: 80, protocol: 'http:', options: [Object: null prototype], requests: [Object: null prototype] {}, sockets: [Object: null prototype], freeSockets: [Object: null prototype] {}, keepAliveMsecs: 1000, keepAlive: false, maxSockets: Infinity, maxFreeSockets: 256, scheduling: 'lifo', maxTotalSockets: Infinity, totalSocketCount: 1, [Symbol(kCapture)]: false }, socketPath: undefined, method: 'GET', maxHeaderSize: undefined, insecureHTTPParser: undefined, path: 'https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93', _ended: true, res: IncomingMessage { _readableState: [ReadableState], _events: [Object: null prototype], _eventsCount: 4, _maxListeners: undefined, socket: [Socket], httpVersionMajor: 1, httpVersionMinor: 1, httpVersion: '1.1', complete: true, rawHeaders: [Array], rawTrailers: [], aborted: false, upgrade: false, url: '', method: null, statusCode: 400, statusMessage: 'Bad Request', client: [Socket], _consuming: false, _dumped: false, req: [Circular *1], responseUrl: 'https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93', redirects: [], [Symbol(kCapture)]: false, [Symbol(kHeaders)]: [Object], [Symbol(kHeadersCount)]: 14, [Symbol(kTrailers)]: null, [Symbol(kTrailersCount)]: 0, [Symbol(RequestTimeout)]: undefined }, aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, host: 'v2fly-uncn', protocol: 'http:', _redirectable: Writable { _writableState: [WritableState], _events: [Object: null prototype], _eventsCount: 3, _maxListeners: undefined, _options: [Object], _ended: true, _ending: true, _redirectCount: 0, _redirects: [], _requestBodyLength: 0, _requestBodyBuffers: [], _onNativeResponse: [Function (anonymous)], _currentRequest: [Circular *1], _currentUrl: 'https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93', [Symbol(kCapture)]: false }, [Symbol(kCapture)]: false, [Symbol(kBytesWritten)]: 0, [Symbol(kEndCalled)]: true, [Symbol(kNeedDrain)]: false, [Symbol(corked)]: 0, [Symbol(kOutHeaders)]: [Object: null prototype] { accept: [Array], 'user-agent': [Array], host: [Array] }, [Symbol(kUniqueHeaders)]: null }, response: { status: 400, statusText: 'Bad Request', headers: { 'content-length': '264', connection: 'keep-alive', 'content-type': 'text/html', date: 'Sat, 24 Dec 2022 10:11:24 GMT', 'keep-alive': 'timeout=4', 'proxy-connection': 'keep-alive', server: 'nginx/1.18.0 (Ubuntu)' }, config: { transitional: [Object], adapter: [Function: httpAdapter], transformRequest: [Array], transformResponse: [Array], timeout: 0, xsrfCookieName: 'XSRF-TOKEN', xsrfHeaderName: 'X-XSRF-TOKEN', maxContentLength: -1, maxBodyLength: -1, validateStatus: [Function: validateStatus], headers: [Object], method: 'get', url: 'https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93', data: undefined }, request: <ref *1> ClientRequest { _events: [Object: null prototype], _eventsCount: 7, _maxListeners: undefined, outputData: [], outputSize: 0, writable: true, destroyed: false, _last: true, chunkedEncoding: false, shouldKeepAlive: false, maxRequestsOnConnectionReached: false, _defaultKeepAlive: true, useChunkedEncodingByDefault: false, sendDate: false, _removedConnection: false, _removedContLen: false, _removedTE: false, strictContentLength: false, _contentLength: 0, _hasBody: true, _trailer: '', finished: true, _headerSent: true, _closed: false, socket: [Socket], _header: 'GET https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93 HTTP/1.1\r\n' + 'Accept: application/json, text/plain, /\r\n' + 'User-Agent: axios/0.26.1\r\n' + 'host: openlibrary.org\r\n' + 'Connection: close\r\n' + '\r\n', _keepAliveTimeout: 0, _onPendingData: [Function: nop], agent: [Agent], socketPath: undefined, method: 'GET', maxHeaderSize: undefined, insecureHTTPParser: undefined, path: 'https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93', _ended: true, res: [IncomingMessage], aborted: false, timeoutCb: null, upgradeOrConnect: false, parser: null, maxHeadersCount: null, reusedSocket: false, host: 'v2fly-uncn', protocol: 'http:', _redirectable: [Writable], [Symbol(kCapture)]: false, [Symbol(kBytesWritten)]: 0, [Symbol(kEndCalled)]: true, [Symbol(kNeedDrain)]: false, [Symbol(corked)]: 0, [Symbol(kOutHeaders)]: [Object: null prototype], [Symbol(kUniqueHeaders)]: null }, data: '\r\n' + '

400 The plain HTTP request was sent to HTTPS port\r\n' + '\r\n' + '

400 Bad Request

\r\n' + '
The plain HTTP request was sent to HTTPS port
\r\n' + '
nginx/1.18.0 (Ubuntu)
\r\n' + '\r\n' + '\r\n' }, isAxiosError: true, toJSON: [Function: toJSON] } [2022-12-24 18:11:24] ERROR: OpenLib Search Error 404

我在bash里可以正确访问,我将地址从https://openlibrary.org//search.json?title=%E4%B8%89%E4%BD%93改为了https://openlibrary.org/search.json?title=%E4%B8%89%E4%BD%93 见如下截图 Snipaste_2022-12-24_21-23-10

Audiobookshelf version

v2.2.11

How are you running audiobookshelf?

Docker

ilwzmf avatar Dec 24 '22 10:12 ilwzmf

I'm not sure what to do here so will need more information on specifically what needs to be done.

advplyr avatar Dec 26 '22 13:12 advplyr

It's maybe a bug about axios.

Using the following code works fine. It might be better to use unity interceptor.

const Axios = require("axios"); const HttpsProxyAgent = require("https-proxy-agent");

const httpsAgent = new HttpsProxyAgent(http://${YOUR_HOST}:${YOUR_PORT}); const axios = Axios.create({ proxy:false, httpsAgent })

ilwzmf avatar Dec 27 '22 06:12 ilwzmf

What would "YOUR_HOST" and "YOUR_PORT" be in your example? How would Abs get that information? Why did you choose to use "http://" for the HttpsProxyAgent?

advplyr avatar Dec 27 '22 21:12 advplyr

The environment variable HTTP_PROXY is common in most dockers. Axios has automatically used the environment variable HTTP_PROXY, but axios has a bug when requesting https links through http proxy.

eg:HTTP_PROXY=http://192.168.1.2:9001 const httpsAgent = new HttpsProxyAgent(process.env.HTTP_PROXY);

I use v2fly, supports socks5 or http proxy. After I tested, I found that axios may not support socks5.

ilwzmf avatar Dec 28 '22 02:12 ilwzmf

Has this issue been fixed?

geekidentity avatar Nov 12 '23 14:11 geekidentity

I don't understand the issue so I added the help wanted tag

advplyr avatar Nov 12 '23 14:11 advplyr

@advplyr What he means is whether it can support the HTTP_PROXY and HTTPS_PROXY environment variables of the Linux system. This is required in the scenario of using VPN.

geekidentity avatar Nov 13 '23 02:11 geekidentity

Support for proxy would be very useful, as there are usecases where the host is behind firewall, requires some proxy setting to access internet.

ykelvis avatar Jan 01 '24 04:01 ykelvis

Looked into it in detail. 2 items on the way:

PR at #2666

zhzy0077 avatar Feb 26 '24 08:02 zhzy0077

I'm having the same problem, has this been resolved now?

[2024-03-04 13:49:55.073] ERROR: [podcastUtils] getPodcastFeed Error Error: Call to 10.1.1.1 is blocked. at agent.createConnection (/node_modules/ssrf-req-filter/lib/index.js:31:13) at Agent.createSocket (node:_http_agent:340:26) at Agent.addRequest (node:_http_agent:288:10) at new ClientRequest (node:_http_client:337:16) at Object.request (node:http:103:10) at RedirectableRequest._performRequest (/node_modules/follow-redirects/index.js:326:24) at new RedirectableRequest (/node_modules/follow-redirects/index.js:100:8) at Object.request (/node_modules/follow-redirects/index.js:532:14) at dispatchHttpRequest (/node_modules/axios/lib/adapters/http.js:262:25) at new Promise (<anonymous>) (podcastUtils.js:265)

asseywang avatar Mar 04 '24 06:03 asseywang