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

Adjust file handling to handle loading from bundles #131

Merged
merged 4 commits into from
Jul 11, 2022
Merged

Adjust file handling to handle loading from bundles #131

merged 4 commits into from
Jul 11, 2022

Conversation

drekka
Copy link
Contributor

@drekka drekka commented Jul 7, 2022

I was trying to load files from a bundle of files passed to a test suite. In my server setup I had this middleware:

let configuration = HBApplication.Configuration()
let server = HBApplication(configuration: configuration)
server.middleware.add(HBFileMiddleware(Bundle.testData.filePath.absoluteString, application: server))
try server.start()

However whenever I requested a file from the testData bundle HBFileMiddleware failed to find it.

I debugged through and found that the string based root folder was being set to a file:///... path which was not understood by the file code attempting to load the file.

This PR:

  • Converts rootFolder to be a file URL instead of a string.
  • Updates usage of rootFolder based on it now being a URL. ie. rootFolder.relativePath.
  • Removes checking for a trailing / which is no longer needed.

Testing

After the code change all Hummingbird test ran green without change.

Signed-off-by: Derek Clarkson <d4rkf1br3@gmail.com>
Signed-off-by: Derek Clarkson <d4rkf1br3@gmail.com>
Signed-off-by: Derek Clarkson <d4rkf1br3@gmail.com>
@codecov
Copy link

codecov bot commented Jul 10, 2022

Codecov Report

Merging #131 (e6a04b5) into main (9eff305) will increase coverage by 0.02%.
The diff coverage is 83.33%.

@@            Coverage Diff             @@
##             main     #131      +/-   ##
==========================================
+ Coverage   78.36%   78.38%   +0.02%     
==========================================
  Files          71       71              
  Lines        3046     3040       -6     
==========================================
- Hits         2387     2383       -4     
+ Misses        659      657       -2     
Impacted Files Coverage Δ
...s/HummingbirdFoundation/Files/FileMiddleware.swift 87.41% <81.81%> (+0.83%) ⬆️
Sources/HummingbirdFoundation/Cookies/Cookie.swift 75.75% <100.00%> (ø)

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 9eff305...e6a04b5. Read the comment docs.

Copy link
Member

@adam-fowler adam-fowler left a comment

Choose a reason for hiding this comment

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

You need Nick Lockwood's swiftformat installed. And then you should run ./script/validate.sh
Otherwise this is good

Signed-off-by: Derek Clarkson <d4rkf1br3@gmail.com>
@drekka
Copy link
Contributor Author

drekka commented Jul 10, 2022

Yep. I think my settings for SwiftFormat might be slightly different to yours as when I originally ran it here it changed a bunch of lines. Anyway, :-) Ran scripts/validate.sh which changed 3 files and committed the results.

@adam-fowler adam-fowler merged commit 896ff39 into hummingbird-project:main Jul 11, 2022
@adam-fowler
Copy link
Member

This is released in v0.16.1

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.

None yet

2 participants