#Question regarding strsep

4 messages · Page 1 of 1 (latest)

sudden quail
#

I have a HTTP string:

Content-Type: text/plain
User-Agent: PostmanRuntime/7.31.3
Accept: */*
Postman-Token: 640d0ede-6dd7-4db3-8aba-8d28d933dda7
Host: 127.0.0.1:8000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 4

poop```

Where I try and get 3 pointers, one for the status line, one for the headers, and one for the body.

```c
    char *status_line, *headers, *body;

    status_line = strsep(&request, "\r\n");
    headers = strsep(&request, "\r\n\r\n");
    body = request;

But this returns:

Status line: GET / HTTP/1.1
Headers:
Body: Content-Type: text/plain
User-Agent: PostmanRuntime/7.31.3
Accept: */*
Postman-Token: 640d0ede-6dd7-4db3-8aba-8d28d933dda7
Host: 127.0.0.1:8000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 4

poop

Why is 'headers' empty?

placid pewterBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

ember depot
#

because strsep stops if any of "\r\n" is found

#

it does not find the string in the second argument, it just finds any of the characters in it