Skip to content

Commit

Permalink
Allowing deleting of existing headers in before_request
Browse files Browse the repository at this point in the history
  • Loading branch information
andyjeffries committed Feb 21, 2018
1 parent 8955b9d commit 26f606f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## 1.5.6

Feature:

- Allow deleting of default headers in `before_request` callbacks

## 1.5.5

Bugfix:

- Fixing already encoded bodies in plain requests

## 1.5.4

Feature:

- Changing `_request` to accept options, including `:headers`, rather than headers directly

## 1.5.3

Feature:
Expand Down
10 changes: 10 additions & 0 deletions lib/flexirest/headers_list.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Flexirest
class HeadersList
STORE_MULTIPLE_VALUES = ["set-cookie"]

def initialize
@store = {}
end
Expand Down Expand Up @@ -33,6 +34,15 @@ def each(split_multiple_headers = false)
end
end

def delete(key)
key = find_existing(key)
@store.delete(key)
end

def keys
@store.keys
end

private

def find_existing(key)
Expand Down
2 changes: 1 addition & 1 deletion lib/flexirest/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Flexirest
VERSION = "1.5.5"
VERSION = "1.5.6"
end
7 changes: 7 additions & 0 deletions spec/lib/headers_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
expect(headers_list["X-My-Header"]).to eq(url)
end

it "should allow deleting stored headers" do
url = "http://www.google.com"
headers_list.delete("X-My-Header")
expect(headers_list["X-My-Header"]).to eq(nil)
expect(headers_list.keys).to_not include("X-My-Header")
end

it "should remember overwrite normal headers" do
url = "http://www.google.com"
headers_list["X-My-Header"] = "SHOULD NEVER BE SEEN"
Expand Down

0 comments on commit 26f606f

Please sign in to comment.