Skip to content

Commit

Permalink
Fix:request from extra mock lost origin headers (#519)
Browse files Browse the repository at this point in the history
* Fix:request from extra mock lost origin headers

* Add case insensitive dict

* utils.py add new line
  • Loading branch information
zhaoye authored Jul 15, 2021
1 parent 70bc315 commit df517eb
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 12 deletions.
11 changes: 10 additions & 1 deletion lyrebird/mock/handlers/http_data_helper/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections import OrderedDict
from . import content_encoding, content_type
from lyrebird.utils import CaseInsensitiveDict
import json

origin2flow_handlers = OrderedDict({
'Content-Encoding': content_encoding,
Expand All @@ -23,8 +25,15 @@ def origin2flow(origin_obj, output=None):
if not _data:
return

# Read raw headers, support the request from extra mock 9999 port
if 'Proxy-Raw-Headers' in origin_obj.headers:
_origin_headers = json.loads(origin_obj.headers['Proxy-Raw-Headers'])
raw_headers = CaseInsensitiveDict(_origin_headers)
else:
raw_headers = origin_obj.headers

for headers_key, func in origin2flow_handlers.items():
headers_val = origin_obj.headers.get(headers_key, '')
headers_val = raw_headers.get(headers_key, '')
_data = func.origin2flow(headers_val, _data)

if output:
Expand Down
11 changes: 11 additions & 0 deletions lyrebird/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,14 @@ def find_free_port():
s.bind(('', 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]


class CaseInsensitiveDict(dict):
def __setitem__(self, key, value):
super(CaseInsensitiveDict, self).__setitem__(key.lower(), value)

def __getitem__(self, key):
return super(CaseInsensitiveDict, self).__getitem__(key.lower())

def get(self, key, default=None):
return super(CaseInsensitiveDict, self).get(key.lower(), default)
11 changes: 0 additions & 11 deletions sonar-project.properties

This file was deleted.

3 changes: 3 additions & 0 deletions vetur.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
projects: ["./frontend"],
};

0 comments on commit df517eb

Please sign in to comment.