Project

General

Profile

Actions

Bug #768

closed

cookies in WidgetSet mode WApplication

Added by Max Quatember about 13 years ago. Updated almost 13 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
03/22/2011
Due date:
% Done:

0%

Estimated time:

Description

In an WApplication running in WidgetSet mode it is not possible to write and read cookies

Please see attached test-files.


Files

test_widgetset_cookie.zip (1.16 KB) test_widgetset_cookie.zip Max Quatember, 03/22/2011 01:21 PM
Actions #1

Updated by Koen Deforche about 13 years ago

  • Status changed from New to Resolved
  • Assignee set to Koen Deforche

Hey Max,

Thanks. Apparently, you need to enable security-trodden cookies explicitly. The latest git seems to work fine, but may need more testing on more browsers ...

Regards,

koen

Actions #2

Updated by Max Quatember about 13 years ago

Hi Koen!

Tested your changes with Firefox 4.0 on Windows and latest Chrome 10.0 also on Windows.

Firefox gives me a JavaScript error messagebox with:

Wt internal error: [Exception... "Security error" code: "1000" nsresult: "0x805303e8 (NS_ERROR_DOM_SECURITY_ERR)" location: "http://localhost:8080/test_cookies.wtjs?div=test Line: 173"], code: 1000, description: undefined

and Chrome only shows "loading..." after the click on "write cookie". In Chrome JavaScript-debugger I get the error:

XMLHttpRequest cannot load http://localhost:8080/test_cookies.wtjs?wtd=rWjmEF0EgWujN7AR. Origin null is not allowed by Access-Control-Allow-Origin.

test_cookies.wtjs POST http://localhost:8080/test_cookies.wtjs?wtd=rWjmEF0EgWujN7AR undefined (undefined)

Best regards,

Max

Actions #3

Updated by Koen Deforche about 13 years ago

  • Status changed from Resolved to InProgress

Hey Markus,

I must have tested with the wrong browsers, then ... Hang on.

Regards,

koen

Btw. how did you like the match ?

Actions #4

Updated by Max Quatember about 13 years ago

Hi Koen!

No problem, I'll wait...

Regards,

Max

I fell asleep in the middle of the first half ;-)

Actions #5

Updated by Koen Deforche about 13 years ago

  • Status changed from InProgress to Feedback

Hey Max,

I tested with Chrome and Firefox 4 and it works for me. This is how I tested using the widgetset feature example:

diff --git a/examples/feature/widgetset/hello.C b/examples/feature/widgetset/hello.C
index 993296d..0e6d1de 100644
--- a/examples/feature/widgetset/hello.C
+++ b/examples/feature/widgetset/hello.C
@@ -30,6 +30,10 @@ HelloApplication::HelloApplication(const Wt::WEnvironment& env, bool embedded)
 {
   Wt::WContainerWidget *top;

+  try {
+    std::cerr << env.getCookie("test") << std::endl;
+  } catch (...) { }
+
   setTitle("Hello world");

   if (!embedded) {
@@ -90,6 +94,7 @@ void HelloApplication::greet()
    * Update the text, using text input into the nameEdit_ field.
    */
   greeting_->setText("Hello there, " + nameEdit_->text());
+  setCookie("test", "hey there too", -1);
 }

 Wt::WApplication *createApplication(const Wt::WEnvironment& env)
Actions #6

Updated by Max Quatember about 13 years ago

Hi Koen!

You are right, the example you tested works fine.

The problem is that I do not set the cookie in the Application constructor but in an event handler.

(In the clicked() signal of a Button for example...)

Is this possible? Because I have to wait for user input...

My Application looks like this:

@

class TestWidgetSet : public Wt::WApplication

{

Wt::WContainerWidget* myTop;

public:

TestWidgetSet( const Wt::WEnvironment& env )

: Wt::WApplication( env )

{

bindWidget( myTop = new Wt::WContainerWidget(), *env.getParameter( "div" ) );

auto myEdit = new Wt::WLineEdit;

std::string cookie;

try

{

cookie = environment().getCookie("TestWidgetSet");

}

catch( std::runtime_error& e )

{

log( "info" ) << "getCookie(): " << e.what();

}

myEdit->setText( cookie );

myTop->addWidget( myEdit );

auto p = new Wt::WPushButton( "write cookie" );

myTop->addWidget( p );

p->clicked().connect( SLOT( this, TestWidgetSet::Clicked ) );

}

void Clicked()

{

setCookie( "TestWidgetSet", "howdie", INT_MAX );

myTop->clear();

auto p = new Wt::WPushButton( "redirect" );

p->clicked().connect( SLOT( this, TestWidgetSet::Redirect ) );

myTop->addWidget( p );

}

void Redirect()

{

redirect( "www.webtoolkit.eu" );

}

};

@

Actions #7

Updated by Koen Deforche about 13 years ago

Hey Max,

The example is actually setting the cookie from inside an event (in the greet() method connected to the button).

Regards,

koen

Actions #8

Updated by Max Quatember about 13 years ago

Hi Koen!

I tried your example.

I think my problem has something to do with my setup...

If I'm setting the cookie in the constructor of the WApplication everything works.

If I'm setting the cookie in the event handler it's not there.

Thank you Koen for your efforts.

Best regards,

Max

Actions #9

Updated by Koen Deforche about 13 years ago

Hey Max,

There was something wrong with cookies and websockets. Perhaps this caused the problem ? This should be fixed in latest git.

Regards,

koen

Actions #10

Updated by Max Quatember almost 13 years ago

Hi Koen!

Just upgraded to latest git.

WidgetSetMode and Cookies work for latest Safari and latest Firefox, but:

WidgetSetMode in latest Chrome (11.0.696.60 on win xp) is broken. I cannot see anything of my application and the JavaScript Debugger gives me following:

"XMLHttpRequest cannot load http://localhost:8080/test_cookies.wtjs?wtd=kAi1OzVu7oyPAOdI. Origin null is not allowed by Access-Control-Allow-Origin."

The problem is reproduceable with the originally attached test case.

Maybe you can help me.

Best regards,

Max

Actions #11

Updated by Koen Deforche almost 13 years ago

Hey Max,

I installed the latest chrome on Windows. I couldn't reproduce the problem (although setting the cookie didn't work properly, there seems to be something wrong with detecting support for cookies).

Nevertheless, I might have found a possible problem, in case the hosting HTML page is from a local file (file:///) and not a website. Perhaps you were testing it like that ? I've fixed this in latest git.

Regards,

koen

Actions #12

Updated by Max Quatember almost 13 years ago

Hi Koen!

Tested it like this! Excuse me that I didn't told you.

I will test latest git in the next few days and give you feedback.

Best regards,

Max

Actions #13

Updated by Max Quatember almost 13 years ago

Hi Koen!

Works fine with latest Wt! Is resolved for me.

Best regards,

Max

Actions #14

Updated by Koen Deforche almost 13 years ago

  • Status changed from Feedback to Resolved
Actions #15

Updated by Koen Deforche almost 13 years ago

  • Target version set to 3.1.10
Actions #16

Updated by Koen Deforche almost 13 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF