MCPcopy Index your code
hub / github.com/php/frankenphp / splitRawHeader

Function splitRawHeader

frankenphp.go:522–550  ·  view source on GitHub ↗

split the raw header coming from C with minimal allocations

(rawHeader *C.char, length int)

Source from the content-addressed store, hash-verified

520
521// split the raw header coming from C with minimal allocations
522func 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
553func go_write_headers(threadIndex C.uintptr_t, status C.int, headers *C.zend_llist) C.bool {

Callers 1

addHeaderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected