request_debug

package
v0.81.0-dev-2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:     "request-debug",
	Short:   "Return request degbug information",
	Aliases: []string{"req", "request", "rd"},
	Args:    cobra.NoArgs,
	Run: func(c *cobra.Command, args []string) {
		http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
			var err error
			rr := &Request{}
			rr.Method = r.Method
			rr.Headers = r.Header
			rr.URL = r.URL.String()
			rr.Body, err = io.ReadAll(r.Body)
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}

			rrb, err := json.Marshal(rr)
			if err != nil {
				http.Error(w, err.Error(), http.StatusInternalServerError)
				return
			}

			w.Header().Set("Content-Type", "application/json")
			w.Write(rrb)
			fmt.Println(string(rrb))
		})
		fmt.Println("Server started on 0.0.0.0:8000, see http://127.0.0.1:8000")
		http.ListenAndServe(":8000", nil)
	},
}

Functions

This section is empty.

Types

type Request

type Request struct {
	URL     string      `json:"url"`
	Method  string      `json:"method"`
	Headers http.Header `json:"headers"`
	Body    []byte      `json:"body"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL