Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Optionally disable debug aborts conditions #217

Closed
matt-curtis opened this issue Sep 21, 2015 · 11 comments
Closed

Optionally disable debug aborts conditions #217

matt-curtis opened this issue Sep 21, 2015 · 11 comments
Labels

Comments

@matt-curtis
Copy link

There are times when GCDWebServer will halt and abort on non-breaking errors. Being able to toggle a flag somewhere would be ideal, rather than just going off of the DEBUG flag.

@swisspol
Copy link
Owner

Abort should only be called on programmer errors. What specific case are you hitting?

@matt-curtis
Copy link
Author

For example - whenever I stop the server, GWS_DNOT_REACHED is hit because (?) _options is not defined. (line 712 in GCDWebServer.m)

@swisspol
Copy link
Owner

That's because you are not retaining the server most likely or calling stop more than once.

@matt-curtis
Copy link
Author

Ah, you're right; I can't believe I missed that.

Do you have any suggestions as to why I experience very long upload times with multipart form data (files)?

@swisspol
Copy link
Owner

Check the Xcode log, GCDWebServer logs a lot if DEBUG is defined. Apart from that, I'd say check your WiFi network 😄

@matt-curtis
Copy link
Author

Examining the logs, I get lots of [DEBUG] Connection received .... bytes on socket 21. Transfer seems slow, and prone to hangs in between chunks. In total it took about a minute and a half, give or take. This was on a single 4 MB file. I don't think my wifi is the issue, as far as I can tell, as other requests to/from GCDWebServer are lighting-fast.

@matt-curtis
Copy link
Author

Could how I make the multipart-data request be an issue? I'm using XMLHttpRequest+form data to make the POST request.

@swisspol
Copy link
Owner

I can't really help with that, sorry, there are too many things that go wrong outside of GCDWebServer.

I'd recommend using the Chrome web inspector to understand what's happening to the requests. Good luck!

@matt-curtis
Copy link
Author

just so you know, I'm experiencing this with bare-bones <forms /> & <input type="file" /> as well.

@matt-curtis
Copy link
Author

What does it mean if I receive aborts in performOpen? Only happens when i send several POST requests one after another.

edit: pending, seems like I fixed it
edit: I take that back, still happens. I think it might have something to do with my synchronous handlers...
edit: I take that back too, still happens.

@matt-curtis
Copy link
Author

If you could provide any pointers I'd appreciate it. Here's the code I'm using to create the server and process multipart POST requests. It aborts in performOpen: if there is an existing pending request, I'm assuming because something isn't getting closed. I'm just not able to identify the fault in my code that is causing this. Thanks.

__weak typeof(self) ws = self;

_webServer = [GCDWebServer new];

[_webServer
    addDefaultHandlerForMethod:@"GET" requestClass:[GCDWebServerRequest class]
    processBlock:^GCDWebServerResponse* (GCDWebServerRequest *request){
        if(![ws shouldRespondToRequest:request]) return ws.notFoundResponse;

        GCDWebServerResponse *response = [ws responseForHTTPGetRequest:request];

        response.gzipContentEncodingEnabled = true; // compress all responses

        [response setValue:@"*" forAdditionalHeader:@"Access-Control-Allow-Origin"];

        return response;
    }];

[_webServer
    addDefaultHandlerForMethod:@"POST" requestClass:[GCDWebServerMultiPartFormRequest class]
    processBlock:^GCDWebServerResponse* (GCDWebServerRequest *request){
        if(![ws shouldRespondToRequest:request]) return ws.notFoundResponse;

        GCDWebServerResponse *response = [ws responseForHTTPPostRequest:request];

        response.gzipContentEncodingEnabled = true; // compress all responses

        [response setValue:@"*" forAdditionalHeader:@"Access-Control-Allow-Origin"];

        return response;
    }];

[_webServer startWithPort:kWebServerPort bonjourName:nil];

//  responseForHTTPPostRequest:

NSString *identifier = [request firstArgumentForControlName:kAPIKey_Ids].string;

NSLog(@"%@", identifier);

return _emptyJSONResonse;

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants