Skip to content

Commit ca9a428

Browse files
authored
fix(utils): handle 1xx HTTP status codes in curl utils (#1540)
Update the curl utility to treat 1xx (informational) HTTP status codes, such as 100 (Continue), as non-errors in both GET and POST requests. Previously, only 2xx (success) codes were considered valid, which could cause issues with streaming or intermediate responses. This change improves compatibility with APIs that use informational status codes. Closes #1508
1 parent aeb6ebb commit ca9a428

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lua/CopilotChat/utils/curl.lua

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ M.get = async.wrap(function(url, opts, callback)
4848

4949
args.callback = function(response)
5050
log.debug('GET response:', response)
51-
if response and not vim.startswith(tostring(response.status), '20') then
51+
-- HTTP status codes: 1xx (informational), 2xx (success)
52+
-- Status 100 (Continue) is common with streaming responses
53+
local status_str = tostring(response.status)
54+
if response and not vim.startswith(status_str, '1') and not vim.startswith(status_str, '20') then
5255
callback(response, response.body)
5356
return
5457
end
@@ -96,7 +99,10 @@ M.post = async.wrap(function(url, opts, callback)
9699
log.debug('Failed to remove temp file:', temp_file_path, err)
97100
end
98101
end
99-
if response and not vim.startswith(tostring(response.status), '20') then
102+
-- HTTP status codes: 1xx (informational), 2xx (success)
103+
-- Status 100 (Continue) is common with streaming responses
104+
local status_str = tostring(response.status)
105+
if response and not vim.startswith(status_str, '1') and not vim.startswith(status_str, '20') then
100106
callback(response, response.body)
101107
return
102108
end

0 commit comments

Comments
 (0)