Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kevinmgranger/requestmod
[golang] Wrap an existing http.RoundTripper, inspecting and/or modifying each request that comes through.
https://github.com/kevinmgranger/requestmod
Last synced: 12 days ago
JSON representation
[golang] Wrap an existing http.RoundTripper, inspecting and/or modifying each request that comes through.
- Host: GitHub
- URL: https://github.com/kevinmgranger/requestmod
- Owner: KevinMGranger
- License: bsd-3-clause
- Created: 2016-01-29T04:26:10.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-06T23:18:38.000Z (almost 9 years ago)
- Last Synced: 2023-04-04T12:41:34.907Z (over 1 year ago)
- Language: Go
- Size: 4.88 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# requestmod
[![Build Status](https://travis-ci.org/KevinMGranger/requestmod.svg?branch=master)](https://travis-ci.org/KevinMGranger/requestmod)
requestmod lets you wrap an existing http.RoundTripper, inspecting and/or
modifying each request that comes through.It is almost entirely adapted from code in the [oauth2 package.](https://golang.org/x/oauth2)
# Example(s)
Override the User-Agent header on each request:
```go
cli := new(http.Client)
cli.Transport = requestmod.NewTransport(nil, func(req *http.Request) error {
req.Header.Set("User-Agent", "MyAwesomeClient")
return nil
})
```Reject requests that go to a certain host:
```go
cli := new(http.Client)
cli.Transport = requestmod.NewTransport(nil, func(req *http.Request) error {
if req.URL.Host == "ravenholm" {
return errors.New("We don't go there anymore.")
}
return nil
})
```# TODO / Bugs
- The tests are terrible... but at least they have 100% coverage.