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 cors header and options to gedis http server #529

Merged
merged 3 commits into from
Jan 3, 2021

Conversation

ranatrk
Copy link
Contributor

@ranatrk ranatrk commented Jan 3, 2021

Description

  • Options method is not supported
  • CORS headers are not supported in gedis http server

Changes

Add suport for OPTIONs method, and add CORS headers

Test changes:

  • Enabling cors headers(default)
GedisHTTPServer(
  instance_name='testing',
  host='127.0.0.1',
  port=4500,
  allow_cors=True
)
curl -i -v  -X OPTIONS http://127.0.0.1:4500/testing/cors/enabled
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 4500 (#0)
> OPTIONS /testing/cors/enabled HTTP/1.1
> Host: 127.0.0.1:4500
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE
< Access-Control-Allow-Headers: Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token
Access-Control-Allow-Headers: Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token
< Content-Length: 0
Content-Length: 0
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Date: Sun, 03 Jan 2021 14:51:45 GMT
Date: Sun, 03 Jan 2021 14:51:45 GMT

< 
* Connection #0 to host 127.0.0.1 left intact

  • Disabling cors headers
GedisHTTPServer(
  instance_name='testing2',
  host='127.0.0.1',
  port=4600,
  allow_cors=False
)
 curl -i -v  -X OPTIONS http://127.0.0.1:4600/testing/cors/enabled
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 4600 (#0)
> OPTIONS /testing/cors/enabled HTTP/1.1
> Host: 127.0.0.1:4600
> User-Agent: curl/7.58.0
> Accept: */*
> 
< HTTP/1.1 405 Method Not Allowed
HTTP/1.1 405 Method Not Allowed
< Allow: GET,POST
Allow: GET,POST
< Content-Length: 753
Content-Length: 753
< Content-Type: text/html; charset=UTF-8
Content-Type: text/html; charset=UTF-8
< Date: Sun, 03 Jan 2021 14:52:02 GMT
Date: Sun, 03 Jan 2021 14:52:02 GMT

< 

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <html>
        <head>
            <title>Error: 405 Method Not Allowed</title>
            <style type="text/css">
              html {background-color: #eee; font-family: sans;}
              body {background-color: #fff; border: 1px solid #ddd;
                    padding: 15px; margin: 15px;}
              pre {background-color: #eee; border: 1px solid #ddd; padding: 5px;}
            </style>
        </head>
        <body>
            <h1>Error: 405 Method Not Allowed</h1>
            <p>Sorry, the requested URL <tt>&#039;http://127.0.0.1:4600/testing/cors/enabled&#039;</tt>
               caused an error:</p>
            <pre>Method not allowed.</pre>
        </body>
    </html>
* Connection #0 to host 127.0.0.1 left intact

Related Issues

threefoldtech/js-sdk#2110
threefoldfoundation/tft-stellar#257

Checklist

  • Pre-commit hook is installed to do formatting checks before committing code...etc
  • Tests included
  • Build pass
  • Documentation
  • Code format and docstrings

@ranatrk ranatrk marked this pull request as ready for review January 3, 2021 15:01
@codecov-io
Copy link

codecov-io commented Jan 3, 2021

Codecov Report

Merging #529 (b65f05f) into development (7594998) will increase coverage by 0.31%.
The diff coverage is n/a.

Impacted file tree graph

@@               Coverage Diff               @@
##           development     #529      +/-   ##
===============================================
+ Coverage        70.44%   70.75%   +0.31%     
===============================================
  Files               84       84              
  Lines             3820     3820              
===============================================
+ Hits              2691     2703      +12     
+ Misses            1129     1117      -12     
Impacted Files Coverage Δ
jumpscale/core/logging/logging.py 94.15% <0.00%> (-0.59%) ⬇️
jumpscale/servers/gedis/server.py 73.82% <0.00%> (+6.80%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7594998...b65f05f. Read the comment docs.

@robvanmieghem robvanmieghem added this to the now milestone Jan 3, 2021
@abom abom merged commit 8012769 into development Jan 3, 2021
@abom abom deleted the development_cors_header branch January 3, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants