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

Can we allow null as well as "" for contentType args #117

Closed
csells opened this issue Apr 17, 2016 · 18 comments
Closed

Can we allow null as well as "" for contentType args #117

csells opened this issue Apr 17, 2016 · 18 comments
Assignees

Comments

@csells
Copy link
Contributor

csells commented Apr 17, 2016

UploadObject fails if there's a null contentType but succeeds if the contentType is "". Can we allow null and translate to "" for the user?

@jskeet
Copy link
Collaborator

jskeet commented Apr 17, 2016

We can if we think that's an appropriate default. We could look at making it an optional parameter in that case... I've never been sure whether "" is a good content type to specify...

@csells
Copy link
Contributor Author

csells commented Apr 17, 2016

I don't think there is a good default for content type. However, in this case "" means "no content specified", so null should be allowed for that as well.

@jskeet jskeet self-assigned this Apr 20, 2016
@jskeet
Copy link
Collaborator

jskeet commented Apr 27, 2016

I've been thinking about this a bit - I'm still somewhat uncomfortable about it, particularly as it would end up being returned as "" (I'd hope, anyway).

Given that this is a required parameter, and it's just as easy to write "" as null, I'm not sure why we'd want to conflate them. Basically, we want users to think about the right content type, and this feels like it's moving in the wrong direction.

Happy to be convinced though :)

@Capstan
Copy link

Capstan commented Apr 27, 2016

I made contentType an optional parameter for Google Cloud Storage in Q1. If you are still seeing otherwise, it's a service bug you should report.

@jskeet
Copy link
Collaborator

jskeet commented Apr 27, 2016

Aha. In that case we should make it optional as well, definitely. Thanks Capstan!

@jskeet
Copy link
Collaborator

jskeet commented Apr 27, 2016

@csells: Let's work out what we want the shape of this to look like. A few options:

  1. Leave the parameter where it is, and just allow it to be null. (User still has to specify it - it's required from a C# perspective.)
  2. Remove the parameter, putting it into UploadObjectOptions - one downside is that it's not relevant when uploading an existing object.
  3. Switch the source and contentType parameters, and make it default to null.

Any particular preference?

@csells
Copy link
Contributor Author

csells commented Apr 27, 2016

Option 1 is my preference.

@jskeet
Copy link
Collaborator

jskeet commented Apr 27, 2016

Well that's handy, as it should be a trivial change. Will send you a PR shortly...

jskeet added a commit to jskeet/google-cloud-dotnet that referenced this issue Apr 27, 2016
@jskeet jskeet closed this as completed May 4, 2016
@jskeet
Copy link
Collaborator

jskeet commented May 4, 2016

(Note that this PR doesn't translate null to "" as the content type as per the original comment - it just doesn't set it, which sounds like it should be fine.)

@jskeet jskeet reopened this May 10, 2016
@jskeet
Copy link
Collaborator

jskeet commented May 10, 2016

Reopening this as it looks like there's other code that does require a content type.

@Capstan
Copy link

Capstan commented May 10, 2016

Pointers?

@jskeet
Copy link
Collaborator

jskeet commented May 10, 2016

@Capstan: I need to look into it tomorrow.

@jskeet
Copy link
Collaborator

jskeet commented May 11, 2016

Okay, found it. It's in the shared resumable upload code, which is what we use for all uploads in the wrapper API. As per https://cloud.google.com/storage/docs/json_api/v1/how-tos/resumable-upload, the X-Upload-Content-Type is required - so it's validated in ResumableUpload.cs.

The simplest fix here will be to just coalesce null to "", as per @csells original comment. Will send that out as a separate PR.

jskeet added a commit to jskeet/google-cloud-dotnet that referenced this issue May 11, 2016
We need to manually coalesce this, as the resumable upload code requires a
content type to be specified, but allows it to be empty.

This also removes an overload of UploadObjectAsync which was unnecessary -
no doubt overlooked when we introduced optional parameters.

Fixes issue googleapis#117.
@jskeet jskeet closed this as completed May 11, 2016
@Capstan
Copy link

Capstan commented May 11, 2016

Aha. That doc is incorrect and was missed when we relaxed that requirement.

@jskeet
Copy link
Collaborator

jskeet commented May 11, 2016

Ah, so it's reasonable to not specify the X-Upload-Content-Type header in general for resumable upload? If that's the case, I'll file a bug against the other github repo :)

@Capstan
Copy link

Capstan commented May 11, 2016

I would not go that far. There exist other uploader service customers besides GCS who may still require it. But it should not be required for all services, no.

@jskeet
Copy link
Collaborator

jskeet commented May 11, 2016

Okay - in that case, we shouldn't prohibit it in the uploader; if it is required and a client doesn't specify it, the server can fail the request - we shouldn't do so too conservatively. Have filed googleapis/google-api-dotnet-client#743

When that's fixed, we can revert some of the previous PR...

@jskeet jskeet reopened this May 11, 2016
@jskeet
Copy link
Collaborator

jskeet commented May 20, 2016

Finally fixed by #176.

@jskeet jskeet closed this as completed May 20, 2016
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Apr 6, 2020
@jskeet jskeet removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Feb 1, 2021
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

4 participants