Giter Site home page Giter Site logo

Comments (7)

eriknelson avatar eriknelson commented on August 25, 2024

https://golang.org/pkg/net/http/#Request.FormValue

from ansible-service-broker.

jmrodri avatar jmrodri commented on August 25, 2024

-1 query parameters are not forms. The POSTs we are getting are "application/json" with query parameters on the url. The FormValue code looks for "multipart/form-data" or "application/x-www-form-urlencoded". If this was a traditional form post FormValue is the way to go. But with the JSON coming in, we're good.

from ansible-service-broker.

shawn-hurley avatar shawn-hurley commented on August 25, 2024

I disagree

FormValue returns the first value for the named component of the query. POST and PUT body parameters take precedence over URL query string values.

FormValue returns the URL Query String parameters and yes will be overridden only if there is a form body with that key. To your point that we will not be sending a form and therefore do not have to worry about the query string being overridden. IMO this is a cleaner way of retrieving url� query parameters.

from ansible-service-broker.

jmrodri avatar jmrodri commented on August 25, 2024

I did some experimenting, the FormValue seems to do what we expect but it definitely is counter-intuitive to me.

It returned the value I expected for both POST and GET

[2017-07-25T09:47:32.27-04:00] [INFO] Request: "POST /v2/foo?accepts_incomplete=true HTTP/2.0\r\nHost: localhost:1338\r\nAccept: */*\r\nContent-Length: 245\r\nContent-Type: application/json\r\nUser-Agent: curl/7.53.1\r\nX-Broker-Api-Version: 2.9\r\n\r\n{\n  \"plan_id\": \"4c10ff42-be89-420a-9bab-27a9bef9aed8\",\n  \"service_id\": \"0aaafc10-132b-41a8-a58c-73268ff1006a\",\n  \"context\": {\n    \"platform\": \"kubernetes\",\n    \"namespace\": \"mysql-project\"\n  }\n  \"parameters\": {\n    \"MYSQL_USER\": \"username\"\n  }\n}"
form: map[]
postform: map[]
formvalue returns: true
async is: true
[2017-07-25T09:51:49.042-04:00] [INFO] Request: "GET /v2/foo?accepts_incomplete=true HTTP/2.0\r\nHost: localhost:1338\r\nAccept: */*\r\nContent-Length: 245\r\nContent-Type: application/json\r\nUser-Agent: curl/7.53.1\r\nX-Broker-Api-Version: 2.9\r\n\r\n{\n  \"plan_id\": \"4c10ff42-be89-420a-9bab-27a9bef9aed8\",\n  \"service_id\": \"0aaafc10-132b-41a8-a58c-73268ff1006a\",\n  \"context\": {\n    \"platform\": \"kubernetes\",\n    \"namespace\": \"mysql-project\"\n  }\n  \"parameters\": {\n    \"MYSQL_USER\": \"username\"\n  }\n}"
form: map[]
postform: map[]
formvalue returns: true
async is: true

Okay so I stand corrected.

from ansible-service-broker.

eriknelson avatar eriknelson commented on August 25, 2024

It is kind of a weird name for that method.

from ansible-service-broker.

jmrodri avatar jmrodri commented on August 25, 2024

For other HTTP methods, or when the Content-Type is not application/x-www-form-urlencoded, the request Body is not read, and r.PostForm is initialized to a non-nil, empty value.

The above had me worried because our Content-Type is application/json. But it seems to be smart enough to get what it needs. Even for a GET. Again for GETs it seems counter-intuitive to look ask a "form" for the query param values.

from ansible-service-broker.

jmrodri avatar jmrodri commented on August 25, 2024

Old, but part of why using FormValue and ParseForm worried me for POSTs with JSON.

https://nathanleclaire.com/blog/2013/11/30/fear-and-loathing-with-golang-and-angular-js/

from ansible-service-broker.

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.