Skip to content

Conversation

optistar
Copy link

@optistar optistar commented Jul 28, 2025

Adds context.Context to HTTP requests for cancellation/timeouts, as requested in #108.

  • Introduces ...Context variants for each API method, taking ctx as first arg.
  • Original methods preserved for compatibility, delegating to ...Context with context.Background().
  • If ...WithContext is preferred, adjust name_suffix="Context" and 'Context(' in the generator.
  • Avoids breaking changes (e.g., no ctx in arg structs).
  • The signature of dropbox.context.Execute is changed to take ctx, based on the assumption that this method is internal.
  • In Execute, the call to http.NewRequest is replaced with http.NewRequestWithContext.
  • No doc comments is set on ...Context methods; something like // UploadContext is the context-aware version of Upload. could be added.

Generated code is not updated by this commit. Example of impact:

Before:

func (dbx *apiImpl) Upload(arg *UploadArg, content io.Reader) (res *FileMetadata, err error) {
  // implementation
}

After:

func (dbx *apiImpl) Upload(arg *UploadArg, content io.Reader) (res *FileMetadata, err error) {
    return dbx.UploadContext(context.Background(), arg, content)
}

func (dbx *apiImpl) UploadContext(ctx context.Context, arg *UploadArg, content io.Reader) (res *FileMetadata, err error) {
    // implementation with ctx in Execute
}

Closes #108.

@CLAassistant
Copy link

CLAassistant commented Jul 28, 2025

CLA assistant check
All committers have signed the CLA.

@optistar optistar force-pushed the context branch 2 times, most recently from 6621f98 to 246c597 Compare July 28, 2025 21:20
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.

Add context to dropbox http requests
2 participants