Test Results

About us

 Redirecting a Web Request
Total posts: 3
 Author Redirecting a Web Request
Margarita Garcia B

04.04.2007 18:07:05
Registered user

I'm learning how to use your components.  I have a hopefully simple question.  

I want to receive a web request, read the URL params to perform a background-time-consuming task and redirect the web request to a new URL with a 302 response so that the user doesn't have to wait for the task to finish.

How can I do this?


Margarita Garcia.
Danijel Tkalcec [RTC]

04.04.2007 18:22:46
Registered user
First, if you want to send a response and then continue processing data on the Server, you need to have a separate thread to process the long-running job, since you can't send a response and continue blocking the connection thread.

If you have created your background thread for the lengthy job processing, you would give your thread the job (not wait for the job to complete - just "give it" and let it work), then prepare your HTTP Response header and normally exit the OnCheckRequest/OnDataReceived event, so the next request (which might come from the same client) could be processed.

To have the Browser redirected to a different URI, all you need to do is set the "Response['Location']" HTTP header to your destination URI and set Response.Status(302,'Redirect'). After you call "Write", your prepared header will be sent to the Client.

Here is an example code for the OnDataReceived event:

with Sender as TRtcDataServer do
  if Request.Complete then
    { You can start your job here.
      If the Client has send you some data,
      you can use the "Read" method here to get it. }
    // myData := Read;

    Write('We will be redirecting to "myredirect.htm"'); // send the response
Should you require further assistance, let me know.

Best Regards,
Danijel Tkalcec
Margarita Garcia B

04.04.2007 18:37:01
Registered user
Thanks a lot for your quick response.  It was exactly what I needed, I've it working already :)