WrathChaos/StompClientLib

Issue with Cookies in header

cedb777 opened this issue · 5 comments

I tried to send a cookie to authenticate to the server but nothing has been sent.
When i read the log on server side, the header does not contain the cookie.
Here is my code what i do

    let cookieHeader = HTTPCookie.requestHeaderFields(with: self.cookies)
    socketClient.openSocketWithURLRequest(request: NSURLRequest(url: url as URL) , delegate: self, connectionHeaders:cookieHeader)

Is it possible to open socket with a cookie which is used to authenticate?
Thank you for your help!

I need to research about it. I will work on it :)

Thank you!

Hey @cedb777,
Really sorry but I had no time for the research, I'm gonna research about it in this weekend. Just to let you know

Hey,

I have a temporary solution.
I have modified SRWebSocket.m (SocketRocket library) and I force to send the cookies if needed.

  • In the didConnect function, I do it :
    `
    NSDictionary * cookies = [NSHTTPCookie requestHeaderFieldsWithCookies:[self requestCookies]];

    if ([cookies count] <= 0) {
    NSString * cookieKey = @"Cookie";
    NSString * cookieValue = [[self requestCookiesDict] objectForKey:cookieKey];

      if ([cookieKey length] && [cookieValue length]) {
          NSLog(@"OBJC - CFHTTPMessageSetHeaderFieldValue");
          CFHTTPMessageSetHeaderFieldValue(request, (__bridge CFStringRef)cookieKey, (__bridge CFStringRef)cookieValue);
      }
    

    }
    else {

      for (NSString * cookieKey in cookies) {
          if ([cookieKey length] && [cookieValue length]) {
              CFHTTPMessageSetHeaderFieldValue(request, (__bridge CFStringRef)cookieKey, (__bridge CFStringRef)cookieValue);
          }
      }
    

    }
    `

  • I added requestCookiesDict in the .h
    @Property (nonatomic, readwrite) NSDictionary<NSString *,NSString *> * requestCookiesDict;

  • Et dans StompClientLib.swift, je modifie la fonction "openSocket"
    socket!.requestCookiesDict = self.connectionHeaders socket!.delegate = self socket!.open()

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.