tus / tusd

Reference server implementation in Go of tus: the open protocol for resumable file uploads
https://tus.github.io/tusd
MIT License
2.92k stars 465 forks source link

Forward headers to grpc hook java #1112

Open TaridaGeorge opened 2 months ago

TaridaGeorge commented 2 months ago

I have an angular app which has an upload file feature. On the frontend side I'm using tus-js-client, the tusd server is v2.4.0 and the hook is grpc. From the frontend, I upload the file with the Authorization header but the tusd doesn't seem to pass them to the grpc server that I have written in Java. Is there an option that I should enable in order for the Authorization token to be passed to my java app?

Is there an option to enable more logging in tusd in order for me to see also the headers that are send from tus-js-client to it? In my java app, I can see that on the grpc hook I have no headers.

Setup details Please provide following details, if applicable to your situation:

const upload = new tus.Upload(file, {
  endpoint: "http://172.17.0.1:1080/files",
  retryDelays: [0, 3000, 5000],
  metadata: metadata,
  onError: (error) => {
      reject(error);
  },
  headers: {
      Authorization: `Bearer ${metadata['authToken']}`,
  },
  onShouldRetry: function (err: any, retryAttempt, options) {
      // omited
      return true;
  },
  onProgress: (bytesUploaded, bytesTotal) => {
      const percentage = (bytesUploaded / bytesTotal) * 100;
      progressCallback(percentage.toFixed(2));
  },
  onSuccess: () => {
      resolve(upload);
  },
});

upload.start();
Acconut commented 2 months ago

Headers from the incoming requests are not attached to HTTP/2 requests for gRPC. Such an option to forward HTTP headers is only available for HTTP hooks (see the flag).

However, the headers from the incoming requests are also provided in the payload provided via gRPC: https://github.com/tus/tusd/blob/15f05c021c9770dc0cd2818aa4ef44b9e361f5b2/pkg/hooks/grpc/proto/hook.proto#L98-L99

TaridaGeorge commented 2 months ago

Indeed. I've created a PR to handle those shortcomings. Please see https://github.com/tus/tusd/pull/1114

Only this line need to be modified:

https://github.com/tus/tusd/pull/1114/files#diff-02dbee1afbbc2d3019a64b4337548b6408b150fdafd5d9960145f692df7295b7R95