Created
May 6, 2024 17:59
-
-
Save sedkis/09894e153835068eb0a4bc62f931c7a1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TerminateRequest checks for a specific query parameter and terminates the request if present. | |
func TerminateRequest(rw http.ResponseWriter, r *http.Request) { | |
// Check for the query parameter | |
if value := r.URL.Query().Get("terminate"); value == "true" { | |
// Prepare the data to send in response | |
responseData := map[string]string{ | |
"message": "Request terminated by custom Tyk plugin.", | |
} | |
jsonData, err := json.Marshal(responseData) | |
if err != nil { | |
rw.WriteHeader(http.StatusInternalServerError) | |
return | |
} | |
// Set the content type and write the JSON response | |
rw.Header().Set("Content-Type", "application/json") | |
rw.WriteHeader(http.StatusOK) | |
rw.Write(jsonData) | |
// Terminate the request processing | |
return | |
} | |
// If the parameter is not present, do nothing and let the request continue | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment