Skip to content

Commit

Permalink
feat: add content-type header to frame
Browse files Browse the repository at this point in the history
  • Loading branch information
dodo849 committed Jun 5, 2024
1 parent b80cb12 commit 4e2edf9
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion Sources/StompClient/StompRequestMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 4e2edf9

Please sign in to comment.