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.



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:


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 = “
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 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:


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).

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:

Best regards,



An update is available in the BitBucket issue:


It’s now fixed: