Skip to content

projectdiscovery/rawhttp

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
October 10, 2022 11:13
fix
November 17, 2022 10:53
February 8, 2023 19:32
January 30, 2021 12:35
November 17, 2022 17:53
February 8, 2023 19:32
July 25, 2022 09:42
February 8, 2023 19:32
February 8, 2023 19:32

rawhttp

rawhttp is a Go package for making HTTP requests in a raw way.

Example

First you need to declare a server

...
...

func headers(w http.ResponseWriter, req *http.Request) {
	for name, headers := range req.Header {
		for _, h := range headers {
			fmt.Fprintf(w, "%v: %v\n", name, h)
		}
	}
}

func main() {
	http.HandleFunc("/headers", headers)
	if err := http.ListenAndServe(":10000", nil); err != nil {
		gologger.Fatal().Msgf("Could not listen and serve: %s\n", err)
	}
}
go run server.go

Second you need to start the client

func main() {
    host := "127.0.0.1:10000"
	swg := sizedwaitgroup.New(25)
	pipeOptions := rawhttp.DefaultPipelineOptions
	pipeOptions.Host = host
	pipeOptions.MaxConnections = 1
	pipeclient := rawhttp.NewPipelineClient(pipeOptions)
	for i := 0; i < 50; i++ {
		swg.Add()
		go func(swg *sizedwaitgroup.SizedWaitGroup) {
			defer swg.Done()
			req, err := http.NewRequest("GET", host + "/headers", nil)
			if err != nil {
				log.Printf("Error sending request to API endpoint. %+v", err)
				return
			}
			req.Host = host
			req.Header.Set("Host", host)
			resp, err := pipeclient.Do(req)
			if err != nil {
				log.Printf("Error sending request to API endpoint. %+v", err)
				return
			}
			log.Printf("%+v\n", resp)
			_ = resp
		}(&swg)
	}

	swg.Wait()

}
go run client.go

License

rawhttp is distributed under MIT License

About

Raw HTTP client in Go for complete request control and customization.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages