Skip to content

Commit

Permalink
fix: prevent override of client request listeners in CodeWhispererSer…
Browse files Browse the repository at this point in the history
…viceIAM
  • Loading branch information
Francesco Piccoli committed Feb 14, 2025
1 parent 04240dc commit aad4188
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
} from '@aws/language-server-runtimes/server-interface'
import { AWSError, ConfigurationOptions, CredentialProviderChain, Credentials } from 'aws-sdk'
import { PromiseResult } from 'aws-sdk/lib/request'
import { Request } from 'aws-sdk/lib/core'
import { v4 as uuidv4 } from 'uuid'
import {
CodeWhispererSigv4ClientConfigurationOptions,
Expand Down Expand Up @@ -90,8 +91,13 @@ export class CodeWhispererServiceIAM extends CodeWhispererServiceBase {
]),
}
this.client = createCodeWhispererSigv4Client(options, sdkInitializator)
this.client.setupRequestListeners = ({ httpRequest }) => {
httpRequest.headers['x-amzn-codewhisperer-optout'] = `${!this.shareCodeWhispererContentWithAWS}`
// Avoid overwriting any existing client listeners
const clientRequestListeners = this.client.setupRequestListeners
this.client.setupRequestListeners = (request: Request<unknown, AWSError>) => {
if (clientRequestListeners) {
clientRequestListeners.call(this.client, request)
}
request.httpRequest.headers['x-amzn-codewhisperer-optout'] = `${!this.shareCodeWhispererContentWithAWS}`
}
}

Expand Down

0 comments on commit aad4188

Please sign in to comment.