Skip to content

Commit 3b2fea7

Browse files
author
FreakyCoder
authored
Merge pull request #56 from Erhannis/master
String body parameter and ':'-in-header-value fix
2 parents d0c63ea + b1ba029 commit 3b2fea7

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

Example/StompClientLib.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public enum StompAckMode {
5858

5959
// Fundamental Protocols
6060
public protocol StompClientLibDelegate {
61-
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header:[String:String]?, withDestination destination: String)
61+
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header:[String:String]?, withDestination destination: String)
6262

6363
func stompClientDidDisconnect(client: StompClientLib!)
6464
func stompClientDidConnect(client: StompClientLib!)
@@ -298,7 +298,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
298298
// Response
299299
if let delegate = delegate {
300300
DispatchQueue.main.async(execute: {
301-
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
301+
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), akaStringBody: body, withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
302302
})
303303
}
304304
} else if command == StompCommands.responseFrameReceipt { //

Example/StompClientLib/ViewController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ class ViewController: UIViewController, StompClientLibDelegate {
4949
print("Socket is Disconnected")
5050
}
5151

52-
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) {
52+
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
5353
print("DESTIONATION : \(destination)")
5454
print("JSON BODY : \(String(describing: jsonBody))")
55+
print("STRING BODY : \(stringBody ?? "nil")")
5556
}
5657

5758
func stompClientJSONBody(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: String?, withHeader header: [String : String]?, withDestination destination: String) {

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ print("Socket is Disconnected")
114114

115115
Your json message will be converted to JSON Body as AnyObject and you will receive your message in this function
116116
```ruby
117-
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header: [String : String]?, withDestination destination: String) {
117+
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
118118
print("Destination : \(destination)")
119119
print("JSON Body : \(String(describing: jsonBody))")
120+
print("String Body : \(stringBody ?? "nil")")
120121
}
121122
```
122123

StompClientLib/Classes/StompClientLib.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public enum StompAckMode {
5858

5959
// Fundamental Protocols
6060
public protocol StompClientLibDelegate {
61-
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, withHeader header:[String:String]?, withDestination destination: String)
61+
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header:[String:String]?, withDestination destination: String)
6262

6363
func stompClientDidDisconnect(client: StompClientLib!)
6464
func stompClientDidConnect(client: StompClientLib!)
@@ -163,7 +163,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
163163
} else {
164164
let parts = line.components(separatedBy: ":")
165165
if let key = parts.first {
166-
headers[key] = parts.last
166+
headers[key] = parts.dropFirst().joined(separator: ":")
167167
}
168168
}
169169
}
@@ -296,7 +296,7 @@ public class StompClientLib: NSObject, SRWebSocketDelegate {
296296
// Response
297297
if let delegate = delegate {
298298
DispatchQueue.main.async(execute: {
299-
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
299+
delegate.stompClient(client: self, didReceiveMessageWithJSONBody: self.dictForJSONString(jsonStr: body), akaStringBody: body, withHeader: headers, withDestination: self.destinationFromHeader(header: headers))
300300
})
301301
}
302302
} else if command == StompCommands.responseFrameReceipt { //

0 commit comments

Comments
 (0)