redirect an upload

79 views
Skip to first unread message

Dave S

unread,
May 26, 2017, 3:35:41 PM5/26/17
to web...@googlegroups.com
I have a function shove() with decorator @request.restful(), used to handle uploading a file, and as part of moving to https, I have a check for https and redirect if it isn't s-full.


@request.restful()
def shove():
   
if not request.is_https:
       redirect
(URL(shove, args=request.args, scheme=https, host=True))
   
def POST(*args, **vars):
       etc


This almost works, but the file being uploaded is a zip-file (by extension and by method of creation),

and the redirect is to "https://myserver.my/myapp/default/shove.zip/myarg0/myarg1" (with the dot-zip elided, but with name not yet hashed).  [Too much detail:  myarg0 is the tablename for the upload file tracking]
How do I get the dot-zip in the right place?

Moving the check into the POST doesn't change the behavior.

Thanks

Dave
/dps




Marlysson Silva

unread,
May 29, 2017, 8:34:44 AM5/29/17
to web2py-users
You tried use the request.requires_https() in your models?

Dave S

unread,
May 30, 2017, 2:48:06 AM5/30/17
to web2py-users


On Monday, May 29, 2017 at 5:34:44 AM UTC-7, Marlysson Silva wrote:
You tried use the request.requires_https() in your models?

 
No, I didn't -- missed completely on that.  However, it looks like it's a decorator I need to use in the controller
        (In this case, in front of call())
rather than a function directly invocable in the model file.  And it doesn't seem to combine well with an auth decorator.

/dps
 

Marlysson Silva

unread,
May 30, 2017, 5:59:58 PM5/30/17
to web2py-users
The request.requires_https() is written on top of models file once time..

And to respect of redirect .. Could you use the absolute URL .. Create completly

The doc of URL() have this..

Dave S

unread,
May 31, 2017, 2:15:46 AM5/31/17
to web2py-users

I went back to the model file with mixed results.  The first try, I had a typo that meant things were broken but I wasn't seeing the tickets right away.

The mixed results:

A linux client, using libcurl, is reporting what seems to be a correct redirect now.  I still need to tell libcurl what to do with that. (Per libcurl recommendations, I'll use the rx'd URL as the new destination and retry the send; the option to automatically follow isn't recommended.)

A winnders client, using wininet, just keeps sending to port 80.  I'm trying to get tcpdump to tell me if the redirect is sent; my first attempts don't see it.

Changing the clients to start on port 443 works, but I want to have the redirs work, too.

/dps

Dave S

unread,
Jun 2, 2017, 7:34:56 PM6/2/17
to web2py-users


On Tuesday, May 30, 2017 at 11:15:46 PM UTC-7, Dave S wrote:


On Tuesday, May 30, 2017 at 2:59:58 PM UTC-7, Marlysson Silva wrote:
The request.requires_https() is written on top of models file once time..

And to respect of redirect .. Could you use the absolute URL .. Create completly

The doc of URL() have this..


I went back to the model file with mixed results.  The first try, I had a typo that meant things were broken but I wasn't seeing the tickets right away.

The mixed results:

A linux client, using libcurl, is reporting what seems to be a correct redirect now.  I still need to tell libcurl what to do with that. (Per libcurl recommendations, I'll use the rx'd URL as the new destination and retry the send; the option to automatically follow isn't recommended.)

Redir works for a browser (to an actual webpage, not a 
A winnders client, using wininet, just keeps sending to port 80.  I'm trying to get tcpdump to tell me if the redirect is sent; my first attempts don't see it.

This is because the POST has to be completely sent before this technique works, and my wininet clients don't seem to cleanly end the send.  Some minutes after the client tells the user that it is done, Rocket throws up its hands and says "broken pipe". (I've a group post about that, probably sometime last year).  For browsers and libcurl clients, the POST completes, the redir is sent, the client uses the new URL, and and everyone lives happily ever after.

Is there a way to tell Rocket to send the redir as soon as the URL is received?  This is typically in the first packet after the connection opening handshakes; does Rocket ever look at URLs, or is the routing extracted at a higher level?  (My first read of rocket.py didn't clue me in very far.)

 
Changing the clients to start on port 443 works, but I want to have the redirs work, too.

Again, varies by client.  wininet is picking up that the scheme is HTTPS,  but it doesn't seem to change ports to reflect that.

/dps
 

Dave S

unread,
Jun 2, 2017, 9:11:05 PM6/2/17
to web2py-users


On Friday, June 2, 2017 at 4:34:56 PM UTC-7, Dave S wrote:


On Tuesday, May 30, 2017 at 11:15:46 PM UTC-7, Dave S wrote:


On Tuesday, May 30, 2017 at 2:59:58 PM UTC-7, Marlysson Silva wrote:
The request.requires_https() is written on top of models file once time..

And to respect of redirect .. Could you use the absolute URL .. Create completly

The doc of URL() have this..


I went back to the model file with mixed results.  The first try, I had a typo that meant things were broken but I wasn't seeing the tickets right away.

The mixed results:

A linux client, using libcurl, is reporting what seems to be a correct redirect now.  I still need to tell libcurl what to do with that. (Per libcurl recommendations, I'll use the rx'd URL as the new destination and retry the send; the option to automatically follow isn't recommended.)

Redir works for a browser (to an actual webpage, not a 
[I better finish this ...]
I'm not using an api URL in the browser), and for a libcurl client to an api URL.

A winnders client, using wininet, just keeps sending to port 80.
I'm trying to get tcpdump to tell me if the redirect is sent; my first attempts don't see it.

This is because the POST has to be completely sent before this technique works, and my wininet clients don't seem to cleanly end the send.  Some minutes after the client tells the user that it is done, Rocket throws up its hands and says "broken pipe". (I've a group post about that, probably sometime last year). 

Looks like that's about 10 minutes.  The POST DATA sits in a tmp file during that time; if my app accepts the data it gets moved into the uploads directory, if I don't (as when I'm trying to do a redir) it gets rm'd.
 
For browsers and libcurl clients, the POST completes, the redir is sent, the client uses the new URL, and and everyone lives happily ever after.

Is there a way to tell Rocket to send the redir as soon as the URL is received?  This is typically in the first packet after the connection opening handshakes; does Rocket ever look at URLs, or is the routing extracted at a higher level?  (My first read of rocket.py didn't clue me in very far.)

 
Changing the clients to start on port 443 works, but I want to have the redirs work, too.

Again, varies by client.  wininet is picking up that the scheme is HTTPS,  but it doesn't seem to change ports to reflect that.



Okay, had to be explicit about the port in InternetConnect(), and also set the SECURE flag in the HttpOpenRequest() call.

 
/dps


e27...@gmail.com

unread,
Jun 4, 2017, 12:04:47 PM6/4/17
to web2py-users
I do not know what is going on.

Dave S

unread,
Jun 12, 2017, 9:35:23 PM6/12/17
to web2py-users

[continuing the subthread on broken pipes]

On Friday, June 2, 2017 at 6:11:05 PM UTC-7, Dave S muttered and muttered:
 
A winnders client, using wininet, just keeps sending to port 80.
I'm trying to get tcpdump to tell me if the redirect is sent; my first attempts don't see it.

This is because the POST has to be completely sent before this technique works, and my wininet clients don't seem to cleanly end the send.  Some minutes after the client tells the user that it is done, Rocket throws up its hands and says "broken pipe". (I've a group post about that, probably sometime last year). 

Looks like that's about 10 minutes.  The POST DATA sits in a tmp file during that time; if my app accepts the data it gets moved into the uploads directory, if I don't (as when I'm trying to do a redir) it gets rm'd.
 
 
This does not happen if the upload file is in the neighborhood of 16K, but does happen if it is 8M.  I'm not sure what the threshold is for exhibiting this behavior.  I may poke around to narrow it down more.

/dps






Reply all
Reply to author
Forward
0 new messages