httpGetHeader() invalid argument v3.16

Discussions about product bugs & problems!
Note: This is no replacement for the Official ETM Support!
5 posts • Page 1 of 1
vedadramovic
Posts:121
Joined: Mon Apr 07, 2014 10:36 am

httpGetHeader() invalid argument v3.16

Post by vedadramovic »

Hello,
in version v3.16, when using function
httpGetHeader(int idxm, string key)

like
"string cookie = httpGetHeader(connIdx, "Cookie");"

connIdx is int

I get warning

Invalid argument in function, ..., httpGetHeader

Is there solution for this warning?
Best regards,

kilianvp
Posts:443
Joined: Fri Jan 16, 2015 10:29 am

Re: httpGetHeader() invalid argument v3.16

Post by kilianvp »

this means your browser dont send a Cookie HTTP Header

just see add a

Code: Select all

DebugN(headernames);
inside your callback to see all Headers

the 3.16 help example has the same problem:

//edit GET wont work.. POST works

Code: Select all

#uses "CtrlHTTP"
int MAXLENGTH = 100 * 1024 * 1024;   //100 MB
  
main()
{
  //starts the HTTP Server at Port 12000 without authentication
  httpServer(FALSE,12000);
  httpSetMaxContentLength(MAXLENGTH);  
  /* Use http://localhost:12000/callBack1 URL in order to show the data */
  /* httpConnect registers the function "callBack1" as a Web resource under the name "callBack1" */
 
  httpConnect("callBack1","/callBack1");
}
//See rfc1867 for detailed information on form-based file uploads in HTML
 string callBack1(blob content, string user, string ip, dyn_string headernames, dyn_string headervalues, int connIdx)
{
   string formDoc = "Test" +
                   "" +
                   "Example page" +
                   "";
   string contentType = httpGetHeader(connIdx, "Content-Type"); //Returns the value of the header
   DebugN("Content type:",contentType);
   return formDoc;  //Returns the form
}
Content-Type is a HTTP Header sent by the Server not the client.
WCCOActrl2:2018.05.10 11:29:32.215[dyn_string 10 items
WCCOActrl2: 1: "Host"
WCCOActrl2: 2: "Connection"
WCCOActrl2: 3: "Cache-Control"
WCCOActrl2: 4: "Upgrade-Insecure-Requests"
WCCOActrl2: 5: "User-Agent"
WCCOActrl2: 6: "Accept"
WCCOActrl2: 7: "DNT"
WCCOActrl2: 8: "Accept-Encoding"
WCCOActrl2: 9: "Accept-Language"
WCCOActrl2: 10: "Cookie"
WCCOActrl2:]
and the warning
Invalid argument in function, ..., httpGetHeader

appears in the Logviewer

vedadramovic
Posts:121
Joined: Mon Apr 07, 2014 10:36 am

Re: httpGetHeader() invalid argument v3.16

Post by vedadramovic »

Thank you Kilian,
this warning is not present in earlier versions.

Gertjan van Schijndel
Posts:634
Joined: Mon Aug 02, 2010 10:37 am

Re: httpGetHeader() invalid argument v3.16

Post by Gertjan van Schijndel »

What does httpGetAllHeaders() return?
If this also produces a warning than the specified 'connIdx' is wrong.
You should use the connection index value that is returned as argument in the callback function after the 'headerValues'.

Otherwise this header is not available and apparently since 3.16 that results also in this 'invalid argument' warning.
So the only way to prevent the warning is to check first if the client has actually passed the header.

vedadramovic
Posts:121
Joined: Mon Apr 07, 2014 10:36 am

Re: httpGetHeader() invalid argument v3.16

Post by vedadramovic »

httpGetAllHeaders() returns:
WCCOActrl106:2018.05.25 14:15:04.804[mapping 4 items
WCCOActrl106: "User-Agent" : "Apache XML RPC 3.0 (Jakarta Commons httpclient Transport)"
WCCOActrl106: "Content-Length" : "210"
WCCOActrl106: "Content-Type" : "text/xml"
WCCOActrl106: "Host" : "127.0.0.1:8002"

This header "Cookie" is not present.
I think it would be easier if warning was not issued if the header is not present (like in previous versions), rather than checking if it is present.

This way logs are clogged with this warning.
Best regards,

5 posts • Page 1 of 1