1

I'm trying to set headers for a simple HTTP request in SilkJS.. the request goes through fine but without my headers..

The curl.setHeader() method just returns 'undefined', from what I can read in the documentation (http://www.silkjs.net/documentation/builtin/curl#curl-setHeader), it should return integer 0 for success or an error code otherwise.. is 'undefined' some kind of error code ?!

Here's a simple test to reproduce the problem:

SilkJS> var curl = require('builtin/curl');
undefined
SilkJS> curl
[object Object]
SilkJS> var handle = curl.init('http://www.google.com/')
undefined
SilkJS> handle
[object Object]
SilkJS> var status = curl.setHeader(handle, 'asdf=asdf')
undefined
SilkJS> status
undefined
Niklas9
  • 8,816
  • 8
  • 37
  • 60

2 Answers2

0

The documentation is bad, it's describing the format of setting a cookie "NAME=CONTENT" rather than the expected way to set a header, "NAME: CONTENT".

I noticed this when I went through the source code.

The status flag is still undefined though, but now I can see that the header is there in the http request:

SilkJS> var status = curl.setHeader(handle, 'asdf: asdf')
undefined
SilkJS> status
undefined
SilkJS> curl.perform(handle, 1)
* About to connect() to www.google.com port 80 (#0)
*   Trying 74.125.143.103... * connected
> GET / HTTP/1.1
User-Agent: SilkJS/1.0
Host: www.google.com
Accept: */*
asdf: asdf

< HTTP/1.1 302 Found
...
Niklas9
  • 8,816
  • 8
  • 37
  • 60
0

Thanks Nik.

See this page:

http://silkjs.net/documentation/cURL

You are using the lowest level routines for accessing curl. There is a much higher level class for accessing curl that has a JavaScript flavor instead of a "C" style procedure style.

Anything that is builtin.* method is low-level, with absolutely no error checking. You can pass invalid values as parameters to these functions and your program will core dump (crash).

The intent is to write JavaScript classes or interfaces that do the error checking and those would call the builtin methods.

mschwartz
  • 63
  • 3