question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CORB `application/json` collision

See original GitHub issue

Hello.

I have a django json-rpc server and frontend which requests this json methods.

When browser make preflight request, server send this response:

(!) Here is correct response for OPTIONS query.

< HTTP/1.1 200 OK
< Server: gunicorn/19.7.1
< Date: Mon, 05 Aug 2019 17:47:12 GMT
< Connection: close
< Content-Type: text/html; charset=utf-8
< Content-Length: 0
< Vary: Origin
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Origin: https://order.reg.ru
< Access-Control-Allow-Headers: accept, accept-encoding, authorization, content-type, dnt, origin, user-agent, x-csrftoken, x-requested-with, x-csrf-token
< Access-Control-Allow-Methods: DELETE, GET, OPTIONS, PATCH, POST, PUT
< Access-Control-Max-Age: 86400

But web-browser (e.g. Chrome) thows warning about CORB violation, because browser expect Content-Type from OPTIONS response as application/json.

How to override Content-Type for all cors answers in project?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
adamchainzcommented, Aug 7, 2019

It’s not directly possible but you can subclass the middleware from:

class MyCorsMiddleware(CorsMiddleware):
    def process_request(self, request):
        response = super().process_request(request)
        if response is not None:
            response['Content-Type'] = 'foobar'  # whatever you want
        return response

If this works for you please let me know as I’ll patch the library then. I haven’t found time to reproduce your issue.

0reactions
bashkirtsevichcommented, Aug 8, 2019

OK, I’m checking for now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cross site error when consumes = "application/json" present
When you are adding the consumes = "application/json" option, you explicitly say that the server expects application/json datatype. If the cors ...
Read more >
Configuring CORS for content-type: application/json - Medium
Correctly configuring CORS for content-type: application/json. The use of dynamic requests to backend servers is prevalent in modern web ...
Read more >
Has been blocked by cors policy [Explain like I am 5] - hinty
Just raise an exception immediately if the content-type request header is not JSON. A lot of frameworks do it for you. To understand...
Read more >
Understanding Cross Origin Resource Sharing (CORS)
Cross-origin resource sharing (CORS) is a mechanism that allows a client application to request restricted resources hosted on server from a ...
Read more >
Enabling Cross Origin Requests for a RESTful Web Service
We use GET in this case because it is convenient for testing. Spring will still reject a GET request where the origin doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found