Skip to content
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

allow for manual setting of Accept header or headers in general #52

Closed
joernhees opened this issue May 18, 2015 · 8 comments
Closed

allow for manual setting of Accept header or headers in general #52

joernhees opened this issue May 18, 2015 · 8 comments

Comments

@joernhees
Copy link
Member

as can be seen in http://stackoverflow.com/a/30306013/1423333 there are endpoints out there which don't understand the ",".join(_SPARQL_JSON) https://github.com/RDFLib/sparqlwrapper/blob/master/SPARQLWrapper/Wrapper.py#L451 Accept header, but only want "one" mime-type :(

in https://github.com/RDFLib/sparqlwrapper/blob/master/SPARQLWrapper/Wrapper.py#L506 we unconditionally add the Accept header.

I think it would be much better if one could manually set headers somehow and the _createRequest() method wouldn't override them if they're there already.

Could be done in one go when switching to the Requests lib (see #51)?

@wikier
Copy link
Member

wikier commented Jun 24, 2015

Well, I understand the feature request.

But... the issue is clearly server-side. The idea is to stay bound to the protocol. Small changes for a broader support are fine. But we should put a line where we do not support such wrong behaviors.

What do others (@iherman, @indeyets, @dayures, etc) think?

@joernhees
Copy link
Member Author

i didn't want to suggest to encourage bad behavior, but i'm suggesting to allow for easier customization so that developers can use the lib in the real world even if things go slightly wrong.

If you read the thread on stackoverflow, you saw that the endpoint actually follows protocol, but that it doesn't seem to understand the longer than necessary Accept header we send for compatibility reasons: Accept: application/sparql-results+json,text/javascript,application/json. The endpoint doesn't understand the , joined alternatives, but it would understand Accept: application/sparql-results+json.

Why shouldn't we allow a developer to just send one of these alternatives / in general manually set the headers?

At the moment the workaround for this really minor flaw of the endpoint is relatively complicated just cause _createRequest() does it in-line (so it doesn't call another method one could override) and it doesn't check if that header was already set.

@psychemedia
Copy link

I need to access an endpoint that requires a custom header attribute to pass an API token.

Am I correct in thinking that I can't do this with SPARQLwrapper as it currently stands?

@wikier
Copy link
Member

wikier commented Sep 1, 2017

@psychemedia, do you need header or parameter?

Because for parameter SPARQLWrapper provides something https://github.com/RDFLib/sparqlwrapper/blob/master/SPARQLWrapper/Wrapper.py#L318

But headers we're not yet there.

@psychemedia
Copy link

Header....

I wondered about something hacky like adding a parameter into class initialiser:

  def __init__(self, endpoint, updateEndpoint=None, returnFormat=XML, defaultGraph=None, agent=__agent__, extraheaders=None):

  ...
    self.extraheaders = extraheaders if extraheaders else {}

and then fudging the request code:

    def _createRequest(self):
        ...
        for extraheader in self.extraheaders:
            request.add_header(extraheader, self.extraheaders[extraheader])

@dayures
Copy link
Contributor

dayures commented Mar 15, 2018

@wikier @iherman @indeyets What do you think to add the functionality explained in #52 (comment) ?

@wikier
Copy link
Member

wikier commented Mar 15, 2018

SGTM

@dayures
Copy link
Contributor

dayures commented Mar 24, 2018

See pull request #103 with an initial approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants