Git Product home page Git Product logo

rawhttp's Introduction

rawhttp

Build Status Documentation

rawhttp is a Go package for making HTTP requests. It intends to fill a niche that https://golang.org/pkg/net/http/ does not cover: having complete control over the requests being sent to the server.

rawhttp purposefully does as little validation as possible, and you can override just about anything about the request; even the line endings.

Warning: This is a work in progress. The API isn't fixed yet.

Full documentation can be found on GoDoc.

Example

req, err := rawhttp.FromURL("POST", "https://httpbin.org")
if err != nil {
	log.Fatal(err)
}

// automatically set the host header
req.AutoSetHost()

req.Method = "PUT"
req.Hostname = "httpbin.org"
req.Port = "443"
req.Path = "/anything"
req.Query = "one=1&two=2"
req.Fragment = "anchor"
req.Proto = "HTTP/1.1"
req.EOL = "\r\n"

req.AddHeader("Content-Type: application/x-www-form-urlencoded")

req.Body = "username=AzureDiamond&password=hunter2"

// automatically set the Content-Length header
req.AutoSetContentLength()

fmt.Printf("%s\n\n", req.String())

resp, err := rawhttp.Do(req)
if err != nil {
	log.Fatal(err)
}

fmt.Printf("< %s\n", resp.StatusLine())
for _, h := range resp.Headers() {
	fmt.Printf("< %s\n", h)
}

fmt.Printf("\n%s\n", resp.Body())
PUT /anything?one=1&two=2#anchor HTTP/1.1
Host: httpbin.org
Content-Type: application/x-www-form-urlencoded
Content-Length: 38

username=AzureDiamond&password=hunter2

< HTTP/1.1 200 OK
< Connection: keep-alive
< Server: meinheld/0.6.1
< Date: Sat, 02 Sep 2017 13:22:06 GMT
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Credentials: true
< X-Powered-By: Flask
< X-Processed-Time: 0.000869989395142
< Content-Length: 443
< Via: 1.1 vegur

{
  "args": {
    "one": "1",
    "two": "2"
  },
  "data": "",
  "files": {},
  "form": {
    "password": "hunter2",
    "username": "AzureDiamond"
  },
  "headers": {
    "Connection": "close",
    "Content-Length": "38",
    "Content-Type": "application/x-www-form-urlencoded",
    "Host": "httpbin.org"
  },
  "json": null,
  "method": "PUT",
  "origin": "123.123.123.123",
  "url": "https://httpbin.org/anything?one=1&two=2"
}

rawhttp's People

Contributors

tomnomnom avatar

Stargazers

 avatar Tsubasa Irisawa avatar Mohan U M  avatar Benjamin Mauss avatar Holiback avatar  avatar itsallpretend avatar Mick avatar Nawel C avatar  avatar  avatar  avatar  avatar Constant Learner avatar  avatar  avatar  avatar Nischal Karki avatar shaochuyu avatar Gitesh Sharma avatar Mr.X avatar  avatar  avatar TheZukul avatar Dekoder avatar Fabian avatar  avatar alpha302 avatar  avatar Leon avatar  avatar Tracy_梓朋 avatar  avatar pyroxenite avatar  avatar tyskill avatar 李三 avatar EvilChen avatar ~ avatar alchu4n avatar ariesike avatar  avatar Jakub avatar Mohammad Iqbal Ahmad avatar Lou1s avatar 无在无不在 avatar  avatar Callisthenes Don avatar Andrey Stepanov avatar Benjamin Ruston avatar E.C. avatar  avatar Alfi Maulana avatar Aan avatar Olivier beg avatar  avatar Marco Lumia avatar  avatar Nico Kokonas avatar  avatar cocoonk1d avatar Anand avatar Angel Valladares avatar Samir avatar reydd avatar 0xfd avatar  avatar  avatar hooman avatar Alireza Ahani avatar Amir Mohammad Jahangirzad avatar Naategh avatar Saad Azghour avatar Yasar Alev avatar b00ls0ck3t avatar Jeff Foley avatar Daehee avatar Will Maier avatar Pham Sy Minh avatar  avatar  avatar  avatar follow avatar CafeNinja avatar  avatar  avatar  avatar motaghipoor avatar Daniel Moretti V. avatar ik5 avatar kick buttowski avatar Eddwin Paz avatar Kevin J avatar Raymond C. Crandall avatar Doru Carastan avatar  avatar Dr. Gupta avatar N@\/ee/\/ avatar  avatar  avatar

Watchers

 avatar James Cloos avatar StaticBunny avatar Anand avatar  avatar  avatar  avatar

rawhttp's Issues

ReadAll function failed to read

Hi @tomnomnom,

This issue could be related to #5.

I had some timeout problems using your tool so I tried to investigate a bit to fix it. Fixing the timeout to 5s didn't resolve my problem (with req.Timeout = time.Second * 5). However, I have seen that the timeout wasn't the problem but the hang came from the ReadAll function. When its passed here and it arrives here.

Even reading byte by byte the problem occured:

} else {

	for {
		v, err := r.ReadByte()
		if v == 0 || err != nil {
			break
		}
        resp.body = append(resp.body, v)
    }
}

I try to manage to check the size before reading the buffer but without success. Right now, I have removed the else condition to be sure it does not hang out.

Thanks again for all your tools, your doing an amazing work.

No handling of redirects

Hi there,
I’m migrating part of my workflow to meg and it just occurred to me that the rawHttp library doesn’t handle redirects as of now.
Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.