split the raw header coming from C with minimal allocations
(rawHeader *C.char, length int)
| 520 | |
| 521 | // split the raw header coming from C with minimal allocations |
| 522 | func splitRawHeader(rawHeader *C.char, length int) (string, string) { |
| 523 | buf := unsafe.Slice((*byte)(unsafe.Pointer(rawHeader)), length) |
| 524 | |
| 525 | // Search for the colon in 'Header-Key: value' |
| 526 | var i int |
| 527 | for i = 0; i < length; i++ { |
| 528 | if buf[i] == ':' { |
| 529 | break |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | if i == length { |
| 534 | return "", "" // No colon found, invalid header |
| 535 | } |
| 536 | |
| 537 | headerKey := C.GoStringN(rawHeader, C.int(i)) |
| 538 | |
| 539 | // skip whitespaces after the colon |
| 540 | j := i + 1 |
| 541 | for j < length && buf[j] == ' ' { |
| 542 | j++ |
| 543 | } |
| 544 | |
| 545 | // anything left is the header value |
| 546 | valuePtr := (*C.char)(unsafe.Pointer(uintptr(unsafe.Pointer(rawHeader)) + uintptr(j))) |
| 547 | headerValue := C.GoStringN(valuePtr, C.int(length-j)) |
| 548 | |
| 549 | return headerKey, headerValue |
| 550 | } |
| 551 | |
| 552 | //export go_write_headers |
| 553 | func go_write_headers(threadIndex C.uintptr_t, status C.int, headers *C.zend_llist) C.bool { |