I finally got the time to come back to this.
1) I'm very grateful Sergio for your httpd, but I want digest authentication your server only implements basic.
2) I'm sorry for the misunderstanding with my pcap.
I was looking at different solution and sent the pcap from that.
3) I sort of found my problem.
Attached new pcap.
In frame 4 of the pcap you can see that my server is sending the tcp packet flagged as FIN.
However if I try to call tcp_close() from the client tcp_recv callback it sends a reset because the receive window isn't empty.
The server sends 143 bytes of data, but the client receive window (pcb->rcv_wnd) is being subtracted 144.
I looked in the code at tcp_in.c and found that
1220: tcplen = TCP_TCPLEN(&inseg) = 144
The pbuf->len = 143.
By my understanding of the TCP_TCPLEN macro this should be the case.
Any idea where I'm missing the point?