@@ -10,6 +10,7 @@ local STRING_UTILS = require("kulala.utils.string")
10
10
local CURL_FORMAT_FILE = FS .get_plugin_path ({ " parser" , " curl-format.json" })
11
11
local Logger = require (" kulala.logger" )
12
12
local StringVariablesParser = require (" kulala.parser.string_variables_parser" )
13
+ local utils = require (" kulala.utils.table" )
13
14
14
15
local M = {}
15
16
@@ -18,27 +19,27 @@ M.scripts.javascript = require("kulala.parser.scripts.javascript")
18
19
19
20
--- @class Request
20
21
--- @field metadata { name : string , value : string } [] -- Metadata of the request
22
+ --- @field environment table<string , string | number> -- The environment- and document-variables
21
23
--- @field method string -- The HTTP method of the request
22
- --- @field grpc GrpcCommand | nil -- The gRPC command
23
- --- @field url_raw string -- The raw URL as it appears in the document
24
24
--- @field url string -- The URL with variables and dynamic variables replaced
25
+ --- @field url_raw string -- The raw URL as it appears in the document
26
+ --- @field http_version string -- The HTTP version of the request
25
27
--- @field headers table<string , string> -- The headers with variables and dynamic variables replaced
26
- --- @field headers_display table<string , string> -- The headers with variables and dynamic variables replaced and sanitized
27
28
--- @field headers_raw table<string , string> -- The headers as they appear in the document
29
+ --- @field headers_display table<string , string> -- The headers with variables and dynamic variables replaced and sanitized
30
+ --- @field ft string -- The filetype of the document
28
31
--- @field cookie string -- The cookie as it appears in the document
32
+ --- @field body string | nil -- The body with variables and dynamic variables replaced
29
33
--- @field body_raw string | nil -- The raw body as it appears in the document
30
34
--- @field body_computed string | nil -- The computed body as sent by curl ; with variables and dynamic variables replaced
31
35
--- @field body_display string | nil -- The body with variables and dynamic variables replaced and sanitized
32
36
--- (e.g. with binary files replaced with a placeholder)
33
- --- @field body string | nil -- The body with variables and dynamic variables replaced
34
- --- @field environment table<string , string | number> -- The environment- and document-variables
35
- --- @field cmd string[] -- The command to execute the request
36
- --- @field ft string -- The filetype of the document
37
- --- @field http_version string -- The HTTP version of the request
38
37
--- @field show_icon_line_number number | nil -- The line number to show the icon
39
- --- @field scripts Scripts -- The scripts to run before and after the request
40
38
--- @field redirect_response_body_to_files ResponseBodyToFile[]
39
+ --- @field scripts Scripts -- The scripts to run before and after the request
40
+ --- @field cmd string[] -- The command to execute the request
41
41
--- @field body_temp_file string -- The path to the temporary file containing the body
42
+ --- @field grpc GrpcCommand | nil -- The gRPC command
42
43
--- @field processed boolean -- Indicates if request has been already processed , used by replay ()
43
44
44
45
--- @class GrpcCommand
@@ -54,38 +55,13 @@ local default_grpc_command = {
54
55
}
55
56
56
57
--- @type Request
58
+ --- @diagnostic disable-next-line : missing-fields
57
59
local default_request = {
58
- metadata = {},
59
- method = " GET" ,
60
- grpc = nil ,
61
- http_version = " " ,
62
- url = " " ,
63
- url_raw = " " ,
64
- headers = {},
60
+ environment = {},
65
61
headers_display = {},
66
- headers_raw = {},
67
- cookie = " " ,
68
- body = nil ,
69
- body_raw = nil ,
70
- body_computed = nil ,
71
- body_display = nil ,
72
- cmd = {},
73
62
ft = " text" ,
74
- environment = {},
75
- redirect_response_body_to_files = {},
76
- scripts = {
77
- pre_request = {
78
- inline = {},
79
- files = {},
80
- },
81
- post_request = {
82
- inline = {},
83
- files = {},
84
- },
85
- },
86
- show_icon_line_number = 1 ,
63
+ cmd = {},
87
64
body_temp_file = " " ,
88
- processed = false
89
65
}
90
66
91
67
local function process_grpc_flags (request , flag , value )
171
147
--- @param document_variables DocumentVariables -- The variables defined in the document
172
148
--- @param silent boolean | nil -- Whether to suppress not found variable warnings
173
149
local process_variables = function (request , document_variables , silent )
150
+ if request .processed then return end
151
+
174
152
local env = ENV_PARSER .get_env () or {}
175
153
local params = { document_variables , env , silent }
176
154
@@ -507,20 +485,12 @@ function M.get_basic_request_data(requests, line_nr)
507
485
508
486
if not document_request then return end
509
487
510
- -- TODO: replace with merge
511
- request .scripts .pre_request = document_request .scripts .pre_request
512
- request .scripts .post_request = document_request .scripts .post_request
513
- request .show_icon_line_number = document_request .show_icon_line_number
514
- request .headers = document_request .headers
515
- request .cookie = document_request .cookie
516
- request .headers_raw = document_request .headers_raw
488
+ request = vim .tbl_extend (" keep" , request , document_request )
489
+
517
490
request .url_raw = document_request .url
518
- request .method = document_request .method
519
- request .http_version = document_request .http_version
520
491
request .body_raw = document_request .body
521
- request .body_display = document_request .body_display
522
- request .metadata = document_request .metadata
523
- request .redirect_response_body_to_files = document_request .redirect_response_body_to_files
492
+
493
+ utils .remove_keys (request , { " body" , " variables" , " start_line" , " end_line" })
524
494
525
495
return request
526
496
end
0 commit comments