-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
api: added preference param to eliminate ES bouncing issue #107
api: added preference param to eliminate ES bouncing issue #107
Conversation
invenio_search/api.py
Outdated
address = request.headers.get('X-Forwarded-For', request.remote_addr) | ||
if address is not None: | ||
# An 'X-Forwarded-For' header includes a comma separated list of | ||
# the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the comment cut in a strange way?
@ntarocco finally you cannot solve inside the init method? Do you need to spread the pain? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just added one comment.
1c5b6d3
to
9cdee79
Compare
@nharraud fixed thanks! |
@jbenito3 and for any other reviewer. The only way I found (and deeply discusses with @nharraud) was to expose a factory instead of the class to add this |
alg = hashlib.md5() | ||
alg.update(user_hash.encode('utf8')) | ||
return alg.hexdigest() | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO we don't need return None
is None
by default :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Saying it explicitly makes the code more readable. Otherwise it might look like a forgotten return.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests are failing on Python 3.5, @ntarocco can you please take a look? Ping me when they are fixed so I will merge.
9cdee79
to
b494e7e
Compare
@switowski thanks, I was fixing it, now it should work! |
invenio_search/api.py
Outdated
|
||
Taken from Flask Login utils.py. | ||
""" | ||
address = request.headers.get('X-Forwarded-For', request.remote_addr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can just use request.remote_addr
, since we expect that to be set correctly. In case of proxies, you need to use Werkzeug's WSGIProxyFix to set it correctly from X-Forwarded-For headers. In order to correctly determine the right user IP address, you need to know how many proxies are in-front of your webapp. For Invenio this is usually 2: Nginx + HAProxy, hence, making the users' IP appear as second in the list. :-)
b494e7e
to
d61bc5a
Compare
@lnielsen I have fixed it as you proposed! Thanks for checking! |
* added a method to RecordsSearch to return a new instance of Search with a new query param preference. The value of the param will not change for requests coming from the same user. * closes inveniosoftware#106
d61bc5a
to
c618a7a
Compare
added a method to RecordsSearch to return a new instance of Search
with a new query param preference. The value of the param will not
change for requests coming from the same user.
closes search: should do the right thing to prevent bouncing results #106