abhishek-ram/django-pyas2

How to add custom headers to an AS2 request

Opened this issue ยท 11 comments

Hi all

I am currently trying to communicate with the US Food and Drug Agency FDA via AS2.

I need to send specific information via an extra header, that I need to add to the AS2 post request, that django-as2 is doing againt fda's AS2 gateway.

How could I add such an extra header to the request? It would be very help if someone could point to a file / function where I can add my custom code, in case that there is no such functionality already available in the package.

More information about fda's header handling can be found here:
https://www.fda.gov/industry/about-esg/esg-appendix-f-as2-header-attributes

Cheers
James

Including custom headers is not supported right now. If the headers are static per partner and does not change per message we could add it to the partner config and make it a part of pyas2.

If not you would need to fork the repo and update pyas2.models.Message.send_message to include the custom headers.

Thanks for the quick response.

The headers differ based on the content of the file that is transferred.

So I will have to modify this manually.

Thinking about it, I think django-pyas2 can add support for custom headers. One way it could work is that we have a setting SEND_MESSAGE_CUSTOM_HEADER_METHOD which would be the path to a function my_lib.get_headers_for_send_message which would return a dictionary that would be appended to the request headers.

That sound good! So, "my_lib.get_headers_for_send_message" would be a custom function, right?

It would be important that this function has access to the file content that is going to be send, as well as the file name. I for myself are planung to put header information into the file name and parse that out before sending the file to the AS2 partner.

Yes I was planning on passing the built as2message as an parameter to it.

Yep. And having access to the filename that is currently processed would be great.

Hi!

Including custom headers is not supported right now. If the headers are static per partner and does not change per message we could add it to the partner config and make it a part of pyas2.

If not you would need to fork the repo and update pyas2.models.Message.send_message to include the custom headers.

I have used this entry point and everything works fine.

But I have one additional question:
Using the self and payload parameters, I am not able to retrieve the original filename as it was put into the outgoing directory.

Is there a way to get the original filename at this point?

James

I know this is a super-old thread, but @JamesInform , how did this approach end up working for you? We are in the same situation where we need to include the x-cyclone headers but so far have seen no "easy" way to accomplish this. Appreciate any feedback/insight on your experience that you feel comfortable sharing

@mmizuno303 : I didn't get it managed.

Just some thoughts/questions:
The application that generates the file to be sent, could that one also create an additional file containing the headers? Then we could extend to read the headers to be used for that particular file and extend the SendMessage function to accept the content of that file as additional headers. A filename pattern could be applied, where header data would exist in a second file with same name but ending .headers .
Also the send message UI function would have to be extended to add an optional headers file.