Skip to content

Commit 63dcf5c

Browse files
authored
Fix http header reader in Go runner (#151)
* Fix http heaer * Fix for format
1 parent c9beec2 commit 63dcf5c

File tree

3 files changed

+72
-39
lines changed

3 files changed

+72
-39
lines changed

desktop/panel/http.test.js

Lines changed: 62 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const USERDATA_FILES = ['json', 'xlsx', 'csv', 'parquet', 'jsonl'];
3232
const PORT = '9799';
3333

3434
let server;
35+
// Kill the existing server if it wasn't killed correctly already.
3536
beforeAll(async () => {
3637
// TODO: port this logic to other platforms...
3738
if (process.platform === 'linux') {
@@ -44,6 +45,7 @@ beforeAll(async () => {
4445
}
4546
}
4647

48+
// Start a new server for all tests
4749
server = spawn('python3', ['-m', 'http.server', PORT]);
4850
let ready = false;
4951
server.on('spawn', () => {
@@ -206,43 +208,69 @@ for (const subprocessName of RUNNERS) {
206208
}
207209

208210
if (process.platform === 'linux') {
209-
describe(
210-
'eval file over server via ' +
211-
(subprocessName ? subprocessName.go || subprocessName.node : 'memory'),
212-
() => {
213-
test('correct result', () => {
214-
const server = new ServerInfo({
215-
address: 'localhost',
216-
type: 'private-key',
217-
});
218-
const hp = new HTTPPanelInfo(
219-
'',
220-
new HTTPConnectorInfo('', 'http://localhost:9799/testdata/unknown')
221-
);
222-
hp.serverId = server.id;
211+
describe('http with headers', () => {
212+
test('correct result', () => {
213+
const hp = new HTTPPanelInfo(
214+
'',
215+
new HTTPConnectorInfo('', 'http://localhost:9799/testdata/unknown', [
216+
{ name: 'X-Test', value: 'OK' },
217+
])
218+
);
223219

224-
const servers = [server];
225-
const panels = [hp];
220+
const panels = [hp];
226221

227-
return withSavedPanels(
228-
panels,
229-
(project) => {
230-
// Grab result
231-
const value = JSON.parse(
232-
fs
233-
.readFileSync(
234-
getProjectResultsFile(project.projectName) + hp.id
235-
)
236-
.toString()
237-
);
222+
return withSavedPanels(
223+
panels,
224+
(project) => {
225+
// Grab result
226+
const value = JSON.parse(
227+
fs
228+
.readFileSync(
229+
getProjectResultsFile(project.projectName) + hp.id
230+
)
231+
.toString()
232+
);
238233

239-
expect(value).toEqual('hey this is unknown');
240-
},
241-
{ evalPanels: true, subprocessName, servers }
242-
);
243-
}, 30_000);
244-
}
245-
);
234+
expect(value).toEqual('hey this is unknown');
235+
},
236+
{ evalPanels: true, subprocessName }
237+
);
238+
});
239+
});
240+
241+
describe('eval http over server via ' + subprocessName.go, () => {
242+
test('correct result', () => {
243+
const server = new ServerInfo({
244+
address: 'localhost',
245+
type: 'private-key',
246+
});
247+
const hp = new HTTPPanelInfo(
248+
'',
249+
new HTTPConnectorInfo('', 'http://localhost:9799/testdata/unknown')
250+
);
251+
hp.serverId = server.id;
252+
253+
const servers = [server];
254+
const panels = [hp];
255+
256+
return withSavedPanels(
257+
panels,
258+
(project) => {
259+
// Grab result
260+
const value = JSON.parse(
261+
fs
262+
.readFileSync(
263+
getProjectResultsFile(project.projectName) + hp.id
264+
)
265+
.toString()
266+
);
267+
268+
expect(value).toEqual('hey this is unknown');
269+
},
270+
{ evalPanels: true, subprocessName, servers }
271+
);
272+
}, 30_000);
273+
});
246274
}
247275
}
248276

runner/http.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func evalHttpPanel(project *ProjectState, pageIndex int, panel *PanelInfo) error
126126
}
127127

128128
for _, header := range h.Headers {
129-
req.Header.Set(header[0], header[1])
129+
req.Header.Set(header.Name, header.Value)
130130
}
131131

132132
client := &http.Client{}

runner/state.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,16 @@ type DatabaseConnectorInfo struct {
285285
Database DatabaseConnectorInfoDatabase `json:"database" db:"database"`
286286
}
287287

288+
type HttpConnectorInfoHeader struct {
289+
Name string `json:"name"`
290+
Value string `json:"value"`
291+
}
292+
288293
type HttpConnectorInfoHttp struct {
289-
Method string `json:"method" db:"method"`
290-
Url string `json:"url" db:"url"`
291-
ContentTypeInfo ContentTypeInfo `json:"contentTypeInfo" db:"contentTypeInfo"`
292-
Headers [][]string `json:"headers" db:"headers"`
294+
Method string `json:"method" db:"method"`
295+
Url string `json:"url" db:"url"`
296+
ContentTypeInfo ContentTypeInfo `json:"contentTypeInfo" db:"contentTypeInfo"`
297+
Headers []HttpConnectorInfoHeader `json:"headers" db:"headers"`
293298
}
294299

295300
type HttpConnectorInfo struct {

0 commit comments

Comments
 (0)