// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/net/protocols/http.cpp
// Function: smooth::Net::Protocols::httpHeader(char*, unsigned long, unsigned long, void*)
size_t S::Net::Protocols::httpHeader(char *buffer, size_t size, size_t n, void *data)
{
	HTTP	*http = (HTTP *) data;

	/* Cancel request if requested.
	 */
	if (http->doCancelDownload.Call()) return 0;

	/* Get data as string.
	 */
	String	 header;

	for (UnsignedInt i = 0; i < size * n; i++) header[i] = buffer[i];

	/* Handle headers.
	 */
	if (header.StartsWith("HTTP/1."))
	{
		/* Reset output stream when we get a new HTTP response.
		 */
		delete http->out;

		http->out = new IO::OutStream(IO::STREAM_FILE, http->file, IO::OS_REPLACE);

		http->responseFields.RemoveAll();

		/* Add status code to header fields.
		 */
		Parameter	 field;

		field.key	= "Status-Code";
		field.value	= header.Tail(header.Length() - header.Find(" ") - 1);

		http->responseFields.Add(field);
	}
	else if (header.Contains(": "))
	{
		/* Split header into key and value.
		 */
		Parameter	 field;
		Int		 colon	= header.Find(": ");

		field.key	= header.Head(colon);
		field.value	= header.Tail(header.Length() - colon - 2);

		http->responseFields.Add(field);
	}

	return size * n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r14
movq %rdx, %rbx
movq %rsi, %rbp
movq %rdi, %r15
leaq 0xa0(%rcx), %rdi
callq 0x95fc6
xorl %r12d, %r12d
testb %al, %al
je 0xa9714
xorl %ebx, %ebx
jmp 0xa994c
leaq 0x20(%rsp), %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x5a180
imulq %rbp, %rbx
movl %r12d, %r12d
cmpq %r12, %rbx
jbe 0xa9746
movsbl (%r15,%r12), %ebp
movq %r13, %rdi
movl %r12d, %esi
callq 0x59cc0
movl %ebp, (%rax)
incl %r12d
jmp 0xa9727
leaq 0x58b4f(%rip), %rsi     # 0x10229c
leaq 0x38(%rsp), %rdi
callq 0x58c40
leaq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x58a10
movl %eax, %ebp
leaq 0x38(%rsp), %rdi
callq 0x5a588
testb %bpl, %bpl
je 0xa9856
movq 0x258(%r14), %rdi
testq %rdi, %rdi
je 0xa978d
movq (%rdi), %rax
callq *0x8(%rax)
movl $0x108, %edi            # imm = 0x108
callq 0x56700
movq %rax, %r15
leaq 0x240(%r14), %rdx
pushq $0x3
popq %rsi
pushq $0x1
popq %rcx
movq %rax, %rdi
callq 0x595a0
movq %r15, 0x258(%r14)
addq $0x1e8, %r14            # imm = 0x1E8
movq %r14, %rdi
callq 0xa9d98
leaq 0x38(%rsp), %rdi
callq 0x582a0
leaq 0x58ace(%rip), %rsi     # 0x1022a4
leaq 0x38(%rsp), %rdi
callq 0x57010
leaq 0x20(%rsp), %rdi
callq 0x58370
movl %eax, %ebp
leaq 0x6ec9d(%rip), %rsi     # 0x118490
leaq 0x70(%rsp), %rdi
callq 0x58c40
leaq 0x20(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x58830
notl %eax
addl %eax, %ebp
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
callq 0x59220
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x56630
leaq 0x8(%rsp), %rdi
callq 0x5a588
leaq 0x70(%rsp), %rdi
callq 0x5a588
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0xaa07e
jmp 0xa9938
leaq 0x62fa0(%rip), %rsi     # 0x10c7fd
leaq 0x38(%rsp), %rdi
callq 0x58c40
leaq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x56180
movl %eax, %ebp
leaq 0x38(%rsp), %rdi
callq 0x5a588
testb %bpl, %bpl
je 0xa9942
leaq 0x38(%rsp), %rdi
callq 0x582a0
leaq 0x62f61(%rip), %rsi     # 0x10c7fd
leaq 0x8(%rsp), %rdi
callq 0x58c40
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x58830
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x5a588
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl %ebp, %edx
callq 0x59e40
leaq 0x38(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x56630
leaq 0x8(%rsp), %rdi
callq 0x5a588
leaq 0x20(%rsp), %rdi
callq 0x58370
subl %ebp, %eax
addl $-0x2, %eax
leaq 0x8(%rsp), %rdi
leaq 0x20(%rsp), %rsi
movl %eax, %edx
callq 0x59220
leaq 0x50(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x56630
leaq 0x8(%rsp), %rdi
callq 0x5a588
addq $0x1e8, %r14            # imm = 0x1E8
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0xaa07e
leaq 0x38(%rsp), %rdi
callq 0x5a4e0
leaq 0x20(%rsp), %rdi
callq 0x5a588
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xa99b3
jmp 0xa9969
jmp 0xa9969
jmp 0xa99b3
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0xa99ac
jmp 0xa99b3
jmp 0xa99d5
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5a588
jmp 0xa99a7
jmp 0xa99b3
jmp 0xa99b3
jmp 0xa99b3
jmp 0xa99d5
jmp 0xa99c4
movq %rax, %rbx
movl $0x108, %esi            # imm = 0x108
movq %r15, %rdi
callq 0x564c0
jmp 0xa99d8
jmp 0xa99d5
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x5a588
jmp 0xa99b6
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x5a4e0
jmp 0xa99d8
jmp 0xa99d5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x5a588
jmp 0xa99d8
jmp 0xa99d5
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x5a588
movq %rbx, %rdi
callq 0x58260