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

Generic filehandle remoteFile refactor #42

Closed
wants to merge 4 commits into from

Conversation

garrettjstevens
Copy link
Collaborator

These are a couple proposed changes to help me get cors-busting working in jb-desktop. Basically they are:

  • Add stat method to the GenericFilehandle interface
  • Refactor RemoteFile so all the fetching happens in a getFetch method
  • Try to parse the content-length header for file size if it's not a range request
  • Some various TypeScript tweaks

Basically I'm extending RemoteFile in jb-desktop so that the getFetch method can fall back to using node-fetch if fetch fails (which may be due to cors).

@codecov
Copy link

codecov bot commented Oct 13, 2019

Codecov Report

Merging #42 into master will increase coverage by 0.64%.
The diff coverage is 92.59%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #42      +/-   ##
==========================================
+ Coverage   89.28%   89.93%   +0.64%     
==========================================
  Files           4        4              
  Lines         140      149       +9     
  Branches       49       54       +5     
==========================================
+ Hits          125      134       +9     
  Misses         15       15
Impacted Files Coverage Δ
src/blobFile.ts 78.72% <ø> (ø) ⬆️
src/localFile.ts 90.47% <0%> (ø) ⬆️
src/remoteFile.ts 95.89% <100%> (+0.57%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 04ea4ab...eaa3749. Read the comment docs.

Copy link
Contributor

@rbuels rbuels left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these look great to me, would like to see what @cmdcolin thinks before merging though

@cmdcolin
Copy link
Collaborator

cmdcolin commented Oct 14, 2019

This is pretty good code wise but I am not a big fan of our library code depending on stat. I know it already exists in some libraries but it complicates any CORS setup by requiring additional headers and such, and it would now require allowing HEAD request CORS setup too. We can just say "whatever screw CORS we'll proxy it/use node fetch" but not hugely into this either.
It's true that web servers can legally return a 416 for beyond the file size requests https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416 but my experience is that this does not happen from most webservers, it just returns a shorter response. Is there something that renewed focus on stat?

@garrettjstevens garrettjstevens self-assigned this Oct 15, 2019
@garrettjstevens garrettjstevens changed the title Generic filehandle stats Generic filehandle remoteFile refactor Oct 15, 2019
@garrettjstevens
Copy link
Collaborator Author

Weird, I wasn't getting notifications for this PR. So I added some additional stuff to stat because I needed it in the first approach I took at cors-busting, but I ended up doing something else. The stat additions are still in here, but I don't actually depend on them in my jb-desktop code. I changed the name of the PR to better reflect what's actually important.

@rbuels
Copy link
Contributor

rbuels commented Oct 15, 2019

Looks to me like this adds a pretty darn robust stat implementation, but doesn’t add any overhead to code that doesn’t want to use it. Is that what you guys are getting from this?

@garrettjstevens
Copy link
Collaborator Author

@cmdcolin any other concerns or questions with merging this? I want to make sure I actually addressed what you were asking about.

@cmdcolin
Copy link
Collaborator

I had concerns including
-why is this change to use head request bring introduced
I'm also concerned about the usage of get fetch function being in this library... It seems like the wrong abstraction

@garrettjstevens
Copy link
Collaborator Author

The HEAD request is basically a way to increase the robustness of the stat method. It tries to use the HEAD request's "content-length" to determine the file size, and if that doesn't work it falls back to using a range request and "content-range". It's only used in the stat method, and then only if the file size hasn't already been determined.

As for the getFetch method, it's just refactoring the fetching logic that was already there into a single method. I thought it would be good for a class extending RemoteFile to be able to customize the fetching logic (it worked out well for what I wanted to do). RemoteFile already allows a custom fetch to be provided, so this method made sense to be able to add the ability to do special things with that custom fetch. That being said, I probably need to make it a protected method instead of a public one.

What about the abstraction do you have concerns with?

@garrettjstevens
Copy link
Collaborator Author

Closing in favor of #43.

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

Successfully merging this pull request may close these issues.

3 participants