Making HTTP request headers available in Lua callbacks

64 views
Skip to first unread message

Dominic Bou-Samra

unread,
May 4, 2020, 8:20:46 PM5/4/20
to Orthanc Users
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

Sébastien Jodogne

unread,
May 5, 2020, 1:15:29 AM5/5/20
to Orthanc Users
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()":

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:

HTH,
Sébastien-

Dominic Bou-Samra

unread,
May 5, 2020, 7:49:37 PM5/5/20
to Orthanc Users
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:

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.

Sébastien Jodogne

unread,
May 6, 2020, 2:43:12 AM5/6/20
to Orthanc Users
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:

Sébastien-
Message has been deleted

Dominic Bou-Samra

unread,
May 7, 2020, 1:38:36 AM5/7/20
to Orthanc Users
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.

Alain Mazy

unread,
May 15, 2020, 10:37:38 AM5/15/20
to Dominic Bou-Samra, Orthanc Users
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.


--
You received this message because you are subscribed to the Google Groups "Orthanc Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orthanc-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orthanc-users/7e8b596a-0217-49bc-a049-e70520338104%40googlegroups.com.


--

Alain Mazy / Orthanc-Studio Manager & Software Developer
a...@osimis.io / +32 494 31 67 27

Osimis

OSIMIS S.A. 
Quai Banning 6BE-4000 Liège 
www.osimis.io

Twitter LinkedIn


Sébastien Jodogne

unread,
May 18, 2020, 2:31:09 PM5/18/20
to Orthanc Users
To unsubscribe from this group and stop receiving emails from it, send an email to orthanc-users+unsubscribe@googlegroups.com.

Alain Mazy

unread,
May 19, 2020, 10:21:31 AM5/19/20
to Sébastien Jodogne, Orthanc Users

To unsubscribe from this group and stop receiving emails from it, send an email to orthanc-user...@googlegroups.com.


--

Alain Mazy / Orthanc-Studio Manager & Software Developer
a...@osimis.io / +32 494 31 67 27

Osimis

OSIMIS S.A. 
Quai Banning 6BE-4000 Liège 
www.osimis.io

Twitter LinkedIn


--
You received this message because you are subscribed to the Google Groups "Orthanc Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orthanc-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/orthanc-users/3bae1aa9-6a81-4a60-9b84-4aa04703f73f%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages