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

What does request.query mean? #16

Open
killev opened this issue Mar 4, 2016 · 3 comments
Open

What does request.query mean? #16

killev opened this issue Mar 4, 2016 · 3 comments
Assignees
Labels

Comments

@killev
Copy link
Contributor

killev commented Mar 4, 2016

Hello guys,
I'm testing the form's processing and it behaves wierd.
my form:

<html>
<body>
<form method="POST" action = "/"><input name="param" type="text"/><input type="submit"/></form>
<br>
Submitted: {{submitted}}
</body>

</html>

My server code:

app.post("/") { (request:Request<AnyContent>)->Action<AnyContent> in
    print("Params:" ,request.params)
    print("Query:",  request.query)
    return Action<AnyContent>.render("index",context: ["submitted": ""])
}

app.get("/") { (request:Request<AnyContent>)->Action<AnyContent> in
    return Action<AnyContent>.render("index",context: ["submitted": ""])
}

The result is:

Merged: ["param": ["12345", "12345"]]
Query: ["param": ["12345"]]

Seems like mergedQuery adds the same value twice??? Why?? What query and mergedQuery are expected to be then?

@killev
Copy link
Contributor Author

killev commented Mar 4, 2016

However if add post parameters in form action like:
<form method="POST" action = "/?param1=123456" >

the result seems to be logical:
Merged: ["param1": ["123456"], "param": ["123456"]]
Query: ["param1": ["123456"]]

Regards,
Peter

@killev
Copy link
Contributor Author

killev commented Mar 4, 2016

If parameters names are the same:
<form method="POST" action = "/?param=123456"><input name="param" type="text"/><input type="submit"/></form>
then also logical but inconvenient a bit as it's not clear where parameter come from:
Merged: ["param": ["123456", "123456"]]
Query: ["param": ["123456"]]

@killev killev changed the title What does request.query means? What does request.query mean? Mar 4, 2016
@dileping dileping added the bug label Mar 4, 2016
@dileping
Copy link
Member

dileping commented Mar 4, 2016

@killev Thanks for reporting. Will try to fix in the nearest version.

query should be just from the URL
mergedQuery is both URL and body.

you can as well access just body data with request.body.asFormUrlEncoded()

@dileping dileping added this to the 0.3.x: current stable milestone Mar 4, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants