Git Product home page Git Product logo

bat's Introduction

Hi there 👋. You're probably interested in my open source work, so here is a quick summary.

📫 Please open a GitHub issue if you want to discuss something related to an open source project of mine.

Otherwise you can reach me at [email protected]

Last Update: 2022-04-22

Open Source

visitor badge

bat's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bat's Issues

301 redirect issue

when i request http://v.pptv.com with curl command line tool, i got this:

$curl -I http://v.pptv.com
HTTP/1.1 301 Moved Permanently
Date: Wed, 22 Apr 2015 15:02:51 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Cache-Control: no-cache
Location: http://www.pptv.com
Age: 1
Via: http/1.1 shnj-b-ats-157-223-2 (ATS/1.2.2 [uScMsSf pSeN:t cCMi p sS]),  http/1.1 sh-i-ats-8-44-1 (ATS/1.2.0 [uScMsSf pSeN:t cCMi p sS])

but when i try with bat, then:

bat head http://v.pptv.com
HEAD / HTTP/1.1
Host: v.pptv.com
Accept: application/json
Accept-Encoding: gzip, deflate
User-Agent: bat/0.0.2



HTTP/1.1 200 OK
Expires : Wed, 22 Apr 2015 15:21:32 GMT
Age : 278
Connection : keep-alive
Last-Modified : Wed, 22 Apr 2015 15:01:32 GMT
Cache-Control : public, max-age=1200
Vary : Accept-Encoding Accept-Encoding Accept-Encoding Accept-Encoding
Via : http/1.1 shnj-b-ats-157-223-2 (ATS/1.2.2 [uIcRs f p eN:t cCHi p s ]),     http/1.1 sh-i-ats-8-45-1 (ATS/1.2.0 [uScRs f p eN:t cCHi p s ])
Content-Length : 714354
Date : Wed, 22 Apr 2015 15:06:09 GMT
Content-Type : text/html; charset=utf-8
Pragma : public

and i try write a small demo with net/http package, i got the same result with bat, so i guess net/http handle this. but i think return origin redirect info not
redirect directly.

Custom path to certs

My router has read-only file system, so I can copy and run "bat" to external USB.
The problem: I cannot point "bat" the new location of certs. Is there a way to add option for custom certificates directory?

Provide cross-platform build

Releases seems to only feature a compiled OSX version. It's pretty simple to provide a Windows and Linux version by simply supplying GOOS environment variable at compile time. Let me know if you'd like any help -- I love the utility, but would really like to install it on systems which don't have a Go compiler installed more easily.

Thanks

foo:={"bar":"baz"} doesn't work as expected?

The following example results in a string as the value, instead of raw json:

> bat POST :8000 name:='{0:0}'
POST / HTTP/1.1
Host: localhost:8000
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
User-Agent: bat/0.1.0


{"name":"{0:0}"}

The same method with an array instead of an object results in an array, as expected:

> bat POST :8000 name:='[0,0]'
POST / HTTP/1.1
Host: localhost:8000
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
User-Agent: bat/0.1.0


{"name":[0,0]}

HTTPS certificate information

One of my main use cases for curl is to check if https is setup correctly.
Having a flag to show certificate information would be very useful.
Example from curl:

* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=US; ST=California; L=Mountain View; O=Google Inc; CN=*.google.com
*  start date: Jan 10 09:55:43 2018 GMT
*  expire date: Apr  4 09:40:00 2018 GMT
*  subjectAltName: host "google.com" matched cert's "google.com"
*  issuer: C=US; O=Google Inc; CN=Google Internet Authority G2
*  SSL certificate verify ok.

Also having curl --resolve functionality would be super handy.

Thanks for creating a nice tool!

http header

"Range:bytes=0-10" argument parse error:

D:\>bat http://www.baidu.com Range:bytes=0-10
POST / HTTP/1.1
Host: www.baidu.com
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
User-Agent: bat/0.1.0


{"Range:bytes":"0-10"}


HTTP/1.1 200 OK
Set-Cookie : BAIDUID=193BF8F2DA8E3A36695F0FB3BEB7A14A:FG=1; expires=Wed, 12-Apr-
17 05:27:39 GMT; max-age=31536000; path=/; domain=.baidu.com; version=1
P3p : CP=" OTI DSP COR IVA OUR IND COM "
Last-Modified : Mon, 29 Feb 2016 11:11:44 GMT
Connection : Keep-Alive
Content-Type : text/html
Etag : "2bd1-52ce6b6c4bc00"
Accept-Ranges : bytes
Cache-Control : max-age=86400
Vary : Accept-Encoding,User-Agent
Date : Tue, 12 Apr 2016 05:27:39 GMT
Server : Apache
Expires : Wed, 13 Apr 2016 05:27:39 GMT

Querystring parameter setting operator is inconsistent

param=value's behavior changes with http method. So user interface changes between http requests whereas the http resource is the same.

For example:

bat GET api.example.com/person/1 apiKey=smellsbad
//apiKey is in the querystring
bat PUT api.example.com/person/1 apiKey=smellsbad
//apiKey is in the request body 

Also, there is no other option to add querystring parameters to post/put/patch requests other than manually adding them to url.

I think, a consistent assign operator for querystring params would be nice. We can adopt httpie's == for this.

in windows: ':=' not mean raw json object

bat POST http://www.baidu.com/ abc:='["123","456"]'

result in windows:

POST / HTTP/1.1
Host: www.baidu.com
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
User-Agent: bat/0.0.3

{"abc":"'[123,456]'"}
<response ignored>

result in linux(or bash in windows):

POST / HTTP/1.1
Host: www.baidu.com
Accept: application/json
Accept-Encoding: gzip, deflate
Content-Type: application/json
User-Agent: bat/0.0.3

{"abc":["123","456"]}
<response ignored>

Making HTTP requests with an array of parameters

With bat is it possible to build a HTTP request that parameter arrays?

Example: bat :8888 foo=val1 foo=val2 bar=val3 should result in a URL like localhost:8888?foo=val1&foo=val2&bar=val3

Currently when I tried using that above syntax I only get one parameter with what ever the last value was.

Header value misinterpreted as query param

When specifying a header option whose value ends with an =, bat incorrectly interprets that as a query param, even when escaped.

➜ bat GET :8001/v1/me/entity 'X-APIKey:asdfasdfa\='
GET /v1/me/entity?X-APIKey%3Aasdfasdfa%5C= HTTP/1.1
Host: localhost:8001
Accept: application/json
Accept-Encoding: gzip, deflate
User-Agent: bat/0.1.0

Support benchmark

sends some load to a web application. similar to Apache Bench (ab)

GET query values / POST json values broken by #59

#59 breaks parsing of query / post parameters.

The fix is meant to allow heder values with = in them, but breaks the case of having GET query or POST values with : in them. E.g.:

filter=fielda(expand:true),fieldb

Instead the implementation should look for the first occurrence of either : or = and split on that.

test file

based on file to test.

bat test.js

Address boundary error

app version: bat 0.12.1
rust toolchain: nightly-x86_64-apple-darwin 1.40.0-nightly
OS: macOS Catalina 10.15.1

Problem
Bat crashes with following 'bat' terminated by signal SIGSEGV (Address boundary error) segmentation fault: 11 if you run it in 'read from standart input mode' (no args, no flags)

Add flag to enable insecure SSL

In order to use bat to test self-signed SSL web services in development, bat needs to support insecure HTTPS queries. cURL has a -k, --insecure flag to facilitate this.

Can not set "Range" into request header

  1. exec command:
    bat GET http://127.0.0.1:8080/bd_logo1.png 'Host:www.baidu.com' 'Range:bytes=0-3'

  2. request message:
    GET /bd_logo1.png?Range%3Abytes=0-3 HTTP/1.1
    Host: www.baidu.com
    Accept: application/json
    Accept-Encoding: gzip, deflate
    User-Agent: bat/0.1.0

  3. question:
    Can not set "Range:bytes=0-3" as a header in http request, and make "Range" as a parameter in URL.

Adding print control flags

What about supporting httpie like print control flags?

From httpie's help:

  --print WHAT, -p WHAT
      String specifying what the output should contain:

          'H' request headers
          'B' request body
          'h' response headers
          'b' response body

Maybe we can also use separate flags for each of the options.

Form value contains ":" be ignored

$ bat -v -f POST https://api.weibo.com/oauth2/access_token redirect_uri=http://127.0.0.1/project/oauth/callback

the redirect_uri did not sent to server

Is bat still maintained? Or should a fork like https://github.com/shoenig/gurl be mentioned?

Hi @astaxie,
thanks for providing bat as Free Software!
A lot of people are interested in it, given the 2.5k stars.

However it seems like the last commits as of today are from 2019 and there is also no real release tagged?

Do you still maintain the software?

Or does it make sense to point users to a more active fork, maybe https://github.com/shoenig/gurl
(at least gurl seems to be more active and has some releases tagged, I like the name "bat" better though. ;) )

JSON display with colors

A nice feature of httpie is to display json body with colors, making the display very human-readable. Can we have it on bat ? Thanks, bat is nice.

The download argument doesn't seem to work

When I try to download a file using bat with the --download argument the following error message is produced:

flag provided but not defined: -download
bat is a Go implemented CLI cURL-like tool for humans.

Usage:

        bat [flags] [METHOD] URL [ITEM [ITEM]]

flags:
  -a, -auth=USER[:PASS]       Pass a username:password pair as the argument
  -f, -form=false             Submitting the data as a form
  -j, -json=true              Send the data in a JSON object
  -v, -verbose=false          Print the whole HTTP exchange (request and response)
  -p, -pretty=true            Print Json Pretty Fomat
  -proxy=PROXY_URL            Proxy with host and port

METHOD:
   bat defaults to either GET (if there is no request data) or POST (with request data).

URL:
  The only information needed to perform a request is a URL. The default scheme is http://,
  which can be omitted from the argument; example.org works just fine.

ITEM:
  Can be any of:
    Query string   key=value
    Header         key:value
    Post data      key=value
    File upload    key@/path/file

Example:

        bat beego.me

more help information please refer to https://github.com/astaxie/bat

I tried the following with the same result:

bat --download https://aur.archlinux.org/packages/la/lastpass-cli/lastpass-cli.tar.gz  
bat -download https://aur.archlinux.org/packages/la/lastpass-cli/lastpass-cli.tar.gz

Downloading the same file with bat https://aur.archlinux.org/packages/la/lastpass-cli/lastpass-cli.tar.gz > lastpass-cli.tar.gz does work though. I don't know if this is a bug or if the example in the README is bad.

How to staticly compile?

I've tried go build -ldflags '-extldflags "-fno-PIC -static"' -buildmode pie -tags 'osusergo netgo static_build' and go build -ldflags '-extldflags "-fPIC -static"' -buildmode pie -tags 'osusergo netgo static_build'.

Both get issues with trying to link.

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpthread.a(pthread_create.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
/usr/lib/gcc/x86_64-linux-gnu/4.9/../../../x86_64-linux-gnu/libpthread.a: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

I don't want a shared object I want a self-contained static binary that I can use in a Docker container FROM scratch.

bat modifies body from stdin if it is also valid JSON

Reading https://github.com/astaxie/bat/blob/master/bat.go#L195-L204 bat attempts to parse stdin as JSON, and when it succeeds, the body content may be different to what was originally submitted. For example if that content has been previously used to calculate a signature such as HMAC-SHA1,
then the signature may no longer be valid.

In practice, when POSTing a file and adding its HMAC as a header, bat effectively appends 0x0a and it's possible that the final output JSON may be altered -- I haven't yet checked this but it could have different key/object order, or changed keys, as JSON allows repeated keys within objects.

I can understand if this is intended behaviour but it took a surprisingly long time to realise
this was the case, and track it down.

I'd propose that PoLA should apply for content from stdin and it not be altered, or at least, only if the -json=true flag has been specified.

insecure flag for allowing connections to SSL sites without certs

There is a flag in cURL of insecure flag of -k, --insecure Allow connections to SSL sites without certs (H)

It's much helpful on some cases that connects to https protocol without certs. Would you consider to do it in the future?

2016/05/16 14:06:39.177690 bat.go:215: can't get the url Get <url>: x509: cannot validate certificate for <ip> because it doesn't contain any IP SANs

Unknown usage option -v in README.md

Examples section in README.md is written following:

See the request that is being sent using one of the output options:

$ bat -v example.org

But -v option works print version string.

Is it typo?

Json Value `:=` Syntax Not Documented in Help Message

The current bat help message says:

...
ITEM:
  Can be any of:
    Query string   key=value
    Header         key:value
    Post data      key=value
    File upload    key@/path/file
...

I was trying to send a JSON number and thought that it was not possible until I read the readme for bat and found that it was possible using the key:=value syntax. It would be great to see that syntax documented in the help message.

« Content-Disposition : filename="filename.ext" » handling

Given the following

$ bat -download=true http://127.0.0.1:8080/3,0140231f47.jpg
HTTP/1.1 200 OK
Last-Modified : Thu, 29 Oct 2015 13:06:15 GMT
Date : Thu, 29 Oct 2015 13:33:31 GMT
Accept-Ranges : bytes
Content-Disposition : filename="dog-spoon-lobster.jpg"
Content-Length : 70059
Content-Type : image/jpeg
Etag : "d1ca1636"

Downloading to ""dog-spoon-lobster.jpg""
68.42 KB / 68.42 KB 

The file resulting is literaly "dog-spoon-lobster.jpg" it should have been dog-spoon-lobster.jpg

$ ls -l
total 184
-rw-r--r-- 1 me users 70059 29 oct.  14:33 "dog-spoon-lobster.jpg"

It looks like Content-Disposition does not remove double quotes ?

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.