zvjerka24
zvjerka24

Reputation: 1792

Reverse proxy inside OSX application

Is there any reverse proxy that can be embedded within OSX application written in Objective-C? I need to develop application which is going to have reverse proxy embedded inside but not to use an external proxy server instance. Did someone used Nginx that way?

Upvotes: 0

Views: 487

Answers (2)

zvjerka24
zvjerka24

Reputation: 1792

It seems that there is no reverse proxy written in Objective-C :) Solution I used is:

  • Download nginx source code
  • Configure using

    ./configure --sbin-path=/usr/local/nginx
       --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-pcre=/usr/local/nginx/src/$PCRE_FILE/ --group=www --user=www --with-http_stub_status_module --with-http_gzip_static_module --prefix=/usr/local/nginx
   
  • copy binary into boundle
  • run binary using

    NSTask *task = [[NSTask alloc] init];
    NSPipe * out = [NSPipe pipe];
    [task setStandardOutput:out];

    [task setLaunchPath:[NSString stringWithFormat:@"%@/Library/run/nginx", appPath]];
    [task setArguments:@[@"-c", [NSString stringWithFormat:@"%@/Library/conf/nginx/nginx.conf", appPath], @"-p", [NSString stringWithFormat:@"%@/Library/nginx", appPath]]];

    [task launch];
    [task waitUntilExit];
    read = [out fileHandleForReading];
    dataRead = [read readDataToEndOfFile];
    stringRead = [[NSString alloc] initWithData:dataRead encoding:NSUTF8StringEncoding];

    NSLog(@"output: %@", stringRead);
    

Upvotes: 1

user3088135
user3088135

Reputation: 21

It's technically possible. I think your idea of using Nginx would work. Why did you call out Objective-C specifically? I don't see why you wouldn't use one written in plain C (there should be no problem with that). You might consider using a separate process space for the proxy, otherwise your app and the proxy might interfere with each other in ways you don't expect. (like calling exit(), handling signals, crashing, etc) Then you don't have to figure out how to recompile the proxy inside Xcode, etc - you just have a binary for it and you configure and run it.

The question is, why would you do it? Reverse proxies only make sense when you have a backing server farm to connect to. Do you just need an embedded web server to serve up pages to your application? Why not just use one directly? A reverse proxy would just complicate things.

Upvotes: 2

Related Questions