From 4e2edf9df63c0fcbf1eab8f000d7248754522524 Mon Sep 17 00:00:00 2001 From: leedoyeon849 Date: Thu, 6 Jun 2024 02:31:10 +0900 Subject: [PATCH] feat: add content-type header to frame --- Sources/StompClient/StompRequestMessage.swift | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/Sources/StompClient/StompRequestMessage.swift b/Sources/StompClient/StompRequestMessage.swift index a10d339..b00ee32 100644 --- a/Sources/StompClient/StompRequestMessage.swift +++ b/Sources/StompClient/StompRequestMessage.swift @@ -25,6 +25,17 @@ public enum StompBody { case data(Data) case string(String) case json(Encodable) + + var contentType: String { + switch(self) { + case .data: + return "application/octet-stream" + case .string: + return "text/plain" + case .json: + return "application/json" + } + } } protocol StompRequestMessage { @@ -38,9 +49,17 @@ protocol StompRequestMessage { extension StompRequestMessage { public func toFrame() -> String { var frame = "\(command.rawValue)\n" - for (key, value) in headers { + + var updatedHeaders = headers + + if let body = body { + updatedHeaders["content-type"] = body.contentType + } + + for (key, value) in updatedHeaders { frame += "\(key):\(value)\n" } + frame += "\n" if let body = body {