RFR: bot: modularize HTTP server
Erik Helin
ehelin at openjdk.java.net
Wed May 12 07:28:27 UTC 2021
Hi all,
please review this patch that modularizes the bot HTTP server. The HTTP server featured by the bot runner is currently only used to process webhooks, but I have coming patches that extends it with other functionality. This refactoring make the bot runner start the actual server and then handlers can be configured in a configuration file. A minimal configuration file looks like:
{
"scratch": {
"path": "/tmp/skara/scratch"
},
"storage": {
"path": "/tmp/skara/storage"
},
"runner": {
"interval": "PT10S",
"watchdog": "PT30M",
"concurrency": 2
},
"log": {
"console": {
"level": "FINER"
}
},
"http-server": {
"port": 8080,
"/api": {
"type": "webhook"
}
}
}
Using the above configuration stored in `config.json` the bot runner can then be started as:
$ make bots
$ ./bots/bin/bin/skara-bots $PWD/config.json
The HTTP server can be then be queried using e.g. `curl`:
$ curl --verbose --request POST --data '{"foo": "bar"}' http://localhost:8080/api
Note: Unnecessary use of -X or --request, POST is already inferred.
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Trying 127.0.0.1:8080...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8080 (#0)
> POST /api HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.68.0
> Accept: */*
> Content-Length: 14
> Content-Type: application/x-www-form-urlencoded
>
} [14 bytes data]
* upload completely sent off: 14 out of 14 bytes
* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Date: Wed, 12 May 2021 07:18:50 GMT
< Content-length: 2
<
{ [2 bytes data]
100 16 100 2 100 14 66 466 --:--:-- --:--:-- --:--:-- 533
* Connection #0 to host localhost left intact
{}
I also updated the webhook handler to return `404` if the supplied data cannot be parsed as valid JSON.
Testing:
- [x] Tested manually on Linux x64
Thanks,
Erik
-------------
Commit messages:
- bot: modularize HTTP server
Changes: https://git.openjdk.java.net/skara/pull/1149/files
Webrev: https://webrevs.openjdk.java.net/?repo=skara&pr=1149&range=00
Stats: 128 lines in 3 files changed: 80 ins; 16 del; 32 mod
Patch: https://git.openjdk.java.net/skara/pull/1149.diff
Fetch: git fetch https://git.openjdk.java.net/skara pull/1149/head:pull/1149
PR: https://git.openjdk.java.net/skara/pull/1149
More information about the skara-dev
mailing list