chdb-io / chdb-server-bak

API Server for chDB, an in-process SQL OLAP Engine powered by ClickHouse
https://chdb.io
Apache License 2.0
21 stars 4 forks source link

request Content-Type suppression #7

Closed akvlad closed 10 months ago

akvlad commented 10 months ago
$ curl -vv -X POST http://a:b@localhost:8123 --data 'CREATE DATABASE test';
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8123...
* Connected to localhost (127.0.0.1) port 8123 (#0)
* Server auth using Basic with user 'a'
> POST / HTTP/1.1
> Host: localhost:8123
> Authorization: Basic YTpi
> User-Agent: curl/7.88.1
> Accept: */*
> Content-Length: 20
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 200 OK
< Server: Werkzeug/3.0.1 Python/3.8.10
< Date: Thu, 02 Nov 2023 21:23:48 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 2
< Connection: close
< 
* Closing connection 0
Ok

$ curl -vv -X POST http://a:b@localhost:8123 --data 'SHOW DATABASES';
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:8123...
* Connected to localhost (127.0.0.1) port 8123 (#0)
* Server auth using Basic with user 'a'
> POST / HTTP/1.1
> Host: localhost:8123
> Authorization: Basic YTpi
> User-Agent: curl/7.88.1
> Accept: */*
> Content-Length: 14
> Content-Type: application/x-www-form-urlencoded
> 
< HTTP/1.1 200 OK
< Server: Werkzeug/3.0.1 Python/3.8.10
< Date: Thu, 02 Nov 2023 21:24:21 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 2
< Connection: close
< 
* Closing connection 0

The database doesn't get created because of Content-Type: application/x-www-form-urlencoded in the request. On the other hand clickhouse server doesn't rely on content-type. In order to suppress Content-Type header it's enough to use request.get_data() instead of request.data as described in https://stackoverflow.com/questions/55847242/flask-flask-restful-force-correct-override-incorrect-content-type-header-for-po

lmangani commented 10 months ago

Damn right! Implemented as suggested https://github.com/chdb-io/chdb-server/commit/63e22545864fb375918124c38f5566383bc2a57a