9595-- @param end_line Line where the request ends
9696local function get_headers (bufnr , start_line , end_line )
9797 local headers = {}
98- local body_start = end_line
98+ local headers_end = end_line
9999
100100 -- Iterate over all buffer lines starting after the request line
101101 for line_number = start_line + 1 , end_line do
@@ -105,7 +105,7 @@ local function get_headers(bufnr, start_line, end_line)
105105 -- message header and message body are seperated by CRLF (see RFC 2616)
106106 -- for our purpose also the next request line will stop the header search
107107 if is_request_line (line_content ) or line_content == " " then
108- body_start = line_number
108+ headers_end = line_number
109109 break
110110 end
111111 if not line_content :find (" :" ) then
@@ -123,7 +123,32 @@ local function get_headers(bufnr, start_line, end_line)
123123 :: continue::
124124 end
125125
126- return headers , body_start
126+ return headers , headers_end
127+ end
128+
129+ -- get_curl_args finds command line flags and returns a lua table with them
130+ -- @param bufnr Buffer number, a.k.a id
131+ -- @param headers_end Line where the headers end
132+ -- @param end_line Line where the request ends
133+ local function get_curl_args (bufnr , headers_end , end_line )
134+ local curl_args = {}
135+ local body_start = end_line
136+
137+ for line_number = headers_end , end_line do
138+ local line = vim .fn .getbufline (bufnr , line_number )
139+ local line_content = line [1 ]
140+
141+ if line_content :find (" ^ *%-%-?[a-zA-Z%-]+" ) then
142+ table.insert (curl_args , line_content )
143+ elseif not line_content :find (" ^ *$" ) then
144+ if line_number ~= end_line then
145+ body_start = line_number - 1
146+ end
147+ break
148+ end
149+ end
150+
151+ return curl_args , body_start
127152end
128153
129154-- start_request will find the request line (e.g. POST http://localhost:8081/foo)
@@ -159,6 +184,11 @@ local function end_request(bufnr)
159184 if next == 0 or (oldlinenumber == last_line ) then
160185 return last_line
161186 else
187+ -- skip comment lines above requests
188+ while vim .fn .getline (next - 1 ):find (" ^ *#" ) do
189+ next = next - 1
190+ end
191+
162192 return next - 1
163193 end
164194end
@@ -191,7 +221,9 @@ M.get_current_request = function()
191221
192222 local parsed_url = parse_url (vim .fn .getline (start_line ))
193223
194- local headers , body_start = get_headers (bufnr , start_line , end_line )
224+ local headers , headers_end = get_headers (bufnr , start_line , end_line )
225+
226+ local curl_args , body_start = get_curl_args (bufnr , headers_end , end_line )
195227
196228 local body = get_body (bufnr , body_start , end_line )
197229
@@ -205,6 +237,7 @@ M.get_current_request = function()
205237 method = parsed_url .method ,
206238 url = parsed_url .url ,
207239 headers = headers ,
240+ raw = curl_args ,
208241 body = body ,
209242 bufnr = bufnr ,
210243 start_line = start_line ,
0 commit comments