Giter Club home page Giter Club logo

Comments (7)

kishorenc avatar kishorenc commented on May 18, 2024

@jasonbosco Added via 523c142

Docker image 0.7.1 is also published:

https://hub.docker.com/r/typesense/typesense/tags/

from typesense.

jasonbosco avatar jasonbosco commented on May 18, 2024

Almost works. It now returns a 200, but looks like it's missing the content-type header in the list of allowed headers:

Network Request:

screen shot 2018-01-01 at 2 11 15 pm

Console:

screen shot 2018-01-01 at 2 10 59 pm

from typesense.

kishorenc avatar kishorenc commented on May 18, 2024

@jasonbosco

According to the spec the server should send the value of the Access-Control-Request-Headers back in Access-Control-Allow-Headers if it accepts them. I am already doing that. Although I see that the Access-Control-Request-Headers is being sent in the screenshot, somehow the server is not finding it and hence the empty response.

Not sure why this is happening since it works for me in CURL... Can you try:

$ curl -H "Origin: http://example.com" \                                                                                                                                           ‹ruby-2.2.5@typesense›
  -H "Access-Control-Request-Method: POST" \
  -H "Access-Control-Request-Headers: x-typesense-api-key, Content-Type" \
  -X OPTIONS --verbose \
  http://localhost:8108/collections
*   Trying ::1...
* TCP_NODELAY set
* Connection failed
* connect to ::1 port 8108 failed: Connection refused
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8108 (#0)
> OPTIONS /collections HTTP/1.1
> Host: localhost:8108
> User-Agent: curl/7.53.1
> Accept: */*
> Origin: http://example.com
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: x-typesense-api-key, Content-Type
>
< HTTP/1.1 200 OK
< Date: Tue, 02 Jan 2018 02:27:49 GMT
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS
< Access-Control-Allow-Headers: x-typesense-api-key, Content-Type
< Access-Control-Max-Age: 86400
< transfer-encoding: chunked
<
* Connection #0 to host localhost left intact

from typesense.

jasonbosco avatar jasonbosco commented on May 18, 2024

@kishorenc Interestingly, when I try that curl out, I get blank value for headers:

$ curl -H "Origin: http://localhost:8108" \
>   -H "Access-Control-Request-Method: POST" \
>   -H "Access-Control-Request-Headers: x-typesense-api-key, Content-Type" \
>   -X OPTIONS --verbose \
>   http://localhost:8108/collections
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8108 (#0)
> OPTIONS /collections HTTP/1.1
> Host: localhost:8108
> User-Agent: curl/7.54.0
> Accept: */*
> Origin: http://localhost:8108
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: x-typesense-api-key, Content-Type
>
< HTTP/1.1 200 OK
< Date: Tue, 02 Jan 2018 04:52:24 GMT
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS
< Access-Control-Allow-Headers:
< Access-Control-Max-Age: 86400
< transfer-encoding: chunked
<
* Connection #0 to host localhost left intact

Another thing I noticed is that if there's only one header passed in the request, say just Content-Type then the server returns that header:

$ curl -H "Origin: http://localhost:8108" \
>   -H "Access-Control-Request-Method: POST" \
>   -H "Access-Control-Request-Headers: Content-Type" \
>   -X OPTIONS --verbose \
>   http://localhost:8108/collections
*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8108 (#0)
> OPTIONS /collections HTTP/1.1
> Host: localhost:8108
> User-Agent: curl/7.54.0
> Accept: */*
> Origin: http://localhost:8108
> Access-Control-Request-Method: POST
> Access-Control-Request-Headers: Content-Type
>
< HTTP/1.1 200 OK
< Date: Tue, 02 Jan 2018 04:54:19 GMT
< Connection: keep-alive
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS
< Access-Control-Allow-Headers: Content-Type
< Access-Control-Max-Age: 86400
< transfer-encoding: chunked
<
* Connection #0 to host localhost left intact

from typesense.

jasonbosco avatar jasonbosco commented on May 18, 2024

@kishorenc Following up from this comment, I tested out typesense/typesense:0.8-api-changes. We're one step closer...

I'm now running into this issue:

screen shot 2018-01-03 at 7 53 35 am

The browser is sending the request and receiving a response, but it's refusing to process the response for the GET request because there are no Access-Control-* headers in the response to the GET request. Only the OPTIONS request's response has those headers:

screen shot 2018-01-03 at 7 53 24 am

Looking at the MDN documentation for CORS, Access-Control headers need to be mirrored on the actual GET/POST requests' responses in addition to the pre-flight OPTIONS request.

from typesense.

kishorenc avatar kishorenc commented on May 18, 2024

@jasonbosco Okay, Access-Control-Allow-Origin is now sent in all responses when CORS is enabled. I've republished the typesense/typesense:0.8-api-changes docker image with that change.

from typesense.

jasonbosco avatar jasonbosco commented on May 18, 2024

Alright! Works fine now.

from typesense.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.