Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

NPN_PostURLNotify treating my headers as data

40 views
Skip to first unread message

Rudi Sherry

unread,
Sep 18, 2012, 1:28:04 PM9/18/12
to dev-tech...@lists.mozilla.org
Hi all,

I am having trouble adding headers to a POST using NPN_PostURLNotify in Firefox 15.0.1. As far as I know I'm using NPN_PostURLNotify correctly, but it is putting my header in the data section of the POST.

I tried two ways: one with a memory buffer and one with a file, with the same results.

I have tried both '\n' and '\r\n' with the same results.

Firefox 14.0.1, for memory buffer, shows the same results (I didn't try the file for that).

Is there something I'm missing?

("instance" is my NPP instance).

// Use Memory Buffer
NPError err = NPERR_NO_ERROR;
static const char *sHeaders = "Custom:\tfoobar\nCookie:\tfoobar\n\nPostData\n";
NPError err = NPN_PostURLNotify( instance,
"http://host.com/home.html", NULL,
strlen(sHeaders), sHeaders, false, (void *) 1000 );


// Use file
static const char *sFilename = "C:\\Temp\\tempdata.txt<smb://Temp//tempdata.txt>";
static const char *sCustomHeader = "Custom:\tfoobar\n";
static const char *sCookieHeader = "Cookie:\tfoobar\n";
static const char *sLF = "\n";
static const char *sPostData = "PostData\n";
FILE *f = NULL;
errno_t ferr = fopen_s( &f, sFilename, "wb" );
if ( ferr == 0 && f != NULL )
{
fwrite( sCustomHeader, 1, strlen(sCustomHeader), f );
fwrite( sCookieHeader, 1, strlen(sCookieHeader), f );
fwrite( sLF, 1, strlen(sLF), f );
fwrite( sPostData, 1, strlen(sPostData), f );
fclose( f );
NPError err = NPN_PostURLNotify( instance, "http://host.com/home.html",
NULL, strlen(sFilename), sFilename, true, (void *) 1000 );
}


// Fiddler shows this for both:

POST http://host.com/home.html HTTP/1.1
Host: host.com<http://host.com>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:15.0) Gecko/20100101 Firefox/15.0.1
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Content-length: 41

Custom: foobar
Cookie: foobar

PostData

Rudi Sherry

unread,
Sep 18, 2012, 5:16:08 PM9/18/12
to dev-tech...@lists.mozilla.org
More info: Chrome works just fine.
> _______________________________________________
> dev-tech-plugins mailing list
> dev-tech...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-tech-plugins

Rudi Sherry

unread,
Sep 18, 2012, 5:30:06 PM9/18/12
to Rudi Sherry, dev-tech...@lists.mozilla.org
I should have searched bugzilla: need to have my own Content-Length custom header as well:

https://bugzilla.mozilla.org/show_bug.cgi?id=457916

That works.
0 new messages