abhishek-ram / django-pyas2

AS2 file transfer Server built on Python and Django.
https://django-pyas2.readthedocs.io
GNU General Public License v3.0
78 stars 31 forks source link

How to add custom headers to an AS2 request #50

Open JamesInform opened 3 years ago

JamesInform commented 3 years ago

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

abhishek-ram commented 3 years ago

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.

JamesInform commented 3 years ago

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.

abhishek-ram commented 3 years ago

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.

JamesInform commented 3 years ago

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.

abhishek-ram commented 3 years ago

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

JamesInform commented 3 years ago

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

JamesInform commented 3 years ago

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

abhishek-ram commented 3 years ago

You can get it using self.payload.name On 31 Aug 2020, 5:49 PM +0530, JamesInform notifications@github.com, wrote:

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 — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe.

mmizuno303 commented 2 months ago

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

JamesInform commented 2 months ago

@mmizuno303 : I didn't get it managed.

chadgates commented 2 months ago

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.