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
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto/ed25519"
|
"crypto/ed25519"
|
||||||
|
|
@ -17,12 +18,13 @@ import (
|
||||||
|
|
||||||
var requestFrom = flag.String("from", "", "the server name that the request should originate from")
|
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 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() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if requestFrom == nil || *requestFrom == "" {
|
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:")
|
fmt.Println("supported flags:")
|
||||||
flag.PrintDefaults()
|
flag.PrintDefaults()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
@ -59,12 +61,36 @@ func main() {
|
||||||
panic(err)
|
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(
|
req := gomatrixserverlib.NewFederationRequest(
|
||||||
"GET",
|
method,
|
||||||
gomatrixserverlib.ServerName(u.Host),
|
gomatrixserverlib.ServerName(u.Host),
|
||||||
u.RequestURI(),
|
u.RequestURI(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if *requestPost {
|
||||||
|
if err = req.SetContent(bodyObj); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if err = req.Sign(
|
if err = req.Sign(
|
||||||
gomatrixserverlib.ServerName(*requestFrom),
|
gomatrixserverlib.ServerName(*requestFrom),
|
||||||
gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
gomatrixserverlib.KeyID(keyBlock.Headers["Key-ID"]),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue