{"action":"created","issue":{"url":"https://api.github.com/repos/grafana/grafana/issues/14561","repository_url":"https://api.github.com/repos/grafana/grafana","labels_url":"https://api.github.com/repos/grafana/grafana/issues/14561/labels{/name}","comments_url":"https://api.github.com/repos/grafana/grafana/issues/14561/comments","events_url":"https://api.github.com/repos/grafana/grafana/issues/14561/events","html_url":"https://github.com/grafana/grafana/issues/14561","id":392123269,"node_id":"MDU6SXNzdWUzOTIxMjMyNjk=","number":14561,"title":"Prometheus datasource with direct/browser access + auth basic + POST does not work","user":{"login":"hekmon","id":3418467,"node_id":"MDQ6VXNlcjM0MTg0Njc=","avatar_url":"https://avatars0.githubusercontent.com/u/3418467?v=4","gravatar_id":"","url":"https://api.github.com/users/hekmon","html_url":"https://github.com/hekmon","followers_url":"https://api.github.com/users/hekmon/followers","following_url":"https://api.github.com/users/hekmon/following{/other_user}","gists_url":"https://api.github.com/users/hekmon/gists{/gist_id}","starred_url":"https://api.github.com/users/hekmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hekmon/subscriptions","organizations_url":"https://api.github.com/users/hekmon/orgs","repos_url":"https://api.github.com/users/hekmon/repos","events_url":"https://api.github.com/users/hekmon/events{/privacy}","received_events_url":"https://api.github.com/users/hekmon/received_events","type":"User","site_admin":false},"labels":[{"id":274350203,"node_id":"MDU6TGFiZWwyNzQzNTAyMDM=","url":"https://api.github.com/repos/grafana/grafana/labels/datasource:%20Prometheus","name":"datasource: Prometheus","color":"85c92c","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2018-12-18T11:56:11Z","updated_at":"2018-12-19T13:16:38Z","closed_at":"2018-12-18T14:56:26Z","author_association":"NONE","body":"Hello,\r\n\r\nWe encountered a bug with Grafana when using a prometheus data source with direct/browser access and POST configuration.\r\n\r\nPre-flight request works fine but during the actual request the xmlhttprequest use a wrong content type `application/json;charset=UTF-8` which prevents prometheus to decode the query as the body is a form url encoded.\r\n\r\nFor now, our workaround is to intercept the query within our reverse proxy to rewrite the \"content-type\" header (with `application/x-www-form-urlencoded`) before it is actually sent to prometheus.\r\n\r\n### What Grafana version are you using?\r\nGrafana v5.4.2\r\n### What datasource are you using?\r\nPrometheus\r\n### What OS are you running grafana on?\r\n-> Grafana Cloud\r\n### What did you do?\r\nConfigure Prometheus data source with `Browser` (direct) access and `POST` HTTP method.\r\n### What was the expected result?\r\nA working datasource. xmlhttprequest preflight request is OK but actual request should have a `application/x-www-form-urlencoded` `content-type` instead of `application/json;charset=UTF-8` given the body is url form encoded.\r\n### What happened instead?\r\nThe content-type is set to `application/json;charset=UTF-8` which prevents Prometheus to parse the body correctly. The error returned was:\r\n```\r\n{\"status\":\"error\",\"errorType\":\"bad_data\",\"error\":\"parse error at char 1: no expression found in input\"}\r\n```\r\n### Include raw network request\r\n\r\n```\r\n# General\r\nRequest URL: https://<prometheus_proxy>:9091/api/v1/query\r\nRequest Method: POST\r\nStatus Code: 400 \r\nRemote Address: <prom_proxy_ip>:9091\r\nReferrer Policy: no-referrer-when-downgrade\r\n\r\n# Response headers\r\naccess-control-allow-credentials: true\r\naccess-control-allow-origin: https://<inst>.grafana.net\r\ncontent-encoding: gzip\r\ncontent-length: 103\r\ncontent-type: application/json\r\ndate: Tue, 18 Dec 2018 11:32:37 GMT\r\nstatus: 400\r\nvary: Origin\r\n\r\n# Request headers\r\nProvisional headers are shown\r\nAccept: application/json, text/plain, */*\r\nAuthorization: Basic <redacted>\r\nContent-Type: application/json;charset=UTF-8  <-- issue is here\r\nOrigin: https://<inst>.grafana.net\r\nReferer: https://<inst>.grafana.net/datasources/edit/29\r\nUser-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36\r\n\r\n# Request payload\r\nquery=1%2B1&time=1545132757.317\r\n```\r\n\r\nThis behavior can simply be simulated with a curl command:\r\n```\r\ncurl -X POST -H \"content-type: application/json\" -d \"query=1%2B1&time=1545132757.317\" \"http://localhost:9090/api/v1/query\"\r\n{\"status\":\"error\",\"errorType\":\"bad_data\",\"error\":\"parse error at char 1: no expression found in input\"}\r\n```\r\n\r\n \r\n"},"comment":{"url":"https://api.github.com/repos/grafana/grafana/issues/comments/448593469","html_url":"https://github.com/grafana/grafana/issues/14561#issuecomment-448593469","issue_url":"https://api.github.com/repos/grafana/grafana/issues/14561","id":448593469,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0ODU5MzQ2OQ==","user":{"login":"hekmon","id":3418467,"node_id":"MDQ6VXNlcjM0MTg0Njc=","avatar_url":"https://avatars0.githubusercontent.com/u/3418467?v=4","gravatar_id":"","url":"https://api.github.com/users/hekmon","html_url":"https://github.com/hekmon","followers_url":"https://api.github.com/users/hekmon/followers","following_url":"https://api.github.com/users/hekmon/following{/other_user}","gists_url":"https://api.github.com/users/hekmon/gists{/gist_id}","starred_url":"https://api.github.com/users/hekmon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hekmon/subscriptions","organizations_url":"https://api.github.com/users/hekmon/orgs","repos_url":"https://api.github.com/users/hekmon/repos","events_url":"https://api.github.com/users/hekmon/events{/privacy}","received_events_url":"https://api.github.com/users/hekmon/received_events","type":"User","site_admin":false},"created_at":"2018-12-19T13:16:38Z","updated_at":"2018-12-19T13:16:38Z","author_association":"NONE","body":"Updated the title to include the \"auth basic\" parameter."}}
{"actor":{"display_login":"hekmon"}}