Making HTTP request headers available in Lua callbacks

Hi all.

We currently use the CalledAET field to enable some advanced auto-routing scenarios when requests come in via DICOM C-Store. We also need access to this field in our Lua scripts when requests are uploaded against the HTTP server. Currently the Rest API only passes on Username and remoteIP fields from the request.

Could we go one step further and also include HTTP headers (perhaps using a whitelist of X-Orthanc-* prefix) in the Lua calbacks?

Is there any appetite for this change? I am happy to build it out if necessary.

Dom

Hello,

There is no wish on my side to integrate such a feature in the Orthanc core. Especially not in Lua scripting, that is designed for simple workflow.

Your wish is really application-specific, and you can already implement this by combining the C/C++/Python plugins together with the metadata mechanism:

1- If you are using Python (the simplest way), register a callback using “orthanc.RegisterRestCallback()”:
https://book.orthanc-server.com/plugins/python.html#extending-the-rest-api

2- Inside the callback, the “request” argument contains all the HTTP headers.

3- Upload the DICOM file with “orthanc.RestApiPost()”.

4- Once the instance is uploaded, modify its metadata using “orthanc.RestApiPut()” to store some of the HTTP headers:
https://book.orthanc-server.com/faq/features.html#accessing-metadata

HTH,
Sébastien-

Thanks for the reply.

Fair enough on not wanting to integrate the change.

Funnily enough, not 30m after posting, I realised the Python plugin API existed. I ported all my Lua scripts to Python and it worked mostly. The new requirement I had was a breeze with a custom Rest route.

However I have an issue with another script, where I make an external HTTP request via the HttpPost call. No matter how much I tinker, I do not receive anything in the body of the request:

url = “http://engvxmt6x8vxr.x.pipedream.net
body = “Example body”
resp = orthanc.HttpPost(url, body, “”, “”)

The body is always null on the receiving end. If you have time, can you try something similar. I am using latest orthanc-python docker image. I was using my own server, and also https://requestbin.com/ to inspect the body.

Dear Dominic,

Thanks for pointing out this problem! This issue was not specific to Python, it was due to a bug in the Orthanc core.

A fix is now available in the mainline, and will be available in forthcoming 1.7.0 release:
https://hg.orthanc-server.com/orthanc/rev/fe0e4ef52a72

Sébastien-

Great, thank you. Look forward to the release. I got around it by using the built in urllibe.request library. It seemed to work well enough.

I may have another bug for you (but it could just be my code). https://gist.github.com/dbousamra/33b69b4bd98f0aa85336e4d120747feb

I noticed this when porting some lua scripts. I left them unported for now. If you have time, try running this plugin, and comment back in L19. Just send it any DICOM file:

curl -X POST -H “Content-Type: application/dicom” -u orthanc:orthanc --data-binary @example_dicom.dcm localhost:8042/upload

I notice will work for a little bit, and then just hang, or occasionally it will never work. If I comment back out that OnStableStudy callback, it works fine.

Hi Dominic,

Thanks for reporting the issue. I confirm I’ve reproduced it. I’ve filed it in our bug tracker: https://bitbucket.org/sjodogne/orthanc/issues/179/orthanc-python-onchangecallgack-not-called

Best regards,

Alain.

Hello,

An update is available in the BitBucket issue:
https://bitbucket.org/sjodogne/orthanc/issues/179/orthanc-python-onchangecallgack-not-called#comment-57457958

Sébastien-

It’s now fixed: https://bitbucket.org/sjodogne/orthanc/issues/179/orthanc-python-onchangecallgack-not-called#comment-57463054