mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-23 14:53:10 -06:00
Add POST support
This commit is contained in:
parent
abb0ffe5d0
commit
6fdc763375
|
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/ed25519"
|
||||
|
|
@ -17,12 +18,13 @@ import (
|
|||
|
||||
var requestFrom = flag.String("from", "", "the server name that the request should originate from")
|
||||
var requestKey = flag.String("key", "matrix_key.pem", "the private key to use when signing the request")
|
||||
var requestPost = flag.Bool("post", false, "send a POST request instead of GET (pipe input into stdin or type followed by Ctrl-D)")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if requestFrom == nil || *requestFrom == "" {
|
||||
fmt.Println("expecting: furl -from ... [-key matrix_key.pem] https://path/to/url")
|
||||
fmt.Println("expecting: furl -from origin.com [-key matrix_key.pem] https://path/to/url")
|
||||
fmt.Println("supported flags:")
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
|
|
@ -59,12 +61,36 @@ func main() {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
var bodyObj interface{}
|
||||
var bodyBytes []byte
|
||||
method := "GET"
|
||||
if *requestPost {
|
||||
method = "POST"
|
||||
fmt.Println("Waiting for JSON input. Press Enter followed by Ctrl-D when done...")
|
||||
|
||||
scan := bufio.NewScanner(os.Stdin)
|
||||
for scan.Scan() {
|
||||
bytes := scan.Bytes()
|
||||
bodyBytes = append(bodyBytes, bytes...)
|
||||
}
|
||||
fmt.Println("Done!")
|
||||
if err = json.Unmarshal(bodyBytes, &bodyObj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
req := gomatrixserverlib.NewFederationRequest(
|
||||
"GET",
|
||||
method,
|
||||
gomatrixserverlib.ServerName(u.Host),
|
||||
u.RequestURI(),
|
||||
)
|
||||
|
||||
if *requestPost {
|
||||
if err = req.SetContent(bodyObj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err = req.Sign(
|
||||
gomatrixserverlib.ServerName(*requestFrom),
|
||||
gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
||||
|
|
|
|||
Loading…
Reference in a new issue