Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to modify request headers #26

Closed
Imoteph opened this issue Aug 22, 2023 · 20 comments
Closed

How to modify request headers #26

Imoteph opened this issue Aug 22, 2023 · 20 comments

Comments

@Imoteph
Copy link

Imoteph commented Aug 22, 2023

Hi,

is there a way to modify the HTTP request headers that JBrowseR sends? I have got a flask server providing the data via stream and an R app set up. Now I would like to modify the request headers, that are being sent to the flask server, from the R side by adding an additional field. I suspect the headers are currently created somewhere in the JS backend and only the request bodies are created as JSONs in R, right?

Thanks a lot!

@cmdcolin
Copy link
Contributor

are you referring to requests for general data files like bam, vcf, etc? we have the concept of 'internetaccounts' that can modify headers and such but it is a little advanced (and I haven't tested those in JBrowseR either)

@Imoteph
Copy link
Author

Imoteph commented Aug 23, 2023

Yes indeed, the data are contents of the bams,
As mentioned, I have a flask server which I need to secure at least with an API key that needs to be sent by the shiny app for every request, to secure that only this application gets access. Hence I would like to add some information to the HTTP request header

@cmdcolin
Copy link
Contributor

If you are not totally tied to JBrowseR, you could use our 'embedded components' potentially, and we have examples of using the "internet accounts" this way.

here is the example with using internetAccounts for our embedded components https://jbrowse.org/storybook/lgv/main/?path=/docs/using-internetaccounts--docs (you can open the track selector on this page and see that it pops up a dialog to enter an oauth token when you turn on the "google drive bigwig" track)

Source code for that example https://github.com/GMOD/jbrowse-components/blob/main/products/jbrowse-react-linear-genome-view/stories/examples/WithInternetAccounts.tsx

The internet accounts are specified in the config by adding a internetAccountId alongside the uri. the ExternalOAuthToken internetAccount type prompts the user for a OAuth token on opening the track. we could make another example so that instead of prompting, you supply the token via the config also

I am new to JBrowseR as a maintainer (I mostly work on the core codebase including the embedded components, but I have taken on some maintainership of JBrowseR) but if you are invested in using JBrowseR let me know and I can do some investigation for how to set this up in JBrowseR

@Imoteph
Copy link
Author

Imoteph commented Aug 23, 2023

Thanks for the links and help so far!

But unfortunately, I am completely tied to JbrowseR, as the mail application is a shiny App, where the requested data is then shown. It would be super nice and helpful if you find some time to investigate how this is set in JBrowseR

@Imoteph
Copy link
Author

Imoteph commented Aug 30, 2023

Hi @cmdcolin

did you find some time to dive a bit into JbrowseR how to set up this request?

@cmdcolin
Copy link
Contributor

I just started a possible approach here to add plugins, and the plugins could add a internetaccount. thanks for the ping though...this PR is not complete as posted but will let you know when I get update

#27

@cmdcolin
Copy link
Contributor

cmdcolin commented Sep 11, 2023

I have continued some work on this with creating a demo plugin that can add custom HTTP headers (https://github.com/cmdcolin/jbrowse-plugin-modifyhttpheaders) and pushed forward this branch a little bit. Haven't fully tested this in JBrowseR land yet but will keep you posted. if you can confirm you're still interested in this, will keep me motivated on it :)

@cmdcolin
Copy link
Contributor

current PR progress here, allows adding plugins from HTTP urls and custom internet accounts

@cmdcolin
Copy link
Contributor

specific code that is adding the custom header https://github.com/cmdcolin/jbrowse-plugin-modifyhttpheaders/blob/main/src/index.ts#L37-L46

@Imoteph
Copy link
Author

Imoteph commented Sep 12, 2023

I have continued some work on this with creating a demo plugin that can add custom HTTP headers (https://github.com/cmdcolin/jbrowse-plugin-modifyhttpheaders) and pushed forward this branch a little bit. Haven't fully tested this in JBrowseR land yet but will keep you posted. if you can confirm you're still interested in this, will keep me motivated on it :)

Yes, I am still interested!! Looking forward to see how this then can be used into JbrowseR.

@Imoteph
Copy link
Author

Imoteph commented Sep 12, 2023

And thanks for the update!

@Imoteph
Copy link
Author

Imoteph commented Sep 25, 2023

@cmdcolin

don´t take it as push :) . Just wanted to know if you have some further news to this topic.

@cmdcolin
Copy link
Contributor

no news yet, apologies. will keep you posted

not sure if it helps but one strategy for you could be to put something like a proxy that adds the particular http header of interest, or avoid the check for the http header entirely (if there is any particular context for why the header is needed let me know though)

@cmdcolin
Copy link
Contributor

cmdcolin commented Oct 5, 2023

I finally managed to make a demo that accomplishes this (adding a request header to file requests from jbrowse using a plugin). It requires installing the current github dev release with devtools::install_github('GMOD/JBrowseR') right now, but will make it CRAN release hopefully soon

Using JBrowse2 plugins with JBrowseR requires hosting them at an HTTP location right now (so e.g. I uploaded that plugin to a S3 bucket), and also needs to use the "JsonView" version

Example here

https://github.com/GMOD/JBrowseR/blob/main/example_apps/using_plugins/config.json
https://github.com/GMOD/JBrowseR/blob/main/example_apps/using_plugins/app.R

The plugin code is here

I made this plugin https://s3.amazonaws.com/jbrowse.org/demos/jbrowse-plugin-modifyhttpheaders.umd.development.js

You can see the adds the header "ExtraHTTPHeader: Wow" to your requests

Thanks for your patience and let me know if there are any questions, I know it's a pretty raw example but it should allow it to be extended for custom use cases

@cmdcolin
Copy link
Contributor

cmdcolin commented Oct 5, 2023

as far as for how you would use this: I would

a) download the plugin I linked above
b) change the header to what you are interested in
c) re-upload the plugin to a http URL
d) change the URL in the config.json for the plugin to your new http URL

@cmdcolin
Copy link
Contributor

cmdcolin commented Oct 5, 2023

and then

e) edit the config.json with your tracks and add the internetAccountId to them, which tells it to use the ModifyHTTPHeaders internet account plugin

@Imoteph
Copy link
Author

Imoteph commented Oct 6, 2023

Thanks a lot for your work, we will have a look into this and will leave a feedback! Thanks again!

@Imoteph
Copy link
Author

Imoteph commented Oct 20, 2023

As promised the feedback,

First of thanks for all the work you already put into this Request! We highly appreciate this.
We had a careful look into it and decided against this approach. The problem for us is that with the solution we need to safely store the jbrowse-plugin-modifyhttpheaders.umd.development.js away for each different jbrowse user/instance and again have the problem of how to deploy this safely.

Instead, we create now inside the shiny server a browse instance that is only alive/reactive/known in the session itself.

Again thanks for all the work and your effort here!!

@cmdcolin
Copy link
Contributor

gotcha no worries. I think it's great you can find a workable solution still and thanks for reporting the cram-js issue!

@cmdcolin
Copy link
Contributor

can maybe close this issue for now...will hopefully get this properly published to CRAN soon :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants