# Pengines.js, Pengine create call - Certain options are ignored?

**URL:** https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714
**Category:** Help!
**Created:** [May 23, 2019, 4:22pm UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714 "2019-05-23T16:22:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)
#### Post date: [May 23, 2019, 4:22pm UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/1 "2019-05-23T16:22:36Z")

</div>

I’m using: SWI-Prolog version 8.0.2 on Ubuntu Linux 18.04.

I’m having trouble configuring the Pengine instance with certain options that are described in the `pengine_create/3` page:

[http://www.swi-prolog.org/pldoc/doc\_for?object=pengine\_create/1](http://www.swi-prolog.org/pldoc/doc_for?object=pengine_create/1)

For example, I try to pass an ID to the call yet the `Pengine.id` property remains `null` after the call.

I looked at the code for the client side Pengines code (i.e. - the code that makes Ajax calls to a Pengines server instance):

> <https://github.com/SWI-Prolog/packages-pengines/blob/463c37310f30a081370f0cf282c5e4a05c5b84d4/web/js/pengines.js>

I don’t see where the `id` property would ever get copied to the client side Pengine instance? There are only two object methods that are involved with these operations during a create call, at least from what I can see: `fillDefaultOptions()` and `copyOptions()`. Here is the relevant code:

```prolog
  // private functions
  function fillDefaultOptions(options) {
    for(let k in Pengine.options) {
      if ( Pengine.options.hasOwnProperty(k) &&
	   options[k] === undefined )
	options[k] = Pengine.options[k];
    }

    return options;
  }

  function copyOptions(to, from, list) {
    for(let i=0; i<list.length; i++) {
      let k = list[i];
      if ( from[k] !== undefined )
		to[k] = from[k];
    }
  }

```

And here are the calls made to those two methods from the constructor:

```prolog
  // create instance
  this.options = fillDefaultOptions(options);
  this.id = null;

  // On creation
  let src = this.options.src ? [this.options.src] : [];
  let createOptions = {
    src_text: this.script_sources(src).join('\n')
  };

  copyOptions(createOptions, options,
	      [ "format",
		"application",
		"ask",
		"template",
		"chunk",
		"destroy"
	      ]);

```

The problem I see when I trace out the code, is that `fillDefaultOptions()` only copies over properties that already exist in the object and only if the existing property is currently `undefined`, and `copyOptions()` only copies over properties that are in the provided property name list, which does not include a list element for the `id` property. In the end, the `id` property provided by the caller during the `pengine_create/3` call never gets assigned to the `id` property that exists in the object and when I inspect the Pengine object after the call the `id` property is `null`.

Am I wrong in this analysis?

---

<div class="post-metadata">

### Author: ![Ian](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/ian/32/1026_2.png) [@Ian](https://swi-prolog.discourse.group/u/Ian)
#### Post date: [May 23, 2019, 10:13pm UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/2 "2019-05-23T22:13:01Z")

</div>

The pengine\_create link is for passing options from a prolog client. In particular, the id option is shown as id(-ID) meaning you don’t pass the ID in, its given back to the caller, and indeed in the javascript version of the call, its set when a response is received back from the server e.g. at lines 431, 475 in the linked javascript code.

---

<div class="post-metadata">

### Author: ![prodog](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@prodog](https://swi-prolog.discourse.group/u/prodog)
#### Post date: [May 23, 2019, 11:11pm UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/3 "2019-05-23T23:11:57Z")

</div>

Thank Jan. My apologies. Despite programming in Prolog for several years, I had forgotten what the +/- signs mean in front of terms in a predicate’s call signature. I’ve got it now.

---

<div class="post-metadata">

### Author: ![jacintodavila](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jacintodavila/32/4357_2.png) [@jacintodavila](https://swi-prolog.discourse.group/u/jacintodavila)
#### Post date: [January 30, 2023, 4:12pm UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/4 "2023-01-30T16:12:17Z")

</div>

Hello. Has anybody tried passing other options (to http\_open) such as these?:

Pengine({ server: PENGINE\_URL, authenticate:true, authorization:“basic(user,password)”,  
//src\_text: le\_string,  
oncreate: handleCreate,  
//onprompt: handlePrompt,  
onoutput: handleOutput,  
onsuccess: showAnswer,  
onfailure: reportFailure  
})

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [January 30, 2023, 4:38pm UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/5 "2023-01-30T16:38:59Z")

</div>

I think you are talking JavaScript? If so, have a look at pengines.js in the Prolog distribution. It doesn’t pass such options, but it should be fairly easy to pass such options on (and save them in the Pengine object such that you can also pass them to the other HTTP requests).

I’m happy to handle a PR doing that.

---

<div class="post-metadata">

### Author: ![jacintodavila](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jacintodavila/32/4357_2.png) [@jacintodavila](https://swi-prolog.discourse.group/u/jacintodavila)
#### Post date: [January 31, 2023, 1:18am UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/6 "2023-01-31T01:18:16Z")

</div>

Yes! I changed pengines.js to support those options:

```prolog
  copyOptions(createOptions, options,
	      [ "format",
		"application",
		"ask",
		"template",
		"chunk",
		"destroy",
    "authorization",
    "authenticate"
	      ]);

```

and they seem to be passing in:

```prolog
Pengine create {src_text: '', format: 'json', authorization: 'basic(jacinto,'123')', authenticate: true}

```

But I still get this error:

```prolog

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

```

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [January 31, 2023, 8:55am UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/7 "2023-01-31T08:55:45Z")

</div>

Could it be it runs the initial “create” fine, but you get the issue in subsequent HTTP requests? You’ll need to propagate these settings into those requests as well.

---

<div class="post-metadata">

### Author: ![jacintodavila](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jacintodavila/32/4357_2.png) [@jacintodavila](https://swi-prolog.discourse.group/u/jacintodavila)
#### Post date: [February 8, 2023, 12:49am UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/8 "2023-02-08T00:49:39Z")

</div>

Thank you Jan. I checked. It does not pass the create connection. I tried to test it from another swipl process, like this:

```prolog
?- use_module(library(http/http_open)).
true.

```

trying setting the authorization to basic like this:

```prolog
?- http_set_authorization('http://localhost:3050/pengine/create', basic(jacinto, '123')). 
true.

```

and then trying:

```prolog
?- http_open('http://localhost:3050/pengine/create', In, [authorization(basic(jacinto, '123'))]),
   copy_stream_data(In, user_output),
   close(In).
ERROR: Unknown error term: permission_error(url,'http://localhost:3050/pengine/create') (status(401,Authorization Required))
E

```

Notice that it also produces an error with:

```prolog
?- http_open('http://localhost:3050/pengine/create', In, [authorization(digest(jacinto, '123'))]),
   copy_stream_data(In, user_output),
   close(In).
ERROR: Domain error: `authorization' expected, found `digest(jacinto,'123')'

```

The only way I could make it work is by loading:

```prolog
?- use_module(library(http/http_digest)).
true.

```

and then trying:

```prolog
?- http_open('http://localhost:3050/pengine/create', In, [authorization(digest(jacinto, '123'))]),
   copy_stream_data(In, user_output),
   close(In).
create('ca1f5988-820e-4872-8647-8cd17b442842',[slave_limit(3)]).
In = <stream>(0x563e192cccc0,0x563e192cce70).

```

But can I get the same effect of library(http/http\_digest) in JS?

---

<div class="post-metadata">

### Author: ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)
#### Post date: [February 8, 2023, 8:59am UTC](https://swi-prolog.discourse.group/t/pengines-js-pengine-create-call-certain-options-are-ignored/714/9 "2023-02-08T08:59:41Z")

</div>

> [@jacintodavila](#):
>
> But can I get the same effect of library(http/http\_digest) in JS?

That is a JavaScript question. I can’t imagine there is no way to specify digest authentication. Surely the browser can do it. You can also configure basic authentication in the Prolog server. That is very much deprecated unless you combine it with HTTPS as the password is sent in a trivially coded way over an insecure connection.
