Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Cookies in header #71

Closed
cedb777 opened this issue Aug 30, 2019 · 5 comments
Closed

Issue with Cookies in header #71

cedb777 opened this issue Aug 30, 2019 · 5 comments
Assignees

Comments

@cedb777
Copy link

cedb777 commented Aug 30, 2019

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!

@WrathChaos WrathChaos self-assigned this Aug 31, 2019
@WrathChaos
Copy link
Owner

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

@cedb777
Copy link
Author

cedb777 commented Sep 2, 2019

Thank you!

@WrathChaos
Copy link
Owner

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

@cedb777
Copy link
Author

cedb777 commented Sep 4, 2019

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
Copy link

stale bot commented Nov 28, 2019

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.

@stale stale bot added the stale label Nov 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants