<commit_before>[![Build Status](https://api.shippable.com/projects/53bd3eef2e23bdcb03c0df9e/badge/master)](https://www.shippable.com/projects/53bd3eef2e23bdcb03c0df9e)
[![Code Climate](https://codeclimate.com/github/kaspernj/http2.png)](https://codeclimate.com/github/kaspernj/http2)
[![Code Climate](https://codeclimate.com/github/kaspernj/http2/coverage.png)](https://codeclimate.com/github/kaspernj/http2)

# http2

A HTTP-framework for Ruby supporting keep-alive, compression, JSON-posting, detailed inspection of responses and much more.

# Usage

```ruby
require "rubygems"
require "http2"

Http2.new(host: "www.google.dk") do |http|
  # Do requests here.
end
```

Or without using a block for ensuring closing of connection:
```ruby
http = Http2.new(...)

# Do requests here.

http.close
```

## Get requests
```ruby
res = http.get("path/to/something")
```

## Post requests
```ruby
res = http.post(url: "path/to/something", post: {
  "some_post_val" => "some_value"
})
```

You can also post JSON like this:
```ruby
res = http.post(url: "path/to/something", json: {some_argument: true})
```

## Delete requests
```ruby
res = http.delete(url: "path/to/something")
```

## File upload
```ruby
res = http.post_multipart(url: "path/to/something", post: {
  "test_file1" => {
    fpath: fpath,
    filename: "specfile"
  }
})
```

## Reading cookies
```ruby<commit_msg>Added documentation on extra headers<commit_after>[![Build Status](https://api.shippable.com/projects/53bd3eef2e23bdcb03c0df9e/badge/master)](https://www.shippable.com/projects/53bd3eef2e23bdcb03c0df9e)
[![Code Climate](https://codeclimate.com/github/kaspernj/http2.png)](https://codeclimate.com/github/kaspernj/http2)
[![Code Climate](https://codeclimate.com/github/kaspernj/http2/coverage.png)](https://codeclimate.com/github/kaspernj/http2)

# http2

A HTTP-framework for Ruby supporting keep-alive, compression, JSON-posting, detailed inspection of responses and much more.

# Usage

```ruby
require "rubygems"
require "http2"

Http2.new(host: "www.google.dk") do |http|
  # Do requests here.
end
```

Or without using a block for ensuring closing of connection:
```ruby
http = Http2.new(...)

# Do requests here.

http.close
```

## Get requests
```ruby
res = http.get("path/to/something")
```

## Post requests
```ruby
res = http.post(url: "path/to/something", post: {
  "some_post_val" => "some_value"
})
```

### Extra headers
```ruby
res = http.post(
  url: "path",
  headers: {"Auth": "123"},
  post: {data: "test"}
)
```

### Post JSON as content
```ruby
res = http.post(url: "path/to/something", json: {some_argument: true})
```

## Delete requests
```ruby
res = http.delete(url: "path/to/something")
```

## File upload
```ruby
res = http.post_multipart(url: "path/to/something", post: {
  "test_file1" => {
    fpath: fpath,
    filename: "specfile"
  }
})
```

## Reading cookies
```ruby
{'fraction_non_alphanumeric': 0.18093249826026445, 'fraction_numerical': 0.021224773834377174, 'mean_word_length': 4.86734693877551, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 12, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2030252', 'n_tokens_mistral': 1119, 'n_tokens_neox': 1033, 'n_words': 217}