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

@uppy/companion-client: avoid unnecessary preflight requests #4462

Merged
merged 7 commits into from
Dec 5, 2023

Conversation

aduh95
Copy link
Contributor

@aduh95 aduh95 commented May 18, 2023

According to https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests, we have so many preflight requests because we add Uppy-Versions header and Content-Type: application/json to each request. It's particularly not useful for for requests with no body / an empty body because the remote Companion doesn't check Content-Type.

It was added in #1612, but render moot by #2967.

@arturi
Copy link
Contributor

arturi commented May 19, 2023

Very nice find! Could this lead to compatibility issues since Uppy-Versions was added to keep Companion compatible with old versions of Uppy Client? It was long ago, could be that it's fine to remove that compat check, but it exists in Companion AFAIK: if new Uppy version, then send certain allowed response, if Uppy-Version is missing, don't. Could be fine for empty requests, like you mentioned?

@aduh95
Copy link
Contributor Author

aduh95 commented May 22, 2023

Trying to look for Uppy-Versions or @uppy/companion-client= in the codebase doesn't return any result, are you sure it's still in used?

EDIT: found it:

clientVersion: req.header('uppy-versions') || versionFromQuery || '1.0.0',

@mifi
Copy link
Contributor

mifi commented Jun 4, 2023

Not sure what it's even being used for though.

it seems to be stored in oauth state here:

state = oAuthState.addToState(state, { clientVersion: req.companion.clientVersion }, secret)

and logged here:

logger.info(`uppy client version ${req.companion.clientVersion}`, 'companion.client.version')

but other than that I cannot find it being used anywhere. maybe it can be removed?

Copy link
Contributor

@mifi mifi left a comment

Choose a reason for hiding this comment

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

nice

packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
@mifi
Copy link
Contributor

mifi commented Nov 2, 2023

so i guess it boils down to:

  1. are we willing to take the risk and remove uppy-versions for requests without a body (possibly breaking old companion versions)?
  2. if so, should we just remove uppy-versions for all requests for consistency?

@mifi
Copy link
Contributor

mifi commented Dec 4, 2023

was added here d77180a - it seesm to not be needed anymore, so we can remove it. let's also remove all the other code from that commit

@mifi
Copy link
Contributor

mifi commented Dec 5, 2023

i'll take over this then

from d77180a
including removing the `logClientVersion` option
and custom preflight logic
@mifi
Copy link
Contributor

mifi commented Dec 5, 2023

Now that I think more about it and look at some old threads #2855 #2610 (comment) - maybe it's a breaking change after all? if some people depend on the uppy client version being logged with the logClientVersion option?

@Murderlon
Copy link
Member

But the presence/absence of a log is not breaking right? The option would just be silently ignored. I think that's fine.

@mifi
Copy link
Contributor

mifi commented Dec 5, 2023

maybe not 😇

packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion-client/src/RequestClient.js Outdated Show resolved Hide resolved
packages/@uppy/companion/src/config/companion.js Outdated Show resolved Hide resolved
packages/@uppy/companion/src/server/controllers/connect.js Outdated Show resolved Hide resolved
@mifi
Copy link
Contributor

mifi commented Dec 5, 2023

how do you run eslint --fix in github @aduh95 ?

Co-authored-by: Mikael Finstad <[email protected]>
@aduh95
Copy link
Contributor Author

aduh95 commented Dec 5, 2023

how do you run eslint --fix in github @aduh95 ?

I don't think that's a thing.

package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
@aduh95 aduh95 merged commit f55b24c into transloadit:main Dec 5, 2023
19 checks passed
@aduh95 aduh95 deleted the fewer-preflight branch December 5, 2023 11:30
@mifi
Copy link
Contributor

mifi commented Dec 5, 2023

Oh i just assumed you didnt do all those by hand 😅

Murderlon added a commit that referenced this pull request Dec 5, 2023
…-core

* 'ts-core' of https://github.com/transloadit/uppy:
  prettier
  Apply suggestion from code reviews
  fix lint
  Fix unit tests
  meta: fix `js2ts` script on Node.js 20+ (#4802)
  @uppy/companion-client: avoid unnecessary preflight requests (#4462)
github-actions bot added a commit that referenced this pull request Dec 12, 2023
| Package                | Version | Package                | Version |
| ---------------------- | ------- | ---------------------- | ------- |
| @uppy/aws-s3           |   3.6.0 | @uppy/instagram        |   3.2.0 |
| @uppy/aws-s3-multipart |  3.10.0 | @uppy/onedrive         |   3.2.0 |
| @uppy/box              |   2.2.0 | @uppy/provider-views   |   3.8.0 |
| @uppy/companion        |  4.12.0 | @uppy/store-default    |   3.2.0 |
| @uppy/companion-client |   3.7.0 | @uppy/tus              |   3.5.0 |
| @uppy/core             |   3.8.0 | @uppy/url              |   3.5.0 |
| @uppy/dropbox          |   3.2.0 | @uppy/utils            |   5.7.0 |
| @uppy/facebook         |   3.2.0 | @uppy/xhr-upload       |   3.6.0 |
| @uppy/google-drive     |   3.4.0 | @uppy/zoom             |   2.2.0 |
| @uppy/image-editor     |   2.4.0 | uppy                   |  3.21.0 |

- @uppy/provider-views: fix uploadRemoteFile undefined (Mikael Finstad / #4814)
- @uppy/companion: fix double tus uploads (Mikael Finstad / #4816)
- @uppy/companion: fix accelerated endpoints for presigned POST  (Mikael Finstad / #4817)
- @uppy/companion: fix `authProvider` property inconsistency (Mikael Finstad / #4672)
- @uppy/companion:  send certain onedrive errors to the user (Mikael Finstad / #4671)
- meta: fix typo in `lockfile_check.yml` name (Antoine du Hamel)
- @uppy/aws-s3: change Companion URL in tests (Antoine du Hamel)
- @uppy/set-state: fix types (Antoine du Hamel)
- @uppy/companion: Provider user sessions (Mikael Finstad / #4619)
- meta: fix `js2ts` script on Node.js 20+ (Merlijn Vos / #4802)
- @uppy/companion-client: avoid unnecessary preflight requests (Antoine du Hamel / #4462)
- meta: Migrate to AWS-SDK V3 syntax (Artur Paikin / #4810)
- @uppy/utils: fix import in test files (Antoine du Hamel / #4806)
- @uppy/core: Fix onBeforeFileAdded with Golden Retriever (Merlijn Vos / #4799)
- @uppy/image-editor: respect `cropperOptions.initialAspectRatio` (Lucklj521 / #4805)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants