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

Add RFC7231 Accept header parsing #80

Open
ekroon opened this issue Sep 20, 2021 · 6 comments
Open

Add RFC7231 Accept header parsing #80

ekroon opened this issue Sep 20, 2021 · 6 comments
Labels
bug Something isn't working

Comments

@ekroon
Copy link
Contributor

ekroon commented Sep 20, 2021

I would like to use ROAPI endpoints from a browser. Currently when accessing /api/tables/{table_name} endpoint with a browser you get an error like the following:

{ "code": 400, "error": "unsupported_content_type", "message": "\"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\" is not a supported response content type" }

How to parse the Accept header is specified in RFC7231 and Actix has an implementation for this. How to implement this would be impacted by #76 and if this would be implemented it might make switching harder.

An easy quicfix would be to implement a fallback to application/json if the resulting content-type is unknown.

@houqp
Copy link
Member

houqp commented Sep 20, 2021

Good catch @ekroon , did you mean to access the endpoint by loading it directly in a browser or loading it through AJAX call?

Regardless, I agree with you that we should support q factor weighting in request header parsing. I think a fallback to json makes sense when accept header is not specified at all by the client. Otherwise, it might confuse the client.

@houqp houqp added the bug Something isn't working label Sep 20, 2021
@ekroon
Copy link
Contributor Author

ekroon commented Sep 20, 2021

I mean loading it directly in the browser window.

@houqp
Copy link
Member

houqp commented Sep 20, 2021

Got it, extending on your use-case, I think it might be an interesting idea to implement a html or xml encoding type. The html encoding could render the query result in a nicely looking web page to help better visualize the result. We can even throw in some js code to make the resulting web page interactive.

@xezpeleta
Copy link
Contributor

Hi, I agree with @ekroon

A fallback to application/json would be enough.

Thanks!!

@ekroon
Copy link
Contributor Author

ekroon commented Nov 12, 2021

A full implementation for Accept header parsing will be a bit involved as there is no implementation available for Axum. The correct place to implement this would be hyperium/headers#7 but that appears to be a little bit stalled. Maybe a port of Rocket or Actix's implementation in a separate crate is a quicker solution.

Alternatively, supporting the format in the url extension, like .json, .csv, would be an easy usable solution from browsers too. This would work nicely with a future .html version.

@houqp
Copy link
Member

houqp commented Nov 14, 2021

Thanks @ekroon , I agree with both of your points :) For your first point, on top of what's in rocket and actix, I think we can also take hyperium/headers#70 as a reference to build out the crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants