librelist archives

« back to archive

Re: [flask] How to add fields to a request?

Re: [flask] How to add fields to a request?

From:
Samuel Čavoj
Date:
2015-04-10 @ 12:52
Unless it is required that the clients send the requests, you could send 
it from your Flask server instead. You can use the 'requests' module for 
that[1].

HTTP does not support what you want to do due to security issues[2]. 307 
is not designed for that feature, and it can not change POST request 
data[3]. It is also available only in HTTP/1.1, which is not that much of 
a problem though.

[1]: 
http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests
[2]: http://www.alanflavell.org.uk/www/post-redirect.html
[3]: https://tools.ietf.org/html/rfc7231#section-6.4.7

On Apr 10, 2015 13:36, Jean Jordaan <jean.jordaan@gmail.com> wrote:
>
> Hi all 
>
> I posted the following to 
> http://stackoverflow.com/questions/29559860/how-to-add-fields-to-a-request as 
> well. 
>
> I have a login page. Upon submission if 'webmail' is selected, the request 
> should be redirected to the webmail server, with the credentials submitted but 
> under different keys. Here's what I'm trying now: 
>
>     if form.validate_on_submit(): 
>         if form.destination.data == 'webmail': 
>             form.rc_user.data = form.email.data 
>             form.rc_password.data = form.password.data 
>             return redirect('https://example.com/webmail/', code=307) 
>
> This almost works: the POST is redirected to webmail. However the values 
> submitted are the default values, not the assigned values. 
>
> I have some more issues though: 
>
> - the keys should be _user and _pass, but Flask seems to blow up with 
>   leading-underscore field names. 
>
> - I do not want to add these fields to the original class. I want to subclass 
>   upon submission, somewhat as follows: 
>
>     if form.validate_on_submit(): 
>         if form.destination.data == 'webmail': 
>             class WebmailLoginForm(LoginForm): 
>                 rc_user = EmailField('user', default=form.email.data) 
>             form = WebmailLoginForm(request.form) 
>             return redirect('https://example.com/webmail/', code=307) 
>
> When I do this, the added fields are not submitted. 
>
> I also tried messing with `request.form` (e.g. replacing the ImmutableDict with 
> my dict), but so far that hasn't worked either. 
>
> -- 
> jean                                              . .. .... //\\\oo///\\ 

Re: [flask] How to add fields to a request?

From:
Jean Jordaan
Date:
2015-04-11 @ 05:08
On Fri, Apr 10, 2015 at 7:52 PM, Samuel Čavoj <sammko@sammserver.com> wrote:
<snip good info>

Thank you for the help! I understand now.

Regards,
-- 
jean                                              . .. .... //\\\oo///\\