Skip to content

Commit 33184e2

Browse files
committed
Refactor getContentTypeHeader function to handle packages endpoint and improve logging
1 parent 72f820b commit 33184e2

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

jamf/jamfprointegration/headers.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@ import (
66
"go.uber.org/zap"
77
)
88

9-
// GetContentTypeHeader determines the appropriate Content-Type header for a given API endpoint.
10-
// It attempts to find a content type that matches the endpoint prefix in the global configMap.
11-
// If a match is found and the content type is defined (not nil), it returns the specified content type.
12-
// If the content type is nil or no match is found in configMap, it falls back to default behaviors:
13-
// - For url endpoints starting with "/JSSResource", it defaults to "application/xml" for the Classic API.
14-
// - For url endpoints starting with "/api", it defaults to "application/json" for the JamfPro API.
9+
// getContentTypeHeader determines the appropriate Content-Type header for a given API endpoint.
10+
// It sets the Content-Type to "application/octet-stream" specifically for the endpoint "/api/v1/packages/{id}/upload".
11+
// For other endpoints, it attempts to match the Content-Type based on the endpoint pattern:
12+
// - For URL endpoints starting with "/JSSResource", it defaults to "application/xml" for the Classic API.
13+
// - For URL endpoints starting with "/api", it defaults to "application/json" for the JamfPro API.
1514
// If the endpoint does not match any of the predefined patterns, "application/json" is used as a fallback.
1615
// This method logs the decision process at various stages for debugging purposes.
1716
func (j *Integration) getContentTypeHeader(endpoint string) string {
18-
if strings.Contains(endpoint, "/api/v1/packages") {
19-
j.Logger.Debug("Content-Type for packages endpoint set to application/octet-stream", zap.String("endpoint", endpoint))
17+
if strings.HasPrefix(endpoint, "/api/v1/packages/") && strings.HasSuffix(endpoint, "/upload") {
18+
j.Logger.Debug("Content-Type for packages upload endpoint set to application/octet-stream", zap.String("endpoint", endpoint))
2019
return "application/octet-stream"
2120
}
2221

0 commit comments

Comments
 (0)